From 26e6ade1757e20ce3a1253c4c4d0a915960a38d8 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 31 Oct 2022 18:03:11 +0100 Subject: stm32: fix USART ORE status flag handling If an USART RX overrun happened on a stm32g0/f0/h7, the ORE flag would get set by hardware. This flag would also trigger an interrupt. The problem was that this flag was never cleared on these 3 mcu families since the ORE flag clear sequence is different to all of the older chips. Since the ORE flag is not used in any meaningful way anyway, it was disabled during the init sequence. Signed-off-by: Alex Voinea --- src/stm32/serial.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/stm32/serial.c') diff --git a/src/stm32/serial.c b/src/stm32/serial.c index 5806eaab..19aa048e 100644 --- a/src/stm32/serial.c +++ b/src/stm32/serial.c @@ -57,8 +57,11 @@ void USARTx_IRQHandler(void) { uint32_t sr = USARTx->SR; - if (sr & (USART_SR_RXNE | USART_SR_ORE)) + if (sr & (USART_SR_RXNE | USART_SR_ORE)) { + // The ORE flag is automatically cleared by reading SR, followed + // by reading DR. serial_rx_byte(USARTx->DR); + } if (sr & USART_SR_TXE && USARTx->CR1 & USART_CR1_TXEIE) { uint8_t data; int ret = serial_get_tx_byte(&data); -- cgit v1.2.3-70-g09d2