From f05fb41587f8be468433e3bd94a8dbf074d35707 Mon Sep 17 00:00:00 2001 From: Daniel Gaston Ochoa Date: Sat, 28 Sep 2024 12:12:10 +0100 Subject: [PATCH] drivers: spi: stm32h7: Avoid unnecessary FIFO flush The RxFIFO is already flushed any time a transceive operation finishes, there is no need for doing it also before the transaction start. The aim of this change is to simplify the logic and to (potentially) reduce the minimum time between transactions. Signed-off-by: Daniel Gaston Ochoa --- drivers/spi/spi_ll_stm32.c | 7 ------- drivers/spi/spi_ll_stm32.h | 9 +++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index e85d9b0e952..a2d682267e8 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -823,13 +823,6 @@ static int transceive(const struct device *dev, #endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) */ -#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo) - /* Flush RX buffer */ - while (ll_func_rx_is_not_empty(spi)) { - (void) LL_SPI_ReceiveData8(spi); - } -#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo) */ - LL_SPI_Enable(spi); #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) diff --git a/drivers/spi/spi_ll_stm32.h b/drivers/spi/spi_ll_stm32.h index 3b95ce211bc..f37f0b46564 100644 --- a/drivers/spi/spi_ll_stm32.h +++ b/drivers/spi/spi_ll_stm32.h @@ -218,12 +218,13 @@ static inline void ll_func_set_fifo_threshold_16bit(SPI_TypeDef *spi) static inline void ll_func_disable_spi(SPI_TypeDef *spi) { -#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) +#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo) /* Flush RX buffer */ - while (LL_SPI_IsActiveFlag_RXP(spi)) { - (void)LL_SPI_ReceiveData8(spi); + while (ll_func_rx_is_not_empty(spi)) { + (void) LL_SPI_ReceiveData8(spi); } -#endif /* st_stm32h7_spi */ +#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo) */ + LL_SPI_Disable(spi); while (LL_SPI_IsEnabled(spi)) {