Skip to content

Commit 860bd87

Browse files
FRASTMnashif
authored andcommitted
drivers: uart stm32 F4X, F1X, F2X have a sw sequence to clear error flags
Gives more explanation on uart_stm32_err_check function. On stm32 F4X, F1X, and F2X, when clearing the usart Error Flag (PE, ORE, FE, NE), the LL Clear function applies a software sequence which reads the usart SR then the usart DR. Consequently the RXNE flag is affected (cleared) by the uart_stm32_err_check function call. Signed-off-by: Francois Ramu <[email protected]>
1 parent 7728587 commit 860bd87

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/serial/uart_stm32.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ static int uart_stm32_poll_in(const struct device *dev, unsigned char *c)
508508
LL_USART_ClearFlag_ORE(UartInstance);
509509
}
510510

511+
/*
512+
* On stm32 F4X, F1X, and F2X, the RXNE flag is affected (cleared) by
513+
* the uart_err_check function call (on errors flags clearing)
514+
*/
511515
if (!LL_USART_IsActiveFlag_RXNE(UartInstance)) {
512516
return -1;
513517
}
@@ -570,9 +574,10 @@ static int uart_stm32_err_check(const struct device *dev)
570574
USART_TypeDef *UartInstance = UART_STRUCT(dev);
571575
uint32_t err = 0U;
572576

573-
/* Check for errors, but don't clear them here.
577+
/* Check for errors, then clear them.
574578
* Some SoC clear all error flags when at least
575-
* one is cleared. (e.g. F4X, F1X, and F2X)
579+
* one is cleared. (e.g. F4X, F1X, and F2X).
580+
* The stm32 F4X, F1X, and F2X also reads the usart DR when clearing Errors
576581
*/
577582
if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
578583
err |= UART_ERROR_OVERRUN;
@@ -595,7 +600,11 @@ static int uart_stm32_err_check(const struct device *dev)
595600
LL_USART_ClearFlag_LBD(UartInstance);
596601
}
597602
#endif
598-
603+
/* Clearing error :
604+
* the stm32 F4X, F1X, and F2X sw sequence is reading the usart SR
605+
* then the usart DR to clear the Error flags ORE, PE, FE, NE
606+
* --> so is the RXNE flag also cleared !
607+
*/
599608
if (err & UART_ERROR_OVERRUN) {
600609
LL_USART_ClearFlag_ORE(UartInstance);
601610
}
@@ -669,6 +678,10 @@ static int uart_stm32_fifo_read(const struct device *dev, uint8_t *rx_data,
669678
/* Clear overrun error flag */
670679
if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
671680
LL_USART_ClearFlag_ORE(UartInstance);
681+
/*
682+
* On stm32 F4X, F1X, and F2X, the RXNE flag is affected (cleared) by
683+
* the uart_err_check function call (on errors flags clearing)
684+
*/
672685
}
673686
}
674687

@@ -750,7 +763,10 @@ static void uart_stm32_irq_rx_disable(const struct device *dev)
750763
static int uart_stm32_irq_rx_ready(const struct device *dev)
751764
{
752765
USART_TypeDef *UartInstance = UART_STRUCT(dev);
753-
766+
/*
767+
* On stm32 F4X, F1X, and F2X, the RXNE flag is affected (cleared) by
768+
* the uart_err_check function call (on errors flags clearing)
769+
*/
754770
return LL_USART_IsActiveFlag_RXNE(UartInstance);
755771
}
756772

0 commit comments

Comments
 (0)