Skip to content

Commit 3099d64

Browse files
committed
Clear UART error flags before delegating to HAL
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.
1 parent ad78c0b commit 3099d64

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lpuart.c

+17
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,25 @@ void RNG_LPUART1_IRQHandler(void)
227227
if (LL_LPUART_IsEnabledIT_RXNE(port.Instance)) {
228228
LL_LPUART_DisableIT_RXNE(port.Instance);
229229
system_disallow_stop_mode(SYSTEM_MODULE_LPUART_RX);
230+
return;
230231
}
231232

233+
// If the event wasn't handled by the code above, delegate to the HAL. But
234+
// before we do that, check and clear the error flags, otherwise the HAL
235+
// would abort the DMA transfer.
236+
237+
if (LL_LPUART_IsActiveFlag_PE(port.Instance))
238+
LL_LPUART_ClearFlag_PE(port.Instance);
239+
240+
if (LL_LPUART_IsActiveFlag_FE(port.Instance))
241+
LL_LPUART_ClearFlag_FE(port.Instance);
242+
243+
if (LL_LPUART_IsActiveFlag_ORE(port.Instance))
244+
LL_LPUART_ClearFlag_ORE(port.Instance);
245+
246+
if (LL_LPUART_IsActiveFlag_NE(port.Instance))
247+
LL_LPUART_ClearFlag_NE(port.Instance);
248+
232249
HAL_UART_IRQHandler(&port);
233250
}
234251

0 commit comments

Comments
 (0)