cancel
Showing results for 
Search instead for 
Did you mean: 

HAL UART Error but no Error Code

Posted on August 07, 2017 at 17:32

Hello, I am getting UART errors (by the means of the HAL_UART_ErrorCallback callback function) but the strange thing is that the value of handle->ErrorCode is zero! So, an error but no error code. I think there is a logical error in the UART driver, here is a the offending part from the STM32L0 UART driver, my comments are the ones starting by '<--------':

/* Call UART Error Call back function if need be --------------------------*/
 if(huart->ErrorCode != HAL_UART_ERROR_NONE) // <------------ The debugger Enters here because huart->ErrorCode is HAL_UART_ERROR_ORE 
 {
 /* UART in mode Receiver ---------------------------------------------------*/
 if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
 {
 UART_Receive_IT(huart); // <---------- but this function clears huart->ErrorCode value back to zero!!!
 }
 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
 consider error as blocking */
 if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) ||
 (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)))
 { 
 /* Blocking error : transfer is aborted
 Set the UART state ready to be able to start again the process,
 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
 UART_EndRxTransfer(huart);
 /* Disable the UART DMA Rx request if enabled */
 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
 {
 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
 /* Abort the UART DMA Rx channel */
 if(huart->hdmarx != NULL)
 {
 /* Set the UART DMA Abort callback : 
 will lead to call HAL_UART_ErrorCallback() at end of DMA abort procedure */
 huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError;
 /* Abort DMA RX */
 if(HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
 {
 /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */
 huart->hdmarx->XferAbortCallback(huart->hdmarx);
 }
 }
 else
 {
 /* Call user error callback */
 HAL_UART_ErrorCallback(huart);
 }
 }
 else
 {
 /* Call user error callback */
 HAL_UART_ErrorCallback(huart);
 }
 }
 else
 {
 /* Non Blocking error : transfer could go on. 
 Error is notified to user through user error callback */
 HAL_UART_ErrorCallback(huart);
 huart->ErrorCode = HAL_UART_ERROR_NONE;
 }
 }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

#uart #stm32cube #overrun
4 REPLIES 4
Tilen MAJERLE
ST Employee
Posted on August 08, 2017 at 11:46

Hello

sweden

‌,

can you please describe more about the problem? How do you use UART driver?

Best regards,

Tilen

Posted on August 08, 2017 at 12:48

Thanks for your interest, I was trying to use 

https://github.com/Lora-net/LoRaMac-node/blob/develop/src/boards/MoteII/uart-board.c

implementation of a FIFO buffered UART driver (it uses HAL and places the arriving characters into a

https://github.com/Lora-net/LoRaMac-node/blob/develop/src/system/fifo.c

buffer, one at a time, using an interrupt).

I think it is not a very much optimized code, because when I'm actively using the

UartMcuGetChar function while there is more data arriving on UART I'm getting the mentioned overrun issue. Maybe the problem is that they disable/enable the interrupts inside

UartMcuGetChar and because it takes long we get an overrun.

It would be nice to get an advice about that issue too, but anyway, the reason that I have created this topic is not this 3-rd party library's errors but the fact that the

HAL_UART_ErrorCallback

function was being called and the handle's ErrorCode was zero.
Posted on August 15, 2017 at 13:32

So, is this a HAL bug or maybe I'm not using it correctly?

Posted on July 05, 2018 at 18:15

Any reply from ST? Did you resolve this issue?