Skip to content

Commit 06c3d7a

Browse files
kamnxttpambor
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 2a033db commit 06c3d7a

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
@@ -1328,6 +1328,16 @@ static void uart_stm32_isr(const struct device *dev)
13281328
#endif
13291329

13301330
#ifdef CONFIG_UART_ASYNC_API
1331+
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
1332+
/* If both ASYNC and INTERRUPT modes are supported in this build,
1333+
* check whether this instance is currently being used via the
1334+
* interrupt-driven API. If it is, do not process interrupt flags
1335+
* as the user callback invoked earlier is responsible for that.
1336+
*/
1337+
if (data->user_cb) {
1338+
return;
1339+
}
1340+
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
13311341
if (LL_USART_IsEnabledIT_IDLE(usart) &&
13321342
LL_USART_IsActiveFlag_IDLE(usart)) {
13331343

0 commit comments

Comments
 (0)