2024-02-15 02:25 AM - edited 2024-02-15 02:46 AM
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
2024-02-15 05:44 PM
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 */
2024-02-15 08:59 PM
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).
2024-02-19 04:58 AM
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
2024-02-19 07:44 AM
See the sequence the HAL driver is doing. Use or don't use what you think is important to use.
2024-02-26 03:16 AM
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