AnsweredAssumed Answered

Possible bug in UART of the latest F4xx_HAL_Driver (v1.4.1, cubef4 v1.9.0)

Question asked by Laureg on Nov 11, 2015
Latest reply on Nov 12, 2015 by Amel N
Hi,


I got stuck for 4 hours in this problem and now found why:


When I use the HAL_UART_Transmit_IT() function and at the same time something arrives in the RX without the HAL_UART_Receive_IT() being called, it causes an overrun error and holds the execution inside the UART IRQ Handler.


This happens because the HAL_UART_Transmit_IT() activate Error interrupts (line 829 of the ..hal_uart.c) (why? this is not intended only for reception?), and when an overrun error occurs, the HAL_UART_IRQHandler() will clear the error and set the ErrorCode to HAL_UART_ERROR_ORE (line 1194), this causes the State to be set to HAL_UART_STATE_READY right before calling the user ErrorCallback function (line 1226), but because the error occurred in the middle of a transmission, the TXE interrupt still running, and now the function UART_Transmit_IT() (line 1210) is being called but will do nothing because of the new set State, keeping the interruption in an infinite loop.


For the moment, my workaround to avoid change the library itself is to implement a function to restore the State and clear the ErrorCode at the ErrorCallback function:


void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
     if(huart->TxXferCount>0)
     {
          huart->State = HAL_UART_STATE_BUSY_TX;
     }
     huart->ErrorCode = HAL_UART_ERROR_NONE;
}


Please, somebody confirm that this is a bug and I'm not using the lib in a wrong way, just to be sure that I'm not crazy


Clive1 ????


Thanks.

Outcomes