cancel
Showing results for 
Search instead for 
Did you mean: 

Identifying and solving UART error.

APant.1
Associate II

I am using a Nucleo GO70RB along with an ESP to control electrical appliances by sending commands to the ESP through the server and transmitting the said commands to STM32 using UART which is configured in normal DMA mode.

I am able to control the appliances through the server until I soft reset the ESP (in case of WiFi credential exchange or stream timeout) after which the STM32 stops responding to the commands sent by the ESP. The ESP is successfully printing the commands on the COM Port and is transmitting data to the ESP, due to some reason the STM32 is not responding to those commands or receiving those commands.

I am using a HAL_UART_ErrorCallback function to determine the type of error in case of a soft reset. In the function I am reading the ORE bit, PE bit, NE bit and RXFF bit of the USART ISR register none of which are are returning 1 to display any sort of error, however the code is executing HAL_UART_ErrorCallback function upon soft reset, as I have defined a global variable Error_count and initialized it to 0, every time the code executes the HAL_UART_ErrorCallback function the Error_count increments by 1.

I can not seem to identify the problem, can someone guide me in relation to this issue.

4 REPLIES 4
TDK
Guru

Error bits are cleared before HAL calls HAL_UART_ErrorCallback (just as status bits are cleared prior to calling the relevant callbacks). The error condition is stored in the ErrorCode member of the handle structure and will be some bitwise combination of:

/** @defgroup UART_Error_Code UART Error Code
  * @{
  */
#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  */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
#define  HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U   /*!< Invalid Callback error  */
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
/**
  * @}
  */

 If there's not an external pullup on the line, or if the ESP toggles it during startup, you probably have a frame error.

If you feel a post has answered your question, please click "Accept as Solution".

Hi, thanks for your response, I am fairly new to programming 32 bit MCU's as I am still a student, could you please bear with me and let me know the following:-

(i) As per my understanding if the error bits are cleared before calling HAL_UART_ErrorCallback function, that means I can not use it to view what exactly my error was, then what is the purpose of this callback function.

(ii) Could you please explain how to proceed regarding reading the error bits in detail.

TDK
Guru

As I said, the error condition is stored within the ErrorCode member. Within the error callback, you would do something like the following to determine what error occurred, and handle it appropriately.

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {
  if (huart->ErrorCode & HAL_UART_ERROR_PE) {
    // parity error
  }
  if (huart->ErrorCode & HAL_UART_ERROR_FE) {
    // frame error
  }
  // etc...
}

Once you determine the type of error occurring, you typically would fix the source of that error so it doesn't happen again as errors should not occur during regular communication. But you could also clear the error and ignore it.

If you feel a post has answered your question, please click "Accept as Solution".

This is what I am doing at the moment after making changes as per your guidance

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {

 Error_count++;

 if ((huart -> ErrorCode & HAL_UART_ERROR_ORE)) {

ORE_Status = 1;

  /* *p_USART_ICR |= (1 << 3);

  ORE_Status = p_USART_ISR->ORE;*/

 }

 else if((huart -> ErrorCode & HAL_UART_ERROR_PE)){

 PE_Status = 1;

 }

 else if((huart -> ErrorCode & HAL_UART_ERROR_FE)){

   FE_Status = 1;

  }

}

However I am still unable to detect any error when I software reset the ESP, however when I reset the ESP via hardware I get a framing error.