Fix: ROERR handling

On the AT32, an unhandled UART overrun (ROERR) latches: one overrun stops the USART feeding the DMA, every ack after it is lost, and only a re-init clears it.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
This commit is contained in:
Niel Nielsen authored and GitHub committed 2026-09-04 06:21:20 +02:00
1 parent 9944e4d161
commit 73a3c85f2c
1 file changed
+10
+10
View File
@@ -150,6 +150,16 @@ int bwm_uart_write(const uint8_t *data, size_t len) {
}
uint16_t bwm_uart_rx_available(void) {
// An unhandled overrun (ROERR) latches on this USART and stops it feeding the
// DMA - after one overrun every subsequent byte is lost until a re-init, which
// is why a stalled OTA "recovers on re-run" but mostly fails in a session.
// Clear it here so reception resumes on its own. ROERR clears by reading STS
// then DT; we only do that when the flag is actually set - the DMA is stalled
// then, so the byte we consume is the already-lost overrun byte.
if (usart_flag_get(BWM_UART, USART_ROERR_FLAG) != RESET) {
(void)BWM_UART->sts;
(void)BWM_UART->dt;
}
return (uint16_t)((bwm_uart_rx_head() - s_rx_tail) & (BWM_RX_RING_SZ - 1));
}