Skip to content

HAL_UART_IRQHandler: With EIE=0 and NE active, the system gets stuck in an IRQ loop on the first TX byte #39

@SimonKagstrom

Description

@SimonKagstrom

I'm seeing an issue with a system which sometimes generate UART noise errors at cold start. What happens is that the system gets stuck in an ifinite loop where the UART IRQ gets retriggered all the time when UART transmission starts.

What happens is that the ISR gets triggered with the EIE flag set to 0, but with the FE flag set. It then enters this section:

void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
{
  uint32_t isrflags   = READ_REG(huart->Instance->ISR);
  uint32_t cr1its     = READ_REG(huart->Instance->CR1);
  uint32_t cr3its     = READ_REG(huart->Instance->CR3);
[...]
  /* If no error occurs */
  errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE | USART_ISR_RTOF));
  if (errorflags == 0U)
  {
[...]
  }

  /* If some errors occur */
  if ((errorflags != 0U)
      && ((((cr3its & (USART_CR3_RXFTIE | USART_CR3_EIE)) != 0U)
           || ((cr1its & (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_RTOIE)) != 0U))))
  {
[...]
    /* UART noise error interrupt occurred --------------------------------------*/
    if (((isrflags & USART_ISR_NE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U))
    {
      __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_NEF);

      huart->ErrorCode |= HAL_UART_ERROR_NE;
    }
[...]
   return;
 }

but since FE isn't cleared (due to EIE = 0), and the IRQ was caused by a TX trigger, it will go to the early return at the end if this. This means the TX IRQ trigger will never get cleared, and we're stuck in a loop.

In the debugger, I can workaround it by either clearing the FE bit (set Instance->ICR = 4), or through clearing TXEIE.

Was tested with v1.6.1, but I don't see any changes to this in the later git commits.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghalHAL-LL driver-related issue or pull-request.uartUniversal Asynchronous Receiver Transmitter

Type

No fields configured for Bug.

Projects

Status
To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions