cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 and RTOS: UART single overrun blocks application

awiernie
Senior II

There is a nasty behaviour if an overrun occurs with uart communications. I don't know if this happens generally or  with our configuration only (STM32F479NI, RTOS with  CMSIS v1,

HAL_UARTEx_ReceiveToIdle_DMA).

The Application hangs because endless irqhandler calls occur until  SR and DR register of the uart us read subsequently in order to clear the error flag.

 

Details:

I had a problem where the application was hanging from time to time. The reason was that an overrun occured in UART dma receive and afterwards  the IRQ handler was called again and again while the threads of the application were not executed anymore. This behaviour could be reproduced by disconnecting or connecting the device attached to the uart during runtime. Here most of the time an overrun occured. After  adding the following in order to clear the overrun flag there is no hanging anymore. If the behaviour is not a bug, the dodumentation should be improved at least.

 

/* USER CODE BEGIN USART1_IRQn 1 */

// overrun or noise flag is cleared by reading SR followed by reading DR

// is needed preventing hanging repeated interrupt calls (mur+pack)

uint32_t isrflags = READ_REG(huart1.Instance->SR);

uint32_t errorflags = (isrflags & (uint32_t)(USART_SR_ORE | USART_SR_NE));

if (errorflags)

{

uint8_t a = huart1.Instance->SR;

uint8_t b = huart1.Instance->DR;

}

/* USER CODE END USART1_IRQn 1 */

 

 

 

1 REPLY 1
TDK
Guru

Overrun suggests the chip is not ready for new data. Likely the previous call finished and a new one has not yet started.

Noise error suggests the signal is not valid. Not really something that can be solved in code, although you can band aid it by just ignoring things and clearing the flag.

If you feel a post has answered your question, please click "Accept as Solution".