Skip to content

Commit c28d779

Browse files
kbidanijhedberg
authored andcommitted
drivers: spi: stm32: Fix race condition causing lockup in half-duplex mode
This patch adds a check for the EOT (End Of Transfer) flag inside the polling loop in spi_stm32_half_duplex_switch_to_receive(). If EOT is set, the transfer is already complete and the loop is exited, preventing the lockup. Signed-off-by: Khaoula Bidani <[email protected]> Signed-off-by: Julien Racki <[email protected]>
1 parent b9a15a9 commit c28d779

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/spi/spi_ll_stm32.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,14 @@ static int spi_stm32_half_duplex_switch_to_receive(const struct spi_stm32_config
10801080
if (LL_SPI_GetMode(spi) == LL_SPI_MODE_MASTER) {
10811081
LL_SPI_StartMasterTransfer(spi);
10821082
while (!LL_SPI_IsActiveMasterTransfer(spi)) {
1083-
/* NOP */
1083+
/*
1084+
* Check for the race condition where the transfer completes
1085+
* before this loop is entered. If EOT is set, the transfer
1086+
* is done and we can break.
1087+
*/
1088+
if (LL_SPI_IsActiveFlag_EOT(spi)) {
1089+
break;
1090+
}
10841091
}
10851092
}
10861093
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) */

0 commit comments

Comments
 (0)