本文整理汇总了C++中DMA_ClearFlag函数的典型用法代码示例。如果您正苦于以下问题:C++ DMA_ClearFlag函数的具体用法?C++ DMA_ClearFlag怎么用?C++ DMA_ClearFlag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DMA_ClearFlag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DMA1_Channel1_IRQHandler
void DMA1_Channel1_IRQHandler(void)
{
uint8_t ii;
/* Test DMA1 TC flag */
if((DMA_GetFlagStatus(DMA1_FLAG_TC1)) != RESET )
{
/* Clear DMA TC flag */
DMA_ClearFlag(DMA1_FLAG_TC1);
if(Motor_State==INIT)
{
ADCTemp_Init(ADC_Tab);
}
else
{
//LED_ON();
if(FOC_Flag)
{
for(ii=0;ii<6;ii++) TPWM_Cnt[ii+1]++;
PWM_Cnt++;
if(Limit_angle<(ANGLE_60D+ANGLE_60D/8))
{
SVM_Angle=SVM_Angle+Delta_angle;
Limit_angle+=Delta_angle;
}
// SVM_Angle_Test=0;
// IQ_Reference=0;
// ID_Reference=1000;
// Test_Hall=HALL_DATA();
SVPWM_2ShuntGetPhaseCurrentValues(&Curr_a_b);
Clarke(&Curr_alfa_beta,&Curr_a_b);
Park(&Curr_q_d,&Curr_alfa_beta,SVM_Angle); //
#ifdef OPEN_I
Volt_q_d.qV_Component1=VQ_Reference;
#else
Volt_q_d.qV_Component1=PID_Regulator(IQ_Reference,Curr_q_d.qI_Component1,&IQ_PID_t); //
#endif
Volt_q_d.qV_Component2=PID_Regulator(ID_Reference,Curr_q_d.qI_Component2,&ID_PID_t);
RevPark_Circle_Limitation(&Volt_q_d);
Rev_Park(&Volt_alfa_beta,&Volt_q_d);
SVPWM_2ShuntCalcDutyCycles(&Volt_alfa_beta);
} else PWM_Cnt=1000;
//LED_OFF();
DAC_SetChannel1Data(DAC_Align_12b_R,SVM_Angle/16);
}
if(++T2ms_Temp>T2MSTEMP) //2ms
{
T2ms_Temp=0;
T2ms_Flag=1;
}
if(++T100ms_Temp>T100MSTEMP) //100ms
{
T100ms_Temp=0;
T100ms_Flag=1;
}else{}
}
}
示例2: I2C_Master_BufferWrite
/**
* @brief Writes buffer of bytes.
* @param pBuffer: Buffer of bytes to be sent to the slave.
* @param NumByteToWrite: Number of bytes to be sent by the Master.
* @param Mode: Polling or DMA or Interrupt having the highest priority in the application.
* @param SlaveAddress: The address of the slave to be addressed by the Master.
* @retval : None.
*/
Status I2C_Master_BufferWrite(uint8_t* pBuffer, uint32_t NumByteToWrite, uint8_t SlaveAddress )
{
__IO uint32_t temp = 0;
__IO uint32_t Timeout = 0;
/* Enable Error IT (used in all modes: DMA, Polling and Interrupts */
I2C1->CR2 |= I2C_IT_ERR;
#if I2C_METHOD == DMA /* I2C1 Master Transmission using DMA */
{
Timeout = 0xFFFF;
/* Configure the DMA channel for I2C1 transmission */
I2CDMA_Set (pBuffer,NumByteToWrite, I2C_DIRECTION_TX);
/* Enable the I2C1 DMA requests */
I2C1->CR2 |= CR2_DMAEN_Set;
/* Send START condition */
I2C1->CR1 |= CR1_START_Set;
/* Wait until SB flag is set: EV5 */
while ((I2C1->SR1&0x0001) != 0x0001)
{
if (Timeout-- == 0)
return Error;
}
Timeout = 0xFFFF;
/* Send slave address */
/* Reset the address bit0 for write */
SlaveAddress &= OAR1_ADD0_Reset;
Address = SlaveAddress;
/* Send the slave address */
I2C1->DR = Address;
/* Wait until ADDR is set: EV6 */
while ((I2C1->SR1&0x0002) != 0x0002)
{
if (Timeout-- == 0)
return Error;
}
/* Clear ADDR flag by reading SR2 register */
temp = I2C1->SR2;
while (!DMA_GetFlagStatus(DMA1_FLAG_TC6));
DMA_Cmd(DMA1_Channel6, DISABLE);
DMA_ClearFlag(DMA1_FLAG_TC6);
/* EV8_2: Wait until BTF is set before programming the STOP */
while ((I2C1->SR1 & 0x00004) != 0x000004);
/* Program the STOP */
I2C1->CR1 |= CR1_STOP_Set;
/* Make sure that the STOP bit is cleared by Hardware */
while ((I2C1->CR1&0x200) == 0x200);
}
#endif
#if I2C_METHOD == POLLING /* I2C1 Master Transmission using Polling */
{
Timeout = 0xFFFF;
/* Send START condition */
I2C1->CR1 |= CR1_START_Set;
/* Wait until SB flag is set: EV5 */
while ((I2C1->SR1&0x0001) != 0x0001)
{
if (Timeout-- == 0)
return Error;
}
/* Send slave address */
/* Reset the address bit0 for write*/
SlaveAddress &= OAR1_ADD0_Reset;
Address = SlaveAddress;
/* Send the slave address */
I2C1->DR = Address;
Timeout = 0xFFFF;
/* Wait until ADDR is set: EV6 */
while ((I2C1->SR1 &0x0002) != 0x0002)
{
if (Timeout-- == 0)
return Error;
}
/* Clear ADDR flag by reading SR2 register */
temp = I2C1->SR2;
/* Write the first data in DR register (EV8_1) */
I2C1->DR = *pBuffer;
/* Increment */
pBuffer++;
/* Decrement the number of bytes to be written */
NumByteToWrite--;
/* While there is data to be written */
while (NumByteToWrite--)
{
//.........这里部分代码省略.........
示例3: I2C_Master_BufferWrite
/**
* @brief Writes buffer of bytes.
* @param pBuffer: Buffer of bytes to be sent to the slave.
* @param NumByteToWrite: Number of bytes to be sent by the Master.
* @param Mode: Polling or DMA or Interrupt having the highest priority in the application.
* @param SlaveAddress: The address of the slave to be addressed by the Master.
* @retval : None.
*/
ErrorStatus I2C_Master_BufferWrite(I2C_TypeDef* I2Cx, uint8_t* pBuffer,
uint32_t NumByteToWrite, I2C_ProgrammingModel Mode, uint8_t SlaveAddress,
uint32_t timeoutMs)
{
__IO uint32_t temp = 0;
__IO uint32_t Timeout = 0;
/* Enable Error IT (used in all modes: DMA, Polling and Interrupts */
I2Cx->CR2 |= I2C_IT_ERR;
if (Mode == DMA) /* I2Cx Master Transmission using DMA */
{
Timeout = 0xFFFF;
/* Configure the DMA channel for I2Cx transmission */
I2C_DMAConfig(I2Cx, pBuffer, NumByteToWrite, I2C_DIRECTION_TX);
/* Enable the I2Cx DMA requests */
I2Cx->CR2 |= CR2_DMAEN_Set;
/* Send START condition */
I2Cx->CR1 |= CR1_START_Set;
/* Wait until SB flag is set: EV5 */
while ((I2Cx->SR1 & 0x0001) != 0x0001)
{
if (Timeout-- == 0)
return ERROR;
}
Timeout = 0xFFFF;
/* Send slave address */
/* Reset the address bit0 for write */
SlaveAddress &= OAR1_ADD0_Reset;
Address = SlaveAddress;
/* Send the slave address */
I2Cx->DR = Address;
/* Wait until ADDR is set: EV6 */
while ((I2Cx->SR1 & 0x0002) != 0x0002)
{
if (Timeout-- == 0)
return ERROR;
}
/* Clear ADDR flag by reading SR2 register */
temp = I2Cx->SR2;
if (I2Cx == I2C1)
{
/* Wait until DMA end of transfer */
// while (!DMA_GetFlagStatus(DMA1_FLAG_TC6));
xSemaphoreTake(i2cdevDmaEventI2c1, M2T(5));
/* Disable the DMA1 Channel 6 */
DMA_Cmd(I2C1_DMA_CHANNEL_TX, DISABLE);
/* Clear the DMA Transfer complete flag */
DMA_ClearFlag(DMA1_FLAG_TC6);
}
else /* I2Cx = I2C2 */
{
/* Wait until DMA end of transfer */
//while (!DMA_GetFlagStatus(DMA1_FLAG_TC4))
xSemaphoreTake(i2cdevDmaEventI2c2, M2T(5));
/* Disable the DMA1 Channel 4 */
DMA_Cmd(I2C2_DMA_CHANNEL_TX, DISABLE);
/* Clear the DMA Transfer complete flag */
DMA_ClearFlag(DMA1_FLAG_TC4);
}
/* EV8_2: Wait until BTF is set before programming the STOP */
while ((I2Cx->SR1 & 0x00004) != 0x000004)
;
/* Program the STOP */
I2Cx->CR1 |= CR1_STOP_Set;
/* Make sure that the STOP bit is cleared by Hardware */
while ((I2Cx->CR1 & 0x200) == 0x200)
;
}
/* I2Cx Master Transmission using Interrupt with highest priority in the application */
else
{
/* Enable EVT IT*/
I2Cx->CR2 |= I2C_IT_EVT;
/* Enable BUF IT */
I2Cx->CR2 |= I2C_IT_BUF;
/* Set the I2C direction to Transmission */
I2CDirection = I2C_DIRECTION_TX;
Buffer_Tx1 = pBuffer;
SlaveAddress &= OAR1_ADD0_Reset;
Address = SlaveAddress;
if (I2Cx == I2C1)
NumbOfBytes1 = NumByteToWrite;
else
NumbOfBytes2 = NumByteToWrite;
/* Send START condition */
I2Cx->CR1 |= CR1_START_Set;
Timeout = timeoutMs * I2CDEV_LOOPS_PER_MS;
/* Wait until the START condition is generated on the bus: the START bit is cleared by hardware */
while ((I2Cx->CR1 & 0x100) == 0x100 && Timeout)
//.........这里部分代码省略.........
示例4: COMInit
void COMInit(COM_TypeDef COM)
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_AHB1Periph_GPIOD, ENABLE);
if (COM == USART_COM1)
{
/* Enable UART clock */
RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
}
/* Connect PXx to USARTx_Tx*/
GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
/* Connect PXx to USARTx_Rx*/
GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
/* Configure USART Tx as alternate function */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
/*USART Init code*/
USART_OverSampling8Cmd(COM_USART[COM], ENABLE);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(COM_USART[COM], &USART_InitStructure);
/*USART Interrupt code*/
/*USART TX interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = COM_DMA_TX_IRQn[COM];
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = COM_TX_DMA_PREPRIO[COM];
NVIC_InitStructure.NVIC_IRQChannelSubPriority = COM_TX_DMA_SUBPRIO[COM];
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*USART RX interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = COM_DMA_RX_IRQn[COM];
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = COM_RX_DMA_PREPRIO[COM];
NVIC_InitStructure.NVIC_IRQChannelSubPriority = COM_RX_DMA_SUBPRIO[COM];
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_AHB1PeriphClockCmd(COM_DMA_CLK[COM], ENABLE);
/*USART TX clean up*/
DMA_ClearFlag(COM_TX_DMA_STREAM[COM], COM_TX_DMA_FLAG_FEIF[COM] | COM_TX_DMA_FLAG_DMEIF[COM] | COM_TX_DMA_FLAG_TEIF[COM] | COM_TX_DMA_FLAG_HTIF[COM] | COM_TX_DMA_FLAG_TCIF[COM]);
DMA_Cmd(COM_TX_DMA_STREAM[COM], DISABLE);
DMA_DeInit(COM_TX_DMA_STREAM[COM]);
/*USART RX Clean up*/
DMA_ClearFlag(COM_RX_DMA_STREAM[COM], COM_RX_DMA_FLAG_FEIF[COM] | COM_RX_DMA_FLAG_DMEIF[COM] | COM_RX_DMA_FLAG_TEIF[COM] | COM_RX_DMA_FLAG_HTIF[COM] | COM_RX_DMA_FLAG_TCIF[COM]);
DMA_Cmd(COM_RX_DMA_STREAM[COM], DISABLE);
DMA_DeInit(COM_RX_DMA_STREAM[COM]);
/*USART TX Config*/
DMA_InitStructure.DMA_Channel = COM_TX_DMA_CHANNEL[COM];
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) COM_DR_ADDRESS[COM];
DMA_InitStructure.DMA_Memory0BaseAddr = COM_TX_BUFFER[COM]; /* This parameter will be configured durig communication */
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; /* This parameter will be configured durig communication */
DMA_InitStructure.DMA_BufferSize = 0xFF; /* This parameter will be configured durig communication */
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(COM_TX_DMA_STREAM[COM], &DMA_InitStructure);
//DMA_ITConfig(COM_TX_DMA_STREAM[COM], DMA_IT_TC, ENABLE);
/*USART RX Config*/
DMA_InitStructure.DMA_Channel = COM_RX_DMA_CHANNEL[COM];
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) COM_DR_ADDRESS[COM];
DMA_InitStructure.DMA_Memory0BaseAddr = COM_RX_BUFFER[COM]; /* This parameter will be configured durig communication */
//.........这里部分代码省略.........
示例5: analogRead
/*
* @brief Read the analog value of a pin.
* Should return a 16-bit value, 0-65536 (0 = LOW, 65536 = HIGH)
* Note: ADC is 12-bit. Currently it returns 0-4096
*/
int32_t analogRead(uint16_t pin)
{
// Allow people to use 0-7 to define analog pins by checking to see if the values are too low.
if (pin < FIRST_ANALOG_PIN)
{
pin = pin + FIRST_ANALOG_PIN;
}
// SPI safety check
if (SPI.isEnabled() == true && (pin == SCK || pin == MOSI || pin == MISO))
{
return LOW;
}
// I2C safety check
if (Wire.isEnabled() == true && (pin == SCL || pin == SDA))
{
return LOW;
}
// Serial1 safety check
if (Serial1.isEnabled() == true && (pin == RX || pin == TX))
{
return LOW;
}
if (pin >= TOTAL_PINS || PIN_MAP[pin].adc_channel == NONE )
{
return LOW;
}
int i = 0;
if (adcChannelConfigured != PIN_MAP[pin].adc_channel)
{
digitalPinModeSaved = PIN_MAP[pin].pin_mode;
pinMode(pin, AN_INPUT);
}
if (adcInitFirstTime == true)
{
ADC_DMA_Init();
adcInitFirstTime = false;
}
if (adcChannelConfigured != PIN_MAP[pin].adc_channel)
{
// ADC1 regular channel configuration
ADC_RegularChannelConfig(ADC1, PIN_MAP[pin].adc_channel, 1, ADC_Sample_Time);
// ADC2 regular channel configuration
ADC_RegularChannelConfig(ADC2, PIN_MAP[pin].adc_channel, 1, ADC_Sample_Time);
// Save the ADC configured channel
adcChannelConfigured = PIN_MAP[pin].adc_channel;
}
for(i = 0 ; i < ADC_DMA_BUFFERSIZE ; i++)
{
ADC_DualConvertedValues[i] = 0;
}
// Reset the number of data units in the DMA1 Channel1 transfer
DMA_SetCurrDataCounter(DMA1_Channel1, ADC_DMA_BUFFERSIZE);
// Enable ADC2 external trigger conversion
ADC_ExternalTrigConvCmd(ADC2, ENABLE);
// Enable DMA1 Channel1
DMA_Cmd(DMA1_Channel1, ENABLE);
// Enable ADC1 DMA
ADC_DMACmd(ADC1, ENABLE);
// Start ADC1 Software Conversion
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// Test on Channel 1 DMA1_FLAG_TC flag
while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
// Clear Channel 1 DMA1_FLAG_TC flag
DMA_ClearFlag(DMA1_FLAG_TC1);
// Disable ADC1 DMA
ADC_DMACmd(ADC1, DISABLE);
// Disable DMA1 Channel1
DMA_Cmd(DMA1_Channel1, DISABLE);
uint16_t ADC1_ConvertedValue = 0;
uint16_t ADC2_ConvertedValue = 0;
uint32_t ADC_SummatedValue = 0;
uint16_t ADC_AveragedValue = 0;
for(int i = 0 ; i < ADC_DMA_BUFFERSIZE ; i++)
{
// Retrieve the ADC2 converted value and add to ADC_SummatedValue
//.........这里部分代码省略.........
示例6: SPI_DMA_Transmit8
/* Envía y recibe datos de 8 bits (SPI-DMA) */
uint8_t SPI_DMA_Transmit8(SPI_TypeDef* SPIx, const uint8_t* pTData, uint8_t* pRData, uint16_t pSize){
uint32_t Dummy = 0xFF;
/* Establece el tamaño de 8 bits al bus de datos a transmitir */
SPI_DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
SPI_DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
/* Configura la dirección del Periférico y la cantidad de bytes a escribir */
SPI_DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)(&(SPIx->DR));
SPI_DMA_InitStruct.DMA_BufferSize = pSize;
/* 8 bits */
SPI_DataSizeConfig(SPIx, SPI_DataSize_8b);
/*********************** TRANSMIT ****************************/
/* Configura el TX DMA */
SPI_DMA_InitStruct.DMA_DIR = SPI_DMA_DIR_TX; /* Memory to Peripheral */
if(pTData){
SPI_DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)pTData;
SPI_DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
}else{
SPI_DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&Dummy;
SPI_DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Disable;
}
/* Clear TX DMA1 FLAG y comienza la transmisión */
if(SPIx == SPI1){
DMA_ClearFlag(SPI1_TX_DMA_CHANNEL_FLAG); /* SPI1 */
DMA_Init(SPI1_TX_DMA_CHANNEL,&SPI_DMA_InitStruct);
}
else if(SPIx == SPI2){
DMA_ClearFlag(SPI2_TX_DMA_CHANNEL_FLAG); /* SPI2 */
DMA_Init(SPI2_TX_DMA_CHANNEL,&SPI_DMA_InitStruct);
}
#if defined(L152RE)
else{
DMA_ClearFlag(SPI3_TX_DMA_CHANNEL_FLAG); /* SPI3 */
DMA_Init(SPI3_TX_DMA_CHANNEL,&SPI_DMA_InitStruct);
}
#endif
/************************** RECEIVE ****************************/
/* Configura el RX DMA */
SPI_DMA_InitStruct.DMA_DIR = SPI_DMA_DIR_RX; /* Peripheral to Memory */
if(pRData){
SPI_DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)pRData;
SPI_DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
}else{
SPI_DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&Dummy;
SPI_DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Disable;
}
/* Clear RX DMA1 FLAG y comienza la transmisión */
if(SPIx == SPI1){
DMA_ClearFlag(SPI1_RX_DMA_CHANNEL_FLAG); /* SPI1 */
DMA_Init(SPI1_RX_DMA_CHANNEL,&SPI_DMA_InitStruct);
}
else if(SPIx == SPI2){
DMA_ClearFlag(SPI2_RX_DMA_CHANNEL_FLAG); /* SPI2 */
DMA_Init(SPI2_RX_DMA_CHANNEL,&SPI_DMA_InitStruct);
}
#if defined(L152RE)
else{
DMA_ClearFlag(SPI3_RX_DMA_CHANNEL_FLAG); /* SPI3 */
DMA_Init(SPI3_RX_DMA_CHANNEL,&SPI_DMA_InitStruct);
}
#endif
/************************ HABILITACIÓN **************************/
if(SPIx == SPI1){
DMA_Cmd(SPI1_TX_DMA_CHANNEL,ENABLE);
DMA_Cmd(SPI1_RX_DMA_CHANNEL,ENABLE);
SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN | SPI_CR2_RXDMAEN);
while ((DMA_GetFlagStatus(SPI1_RX_DMA_CHANNEL_FLAG) == RESET) | SPI_IS_BUSY(SPI1));
DMA_Cmd(SPI1_TX_DMA_CHANNEL,DISABLE);
DMA_Cmd(SPI1_RX_DMA_CHANNEL,DISABLE);
CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN);
}
else if(SPIx == SPI2){
DMA_Cmd(SPI2_TX_DMA_CHANNEL,ENABLE);
DMA_Cmd(SPI2_RX_DMA_CHANNEL,ENABLE);
SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN | SPI_CR2_RXDMAEN);
while ((DMA_GetFlagStatus(SPI2_RX_DMA_CHANNEL_FLAG) == RESET) | SPI_IS_BUSY(SPI2));
DMA_Cmd(SPI2_TX_DMA_CHANNEL,DISABLE);
DMA_Cmd(SPI2_RX_DMA_CHANNEL,DISABLE);
CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN);
}
#if defined(L152RE)
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
/* NVIC configuration ------------------------------------------------------*/
NVIC_Configuration();
/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();
/* TIM1 configuration ------------------------------------------------------*/
/* Time Base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0xFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x4;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* TIM1 channel1 configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0x7F;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
/* DMA1 Channel1 Configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_RegularConvertedValueTab;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 32;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel14 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);
/* Set injected sequencer length */
ADC_InjectedSequencerLengthConfig(ADC1, 1);
/* ADC1 injected channel Configuration */
ADC_InjectedChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_71Cycles5);
/* ADC1 injected external trigger configuration */
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
/* Enable automatic injected conversion start after regular one */
ADC_AutoInjectedConvCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 external trigger */
ADC_ExternalTrigConvCmd(ADC1, ENABLE);
/* Enable JEOC interrupt */
ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* TIM1 main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
/* Test on channel1 transfer complete flag */
while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
/* Clear channel1 transfer complete flag */
DMA_ClearFlag(DMA1_FLAG_TC1);
/* TIM1 counter disable */
TIM_Cmd(TIM1, DISABLE);
while (1)
{
}
}
示例8: SPIData_DMA_Enable
void SPIData_DMA_Enable(FunctionalState isEnable)
{
DMA_ClearFlag(DMA2_Stream0, DMA_FLAG_TCIF0);
DMA_Cmd(DMA2_Stream0,isEnable);
}
示例9: LM75_ReadConfReg
/**
* @brief Read the configuration register from the LM75.
* @param None
* @retval LM75 configuration register value.
*/
uint8_t LM75_ReadConfReg(void)
{
uint8_t LM75_BufferRX[2] ={0,0};
/* Test on BUSY Flag */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Configure DMA Peripheral */
LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
/* Enable the I2C peripheral */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send device address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send the device's internal address to write to */
I2C_SendData(LM75_I2C, LM75_REG_CONF);
/* Test on TXE FLag (data sent) */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send START condition a second time */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send LM75 address for read */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Enable I2C DMA request */
I2C_DMACmd(LM75_I2C,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send STOP Condition */
I2C_GenerateSTOP(LM75_I2C, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(LM75_I2C,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
/*!< Return Temperature value */
return (uint8_t)LM75_BufferRX[0];
}
示例10: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
before to branch to application main.
*/
/* SPI configuration */
SPI_Config();
/* SysTick configuration */
SysTickConfig();
/* Initialize LEDs mounted on EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
#ifdef SPI_MASTER
/* Master board configuration */
/* Initializes the SPI communication */
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPIx, &SPI_InitStructure);
/* The Data transfer is performed in the SPI using Direct Memory Access */
/* Enable DMA SPI TX Stream */
DMA_Cmd(SPIx_TX_DMA_STREAM,ENABLE);
/* Enable DMA SPI RX Stream */
DMA_Cmd(SPIx_RX_DMA_STREAM,ENABLE);
/* Enable SPI DMA TX Requsts */
SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Tx, ENABLE);
/* Enable SPI DMA RX Requsts */
SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Rx, ENABLE);
/* Configure the Tamper Button */
STM_EVAL_PBInit(BUTTON_TAMPER,BUTTON_MODE_GPIO);
/* Wait until Tamper Button is pressed */
while (STM_EVAL_PBGetState(BUTTON_TAMPER));
/* Enable the SPI peripheral */
SPI_Cmd(SPIx, ENABLE);
#endif /* SPI_MASTER */
#ifdef SPI_SLAVE
/* Slave board configuration */
/* Initializes the SPI communication */
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_Init(SPIx, &SPI_InitStructure);
/* Enable DMA SPI TX Stream */
DMA_Cmd(SPIx_TX_DMA_STREAM,ENABLE);
/* Enable DMA SPI RX Stream */
DMA_Cmd(SPIx_RX_DMA_STREAM,ENABLE);
/* Enable SPI DMA TX Requsts */
SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Tx, ENABLE);
/* Enable SPI DMA RX Requsts */
SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Rx, ENABLE);
/* Enable the SPI peripheral */
SPI_Cmd(SPIx, ENABLE);
#endif /* SPI_SLAVE */
/* Waiting the end of Data transfer */
while (DMA_GetFlagStatus(SPIx_TX_DMA_STREAM,SPIx_TX_DMA_FLAG_TCIF)==RESET);
while (DMA_GetFlagStatus(SPIx_RX_DMA_STREAM,SPIx_RX_DMA_FLAG_TCIF)==RESET);
/* Clear DMA Transfer Complete Flags */
DMA_ClearFlag(SPIx_TX_DMA_STREAM,SPIx_TX_DMA_FLAG_TCIF);
DMA_ClearFlag(SPIx_RX_DMA_STREAM,SPIx_RX_DMA_FLAG_TCIF);
/* Disable DMA SPI TX Stream */
DMA_Cmd(SPIx_TX_DMA_STREAM,DISABLE);
/* Disable DMA SPI RX Stream */
DMA_Cmd(SPIx_RX_DMA_STREAM,DISABLE);
/* Disable SPI DMA TX Requsts */
SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Tx, DISABLE);
/* Disable SPI DMA RX Requsts */
SPI_I2S_DMACmd(SPIx, SPI_I2S_DMAReq_Rx, DISABLE);
/* Disable the SPI peripheral */
//.........这里部分代码省略.........
示例11: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
/* USART configuration -----------------------------------------------------*/
USART_Config();
/* SysTick configuration ---------------------------------------------------*/
SysTickConfig();
/* LEDs configuration ------------------------------------------------------*/
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
#ifdef USART_TRANSMITTER
/* Tamper Button Configuration ---------------------------------------------*/
STM_EVAL_PBInit(BUTTON_TAMPER,BUTTON_MODE_GPIO);
/* Enable DMA USART TX Stream */
DMA_Cmd(USARTx_TX_DMA_STREAM,ENABLE);
/* Wait until Tamper Button is pressed */
while (STM_EVAL_PBGetState(BUTTON_TAMPER));
/* Enable USART DMA TX Requsts */
USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);
/* Waiting the end of Data transfer */
while (USART_GetFlagStatus(USARTx,USART_FLAG_TC)==RESET);
while (DMA_GetFlagStatus(USARTx_TX_DMA_STREAM,USARTx_TX_DMA_FLAG_TCIF)==RESET);
/* Clear DMA Transfer Complete Flags */
DMA_ClearFlag(USARTx_TX_DMA_STREAM,USARTx_TX_DMA_FLAG_TCIF);
/* Clear USART Transfer Complete Flags */
USART_ClearFlag(USARTx,USART_FLAG_TC);
#endif /* USART_TRANSMITTER */
#ifdef USART_RECEIVER
/* Enable DMA USART RX Stream */
DMA_Cmd(USARTx_RX_DMA_STREAM,ENABLE);
/* Enable USART DMA RX Requsts */
USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);
/* Waiting the end of Data transfer */
while (USART_GetFlagStatus(USARTx,USART_FLAG_TC)==RESET);
while (DMA_GetFlagStatus(USARTx_RX_DMA_STREAM,USARTx_RX_DMA_FLAG_TCIF)==RESET);
/* Clear DMA Transfer Complete Flags */
DMA_ClearFlag(USARTx_RX_DMA_STREAM,USARTx_RX_DMA_FLAG_TCIF);
/* Clear USART Transfer Complete Flags */
USART_ClearFlag(USARTx,USART_FLAG_TC);
if (Buffercmp(aTxBuffer, aRxBuffer, BUFFERSIZE) != FAILED)
{
/* Turn ON LED2 */
STM_EVAL_LEDOn(LED2);
}
else
{
/* Turn ON LED3 */
STM_EVAL_LEDOn(LED3);
}
#endif /* USART_RECEIVER */
while (1)
{
}
}
示例12: I2C1_EV_IRQHandler
/*
Only 1 byte READ using Interrupt or Polling otherwise using DMA
*/
void I2C1_EV_IRQHandler()
{
__IO uint16_t regSR1, regSR2;
__IO uint32_t regSR;
int i=10;
rt_interrupt_enter();
//rt_hw_led_on(10);
regSR1 = I2C1->SR1;
regSR2 = I2C1->SR2;
regSR = (regSR2 << 16) | regSR1;
//rt_kprintf("EV=> SR1: 0x%x\tSR2: 0x%x\tSR: 0x%x status: %d\n", regSR1, regSR2, regSR, i2cStatus);
if( (regSR & I2C_EVENT_MASTER_MODE_SELECT) == I2C_EVENT_MASTER_MODE_SELECT) //EV5
{
if( i2cStatus == S1 ) //Send TX Command
{
I2C1->DR = DevAddr & 0xFE;
i2cStatus = S2;
}
else if( i2cStatus == S4 ) //Send RX Command
{
I2C1->DR = DevAddr | 0x01;
i2cStatus = S5;
}
regSR1 = 0;
regSR2 = 0;
}
if( (regSR & I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)== I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ) //EV6
{
switch( i2cStatus )
{
case S2: //Send 1st memory address phase
{
//I2C_DMACmd(I2C1, ENABLE);
I2C1->DR = MemAddr[0];
if( memtype == I2C_MEM_1Byte )
i2cStatus = S2_2;
else if( memtype == I2C_MEM_2Bytes )
i2cStatus = S2_1;
}
break;
case S5: //Set RX buffer phase
{
if( i2cFlag == I2C_READ_DMA )
{
I2C_DMAConfig(I2C1, i2c_buf, BufSize, I2C_DIRECTION_RX);
I2C1->CR2 |= CR2_LAST_Set | CR2_DMAEN_Set;
DMA_ITConfig( I2C1_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE);
}
else if( i2cFlag == I2C_READ_INTERRUPT )
{
I2C1->CR2 |= I2C_IT_BUF;
I2C1->CR1 &= CR1_ACK_Reset;
/* Program the STOP */
I2C1->CR1 |= CR1_STOP_Set;
}
i2cStatus = S6;
}
break;
}
regSR1 = 0;
regSR2 = 0;
//dump_i2c_register(I2C1);
}
if((regSR & I2C_EVENT_MASTER_BYTE_RECEIVED) == I2C_EVENT_MASTER_BYTE_RECEIVED) //EV7
{
//Interrupt RX complete phase
if( i2cStatus == S6 && i2cFlag == I2C_READ_INTERRUPT )
{
*i2c_buf = I2C1->DR;
i2cStatus = S_STOP;
rt_event_send(&i2c_event, I2C_COMPLETE);
}
}
if( (regSR & I2C_EVENT_MASTER_BYTE_TRANSMITTED) == I2C_EVENT_MASTER_BYTE_TRANSMITTED ) //EV8_2
{
//Start TX/RX phase
if(i2cStatus == S3)
{
DMA_ClearFlag(I2C1_DMA_CHANNEL_TX, DMA_FLAG_TCIF6 );
DMA_Cmd(I2C1_DMA_CHANNEL_TX, DISABLE);
switch (i2cFlag)
{
case I2C_WRITE:
i2cStatus = S_STOP;
I2C1->CR1 |= CR1_STOP_Set;
rt_event_send(&i2c_event, I2C_COMPLETE);
break;
case I2C_READ_DMA:
i2cStatus = S4;
//.........这里部分代码省略.........
示例13: serialUSART1
serialPort_t *serialOpen(USART_TypeDef *USARTx, unsigned int baud, uint16_t flowControl, unsigned int rxBufSize, unsigned int txBufSize) {
DMA_InitTypeDef DMA_InitStructure;
serialPort_t *s = 0;
// Enable USART clocks/ports
#ifdef SERIAL_UART1_PORT
if (USARTx == USART1) {
s = serialUSART1(flowControl, rxBufSize, txBufSize);
}
#endif
#ifdef SERIAL_UART2_PORT
if (USARTx == USART2) {
s = serialUSART2(flowControl, rxBufSize, txBufSize);
}
#endif
#ifdef SERIAL_UART3_PORT
if (USARTx == USART3) {
s = serialUSART3(flowControl, rxBufSize, txBufSize);
}
#endif
#ifdef SERIAL_UART4_PORT
if (USARTx == UART4) {
s = serialUSART4(flowControl, rxBufSize, txBufSize);
}
#endif
#ifdef SERIAL_UART5_PORT
if (USARTx == UART5) {
s = serialUSART5(flowControl, rxBufSize, txBufSize);
}
#endif
#ifdef SERIAL_UART6_PORT
if (USARTx == USART6) {
s = serialUSART6(flowControl, rxBufSize, txBufSize);
}
#endif
s->waitFlag = CoCreateFlag(0, 0); // manual reset
s->USARTx = USARTx;
s->rxHead = s->rxTail = 0;
s->txHead = s->txTail = 0;
s->baudRate = baud;
s->flowControl = flowControl;
s->parity = USART_Parity_No;
s->stopBits = USART_StopBits_1;
serialOpenUART(s);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)USARTx + 0x04;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
// Configure DMA for rx
if (s->rxDMAStream) {
DMA_DeInit(s->rxDMAStream);
DMA_InitStructure.DMA_Channel = s->rxDMAChannel;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)s->rxBuf;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = s->rxBufSize;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(s->rxDMAStream, &DMA_InitStructure);
DMA_ClearFlag(s->rxDMAStream, s->rxDmaFlags);
DMA_Cmd(s->rxDMAStream, ENABLE);
USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);
s->rxPos = DMA_GetCurrDataCounter(s->rxDMAStream);
}
// otherwise use ISR
else {
USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE);
}
// Configure DMA for tx
if (s->txDMAStream) {
DMA_DeInit(s->txDMAStream);
DMA_InitStructure.DMA_Channel = s->txDMAChannel;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = (s->txBufSize != 0) ? s->txBufSize : 16;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(s->txDMAStream, &DMA_InitStructure);
DMA_SetCurrDataCounter(s->txDMAStream, 0);
DMA_ITConfig(s->txDMAStream, DMA_IT_TC, ENABLE);
//.........这里部分代码省略.........
示例14: USART3_IRQHandler
void USART3_IRQHandler(void)
{
volatile u32 tem_reg;
volatile u16 u16BufferUsedLen = 0;
BaseType_t xHigherPriorityTaskWoken, xResult;
// xHigherPriorityTaskWoken must be initialised to pdFALSE.
xHigherPriorityTaskWoken = pdFALSE;
// error happen
if(USART_GetITStatus(USART3, USART_IT_PE) != RESET)
{
USART_ClearITPendingBit(USART3, USART_IT_PE);
xSerialRxParityFlag = DMA_UART_PACKET_PARITY_ERR;
}
// uart idle interrupt
if(USART_GetITStatus(USART3, USART_IT_IDLE) != RESET)
{
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
DMA_ClearFlag(DMA1_FLAG_GL3);//clear all interrupt flags
DMA_Cmd(DMA1_Channel3, DISABLE); //close DMA incase receive data while handling
xResult = xSemaphoreTakeFromISR( xSerialRxHandleLock, &xHigherPriorityTaskWoken);
if( pdTRUE == xResult)
{
if (uart3_rx_dma_buf.IdleBufferIndex) //buf1 busy, buf2 idle
{
u16BufferUsedLen = uart3_rx_dma_buf.nBuff1MaxLength - DMA_GetCurrDataCounter(DMA1_Channel3);
if (u16BufferUsedLen > 0)
{
uart3_rx_dma_buf.nBuff1Offset = u16BufferUsedLen;
DMA1_Channel3->CMAR = (uint32_t)uart3_rx_dma_buf.pPingPongBuff2;
DMA1_Channel3->CNDTR = uart3_rx_dma_buf.nBuff2MaxLength;
uart3_rx_dma_buf.IdleBufferIndex = 0;
}
}
else
{
u16BufferUsedLen = uart3_rx_dma_buf.nBuff2MaxLength - DMA_GetCurrDataCounter(DMA1_Channel3);
if (u16BufferUsedLen > 0)
{
uart3_rx_dma_buf.nBuff2Offset = u16BufferUsedLen;
DMA1_Channel3->CMAR = (uint32_t)uart3_rx_dma_buf.pPingPongBuff1;
DMA1_Channel3->CNDTR = uart3_rx_dma_buf.nBuff1MaxLength;
uart3_rx_dma_buf.IdleBufferIndex = 1;
}
}
xResult = xSemaphoreGiveFromISR( xSerialRxHandleLock ,&xHigherPriorityTaskWoken);
if (u16BufferUsedLen > 0)
{
//boardcast message to handle
xResult = xEventGroupSetBitsFromISR(
xUart3RxEventGroup, // The event group being updated.
UART_DMA_RX_INCOMPLETE_EVENT_BIT,// The bits being set.
&xHigherPriorityTaskWoken );
} //End if u16BufferUsedLen > 0
}// End if pdTRUE == xSemaphoreTakeFromISR
DMA_Cmd(DMA1_Channel3, ENABLE); //open DMA after handled
//clear Idle flag by read SR and DR
tem_reg = USART3->SR;
tem_reg = USART3->DR;
tem_reg = tem_reg; // slove warning
}// End if USART_IT_IDLE
if(USART_GetITStatus(USART3, USART_IT_FE | USART_IT_NE) != RESET)
{
USART_ClearITPendingBit(USART3, USART_IT_FE | USART_IT_NE);
}
if( xResult == pdPASS )
{
// If xHigherPriorityTaskWoken is now set to pdTRUE then a context
// switch should be requested. The macro used is port specific and
// will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
// refer to the documentation page for the port being used.
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
示例15: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();
/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_DualConvertedValueTab;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 16;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 Channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_239Cycles5);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* ADC2 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2;
ADC_Init(ADC2, &ADC_InitStructure);
/* ADC2 regular channels configuration */
ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 2, ADC_SampleTime_239Cycles5);
/* Enable ADC2 external trigger conversion */
ADC_ExternalTrigConvCmd(ADC2, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable Vrefint channel17 */
ADC_TempSensorVrefintCmd(ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Enable ADC2 */
ADC_Cmd(ADC2, ENABLE);
/* Enable ADC2 reset calibaration register */
ADC_ResetCalibration(ADC2);
/* Check the end of ADC2 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC2));
/* Start ADC2 calibaration */
ADC_StartCalibration(ADC2);
/* Check the end of ADC2 calibration */
while(ADC_GetCalibrationStatus(ADC2));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
/* Test on DMA1 channel1 transfer complete flag */
while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
/* Clear DMA1 channel1 transfer complete flag */
DMA_ClearFlag(DMA1_FLAG_TC1);
//.........这里部分代码省略.........