cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube_FW_L4_V1.17.2 UART driver issue

RHerm.3
Associate III

My application uses UART BREAK detect to switch modes and I found a bug in the 1.17.2 ST HAL UART driver.

Description of my application interface to the HAL UART driver:

My app uases a Rx and Error callback.

I perform RX 1 char at a time using the call HAL_UART_Receive_IT(drv->handle, &(drv->rxchar), 1);.

My Rx callback copies one character from the HAL driver and starts another RX.

My Error callback sets a break detect flag if drv->handle->ErrorCode indicates HAL_UART_ERROR_FE.

Bug Description:

HAL_UART_IRQHandler() checks for errors. If errors are found it ors error bits into huart->ErrorCode and clears the error bits. Then it calls huart->RxISR(), UART_RxISR_8BIT_FIFOEN() in my case.

This reads the data and checks for errors directly from the registers. Errors were already cleared So the RX callback is invoked. My callback starts RX again which clears huart->ErrorCode.

huart->RxISR() returns then eventually the Error callback is invoked with no errors reported.

This is the offecding section of code in HAL_UART_IRQHandler():

------------------------------------------------------------------------------------------

#if defined(USART_CR1_FIFOEN)

   if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U)

     && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U)

       || ((cr3its & USART_CR3_RXFTIE) != 0U)))

#else

   if (((isrflags & USART_ISR_RXNE) != 0U)

     && ((cr1its & USART_CR1_RXNEIE) != 0U))

#endif /* USART_CR1_FIFOEN */

   {

     if (huart->RxISR != NULL)

     {

      huart->RxISR(huart);

     }

   }

   /* If Error is to be considered as blocking :

     - Receiver Timeout error in Reception

     - Overrun error in Reception

     - any error occurs in DMA mode reception

   */

   errorcode = huart->ErrorCode;

------------------------------------------------------------------------------------------

I replaced the   huart->RxISR(huart); call with the following and it allowed my code to detect BREAK chars.

    if (huart->RxISR != NULL)

    {

          //RJH save the error code

          //RJH could be cleared by ->RxISR if rx ends and callback starts it again

          errorcode = huart->ErrorCode;

          huart->RxISR(huart);

          //RJH restore error code

          huart->ErrorCode = errorcode;

    }

Of course this is lost if I regenerate code.

It also seens to me that the UART rx character should be discarded is an error is detected but the driver doesn't do this.

Please let me know when this is fixed in the driver distribution.

0 REPLIES 0