cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H5 USART RXFIFO error handing

CTabo.1
Senior

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

 

5 REPLIES 5
Karl Yamashita
Lead II

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  */

 

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).

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

 

Karl Yamashita
Lead II

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

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