Skip to content

Commit db15de5

Browse files
kamnxtkartben
authored andcommitted
drivers: serial: stm32: fix race condition when both APIs enabled
Fix a bug where if CONFIG_UART_ASYNC_API was enabled in the config, the interrupt flags would get cleared after the interrupt driven API callback finished executing, causing data loss if data happened to arrive after the callback but before the flags were cleared. Signed-off-by: Kamil Krzyżanowski <[email protected]>
1 parent 6191f13 commit db15de5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/serial/uart_stm32.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,16 @@ static void uart_stm32_isr(const struct device *dev)
13591359
#endif
13601360

13611361
#ifdef CONFIG_UART_ASYNC_API
1362+
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1363+
/* If both ASYNC and INTERRUPT modes are supported in this build,
1364+
* check whether this instance is currently being used via the
1365+
* interrupt-driven API. If it is, do not process interrupt flags
1366+
* as the user callback invoked earlier is responsible for that.
1367+
*/
1368+
if (data->user_cb) {
1369+
return;
1370+
}
1371+
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
13621372
if (LL_USART_IsEnabledIT_IDLE(usart) &&
13631373
LL_USART_IsActiveFlag_IDLE(usart)) {
13641374

0 commit comments

Comments
 (0)