Skip to content

Commit f91258d

Browse files
gautierg-stnashif
authored andcommitted
drivers: spi: stm32: invert ll_func_spi_dma_busy logic
Inverts ll_func_spi_dma_busy logic so that the function returns true if the SPI DMA is busy (as suggested by the name) instead of the other way around. Also completes the check for H7-compatible with the LL_SPI_IsActiveFlag_EOT function when transfer size is set. Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
1 parent 21950ef commit f91258d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

drivers/spi/spi_stm32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,12 +1443,12 @@ static int transceive_dma(const struct device *dev,
14431443
#endif /* SPI_SR_FTLVL */
14441444

14451445
#ifdef CONFIG_SPI_STM32_ERRATA_BUSY
1446-
WAIT_FOR(ll_func_spi_dma_busy(spi) != 0,
1446+
WAIT_FOR(!ll_func_spi_dma_busy(spi),
14471447
CONFIG_SPI_STM32_BUSY_FLAG_TIMEOUT,
14481448
k_yield());
14491449
#else
14501450
/* wait until spi is no more busy (spi TX fifo is really empty) */
1451-
while (ll_func_spi_dma_busy(spi) == 0) {
1451+
while (ll_func_spi_dma_busy(spi)) {
14521452
}
14531453
#endif /* CONFIG_SPI_STM32_ERRATA_BUSY */
14541454

drivers/spi/spi_stm32.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,19 @@ static inline uint32_t ll_func_dma_get_reg_addr(SPI_TypeDef *spi, uint32_t locat
9797
/* checks that DMA Tx packet is fully transmitted over the SPI */
9898
static inline uint32_t ll_func_spi_dma_busy(SPI_TypeDef *spi)
9999
{
100-
#ifdef LL_SPI_SR_TXC
101-
return LL_SPI_IsActiveFlag_TXC(spi);
100+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi)
101+
if (LL_SPI_GetTransferSize(spi) == 0) {
102+
return LL_SPI_IsActiveFlag_TXC(spi) == 0;
103+
} else {
104+
return LL_SPI_IsActiveFlag_EOT(spi) == 0;
105+
}
102106
#else
103107
/* the SPI Tx empty and busy flags are needed */
104-
return (LL_SPI_IsActiveFlag_TXE(spi) &&
105-
!LL_SPI_IsActiveFlag_BSY(spi));
108+
return (!LL_SPI_IsActiveFlag_TXE(spi) ||
109+
LL_SPI_IsActiveFlag_BSY(spi));
106110
#endif /* LL_SPI_SR_TXC */
107111
}
108-
#endif /* CONFIG_SPI_STM32_DMA */
112+
#endif /* st_stm32h7_spi */
109113

110114
static inline uint32_t ll_func_tx_is_not_full(SPI_TypeDef *spi)
111115
{

0 commit comments

Comments
 (0)