Skip to content

Commit

Permalink
Clear UART error flags before delegating to HAL
Browse files Browse the repository at this point in the history
We use the LPUAR1 port in DMA receive mode. On error, the HAL aborts the
DMA transfer. Since we don't want that, we clear the various error flags
before delegating to the HAL IRQ handler.

This was triggered when the port was configured with the wrong baud
rate. In that case, the LPUART1 peripheral sets the framing error flag.
  • Loading branch information
janakj committed Apr 5, 2022
1 parent ad78c0b commit 3099d64
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lpuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,25 @@ void RNG_LPUART1_IRQHandler(void)
if (LL_LPUART_IsEnabledIT_RXNE(port.Instance)) {
LL_LPUART_DisableIT_RXNE(port.Instance);
system_disallow_stop_mode(SYSTEM_MODULE_LPUART_RX);
return;
}

// If the event wasn't handled by the code above, delegate to the HAL. But
// before we do that, check and clear the error flags, otherwise the HAL
// would abort the DMA transfer.

if (LL_LPUART_IsActiveFlag_PE(port.Instance))
LL_LPUART_ClearFlag_PE(port.Instance);

if (LL_LPUART_IsActiveFlag_FE(port.Instance))
LL_LPUART_ClearFlag_FE(port.Instance);

if (LL_LPUART_IsActiveFlag_ORE(port.Instance))
LL_LPUART_ClearFlag_ORE(port.Instance);

if (LL_LPUART_IsActiveFlag_NE(port.Instance))
LL_LPUART_ClearFlag_NE(port.Instance);

HAL_UART_IRQHandler(&port);
}

Expand Down

0 comments on commit 3099d64

Please sign in to comment.