From 73a3c85f2c2e3b6fc194d795d4db8096fe037ac6 Mon Sep 17 00:00:00 2001 From: Niel Nielsen Date: Fri, 4 Sep 2026 06:21:20 +0200 Subject: [PATCH] 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 --- armsrc/bwm_uart_at32.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/armsrc/bwm_uart_at32.c b/armsrc/bwm_uart_at32.c index 3ab6b87c8..e796f1945 100644 --- a/armsrc/bwm_uart_at32.c +++ b/armsrc/bwm_uart_at32.c @@ -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)); }