cancel
Showing results for 
Search instead for 
Did you mean: 

DMA and USART error during transmission

JJohn.3
Associate II

Hello,

Here is my DMA and USART configuration:(BaudRate=2250000)

DMA_InitTypeDef DMA_InitStructure;	
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel3_IRQn;;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);		
	
	DMA_ClearFlag(DMA1_FLAG_TE3|DMA1_IT_TC3);
	DMA_Cmd(DMA1_Channel3, DISABLE);
	
	DMA_DeInit(DMA1_Channel3);
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART3->DR;
	DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Buffer;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
	DMA_InitStructure.DMA_BufferSize =sizeof(Buffer);
	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_Circular ;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	DMA_Init(DMA1_Channel3, &DMA_InitStructure);
	
							
	DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE);
	USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
	DMA_Cmd(DMA1_Channel3, ENABLE);	
	DMA_ITConfig(DMA1_Channel3,DMA_IT_TE,ENABLE);
void DMA1_Channel3_IRQHandler(void){ // USART3_RX
 
	///	Error->1 Ok, 0 Not ok, 3 CRC, 2 Page
	
 
	
	if(DMA_GetITStatus(DMA1_IT_TC3) == SET)
	{							
						DMARead=1;
						DMA_ClearITPendingBit(DMA1_IT_TC3);
						USART_Cmd(USART3,DISABLE);
						USART_ITConfig(USART3,USART_IT_RXNE,DISABLE);
						USART_DMACmd(USART3, USART_DMAReq_Rx, DISABLE);
						DMA_Cmd(DMA1_Channel3, DISABLE);
			
		}
 
 
	if(DMA_GetITStatus(DMA1_IT_TE3) == SET)
	{
		USART_Cmd(USART3,DISABLE);
		DMA_ClearITPendingBit(DMA1_IT_TE3);
		DMA_ClearITPendingBit(DMA1_IT_TC3);
		USART_DMACmd(USART3, USART_DMAReq_Rx, DISABLE);
		DMA_Cmd(DMA1_Channel3, DISABLE);
	}

I Enable my DMA during my program to have a control on the transmission an other task. My problem is when the USART or DMA has an error DMA stop working( it works for many cycles but it stop working after some minutes). As I checked the DMA1_IT_TE3 Flag I didn't any error on the DMA. I think maybe USART has an error ( Overrun or ....). I need to find out where the error is and How I can find the usart problem when I am using DMA. In addition, How can I reset the value of DMA buffer before starting it?

2 REPLIES 2

Which STM32?

Is this USART_Rx?

Yes, USART overrun if unhandled may cause the whole process to stop. Read out and check the USART regsiters when it stops.

JW

JJohn.3
Associate II

Thank you very much.

Yes in RX mode and my MCU is STm32f107. It means before enabling the DMA each time I should reset the USART error flag? Could you provide me an example? or In DMA IRQ I can manage USART error. Becuase as you can see I didn't enable USART interrupt lonely.