cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 UART HAL time race condition?

stst9193
Associate II
Posted on March 20, 2015 at 11:39

Hello,

In multiple places in the UART HAL (in all the variants of HAL_UART_Receive) one can find the following code:   

/* Check if a transmit process is ongoing or not */

    if(huart->State == HAL_UART_STATE_BUSY_TX)

    {

      huart->State = HAL_UART_STATE_BUSY_TX_RX;

    }

    else

    {

      huart->State = HAL_UART_STATE_BUSY_RX;

    }

This code may be interrupted in case of completion of transmit buffer, and the interrupt service routine may change the value of huart->State .  

The above code should be either protected from interrupt or better replaced by an atomic instruction (which seems fairly easy looking at the possible values of huart->state.

Gerard

1 REPLY 1
stst9193
Associate II
Posted on April 12, 2015 at 09:23

Could someone from ST confirm if this is a bug, and will be corrected in next HAL version.

Thanks