2025-02-18 12:47 AM
Hi,
When HAL_Uart_errorhandler is triggered, how can we check if the trigger is for reception or transmission?
2025-02-18 12:50 AM - edited 2025-02-18 12:50 AM
Check the UART error & status flags - each one will be applicable to only receive or transmit.
eg, you can't get framing or parity errors on transmit - only receive!
2025-02-18 01:28 AM
Possible UART errors listed below, and which one is for TX, and which one is for RX mentioned below. Please let me know if my understandings are correct.
#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 */
Receive Error: HAL_UART_ERROR_PE, HAL_UART_ERROR_FE, HAL_UART_ERROR_NE, HAL_UART_ERROR_ORE, HAL_UART_ERROR_RTO, HAL_UART_ERROR_DMA
Transmit Error: HAL_UART_ERROR_DMA
2025-02-18 02:15 AM
Look-up the definitions of those bits in the Reference Manual.
These, by definition, can only happen on receive:
#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_RTO (0x00000020U) /*!< Receiver Timeout error */
These you'd have to check in the Refence Manual:
#define HAL_UART_ERROR_ORE (0x00000008U) /*!< Overrun error */
#define HAL_UART_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
2025-02-18 05:49 AM
> Please let me know if my understandings are correct.
These are correct.