Skip to content
Snippets Groups Projects
Commit 7bdbea9a authored by Damien George's avatar Damien George
Browse files

stm32/uart: Clear overrun error flag after reading RX data register.

On MCUs other than F4 the ORE (overrun error) flag needs to be cleared
independently of clearing RXNE, even though both are wired to trigger the
same RXNE IRQ.  In the case that an overrun occurred it's necessary to
explicitly clear the ORE flag or else the RXNE interrupt will keep firing.
parent 0d860fdc
No related branches found
No related tags found
No related merge requests found
...@@ -597,7 +597,9 @@ int uart_rx_char(pyb_uart_obj_t *self) { ...@@ -597,7 +597,9 @@ int uart_rx_char(pyb_uart_obj_t *self) {
} else { } else {
// no buffering // no buffering
#if defined(STM32F0) || defined(STM32F7) || defined(STM32L4) || defined(STM32H7) #if defined(STM32F0) || defined(STM32F7) || defined(STM32L4) || defined(STM32H7)
return self->uartx->RDR & self->char_mask; int data = self->uartx->RDR & self->char_mask;
self->uartx->ICR = USART_ICR_ORECF; // clear ORE if it was set
return data;
#else #else
return self->uartx->DR & self->char_mask; return self->uartx->DR & self->char_mask;
#endif #endif
...@@ -722,6 +724,7 @@ void uart_irq_handler(mp_uint_t uart_id) { ...@@ -722,6 +724,7 @@ void uart_irq_handler(mp_uint_t uart_id) {
// only read data if room in buf // only read data if room in buf
#if defined(STM32F0) || defined(STM32F7) || defined(STM32L4) || defined(STM32H7) #if defined(STM32F0) || defined(STM32F7) || defined(STM32L4) || defined(STM32H7)
int data = self->uartx->RDR; // clears UART_FLAG_RXNE int data = self->uartx->RDR; // clears UART_FLAG_RXNE
self->uartx->ICR = USART_ICR_ORECF; // clear ORE if it was set
#else #else
int data = self->uartx->DR; // clears UART_FLAG_RXNE int data = self->uartx->DR; // clears UART_FLAG_RXNE
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment