AnsweredAssumed Answered

Bug in Cube F4 HAL_UART_IRQHandler

Question asked by Andrei Chichak on Dec 15, 2014
Latest reply on Jan 19, 2015 by k.tom

* @file    stm32f4xx_hal_uart.c  
* @author  MCD Application Team
* @version V1.1.0
* @date    19-June-2014

There is a problem with HAL_UART_IRQHandler where received data will be lost.

If you have a set of characters being transmitted while data is being received (such as if you have a port wired for loopback (Tx wired to Rx)), the received data will cause an overrun error if they happen to come in while the handler is transmitting the last character of the data buffer.

On a transmitter empty interrupt, HAL_UART_IRQHandler will call UART_Transmit_IT to send the next character. If the next character is the last character in the buffer, this routine disables transmitter empty interrupts then uses the following code to wait for the transmitter to drain the last character:

      if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, UART_TIMEOUT_VALUE) != HAL_OK)

      {

        return HAL_TIMEOUT;

      }

The timeout on this code is 22000 milliseconds or 22 seconds(!), but the typical time would be 1 character time plus overhead.

If any characters are received while this code block is being executed, the RXNE interrupts (or any others) are not fielded, since we are still in the interrupt routine and it is busy waiting for the transmitter to drain.

This problem happens independent of the number of characters being transmitted or the baud rate.

So, Cube authors, can you suggest a workaround?

Outcomes