Skip to main content
Graduate II
February 15, 2024
Question

STM32H5 USART RXFIFO error handing

  • February 15, 2024
  • 2 replies
  • 1526 views

Hello,
I am developing a serial communication driver using USART.
I have enabled FIFO and RTO interrupt, to handle reception.

TRM says that the received data is stored in the RXFIFO together with the corresponding flags and that PE, FE, NE bits in ISR register are associated with the character in the RDR register.

I would like to know which is the correct way to handle rx error.

In particular, when the RTO event occours (reception done), for each character present in the RXFIFO, should I first read the RDR register and then check the error flags in the ISR register, or viceversa?

Regards,
Carlo

 

    This topic has been closed for replies.

    2 replies

    Graduate II
    February 16, 2024

    The HAL driver automatically handles the error and clears the flag. It saves the error(s) in huart->ErrorCode and calls HAL_UART_ErrorCallback

    In the callback, It's up to you to then check the error bits and act upon it accordingly.  

    /** @defgroup UART_Error_Definition UART Error Definition
     * @{
     */
    #define HAL_UART_ERROR_NONE (0x00000000U) /*!< No error */
    #define HAL_UART_ERROR_PE (0x00000001U) /*!< Parity error */
    #define HAL_UART_ERROR_NE (0x00000002U) /*!< Noise error */
    #define HAL_UART_ERROR_FE (0x00000004U) /*!< Frame error */
    #define HAL_UART_ERROR_ORE (0x00000008U) /*!< Overrun error */
    #define HAL_UART_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
    #define HAL_UART_ERROR_RTO (0x00000020U) /*!< Receiver Timeout error */

     

    Visitor II
    February 16, 2024

    Yes, the HAL Drivers should handle already errors (at least to clear them).

    Why do you get a RFIFO Error?
    Is your FW too slow? Do you miss an INT?

    I would solve this RXFIFO error (instead to ask how to handle it: you would have lost data anyway).

    CTabo.1Author
    Graduate II
    February 19, 2024

    Hello @Karl Yamashita and @tjaekel,
    for performance reasons I am using LL rather than HAL driver.

    Anyway, despite the way used to access USART registers, I am interested in the correct sequence for handling USART reception.

    Should I first read the character from RDR register and the check the presence of the associated pending error flags, or should I first check the presence of error flags associated with the character in the RDR register and then read it?

    I am not having FIFO errors, but I simply want to check if the received caracters are affected by errors (PE, FE, NE).

     

    Regards,
    Carlo

     

    Graduate II
    February 19, 2024

    See the sequence the HAL driver is doing. Use or don't use what you think is important to use.  

    CTabo.1Author
    Graduate II
    February 26, 2024

    Hello,

    from a brief analisys of HAL_UART_IRQHandler() function, it seems that the right sequence is first check the presence of error flags associated with the character in the RDR register and then read it.

    Regards,
    Carlo