From 39391b4a160a4e23a2b7f213f94cf04b2c250ad7 Mon Sep 17 00:00:00 2001 From: Benedikt Schmidt Date: Tue, 4 Jul 2023 13:28:33 +0200 Subject: [PATCH] drivers: spi: replace timeout for STM32 DMA slave mode Replace the timeout for a SPI transceive in slave mode for STM32 DMA operations with a K_FOREVER. Being an SPI slave means we do not know when the transaction will start, hence it does not make sense to have a timeout in such a case. This will resolve issue #60000. Signed-off-by: Benedikt Schmidt --- drivers/spi/spi_ll_stm32.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index 418a635589b..8590cc6fd58 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -693,9 +693,20 @@ static int wait_dma_rx_tx_done(const struct device *dev) { struct spi_stm32_data *data = dev->data; int res = -1; + k_timeout_t timeout; + + /* + * In slave mode we do not know when the transaction will start. Hence, + * it doesn't make sense to have timeout in this case. + */ + if (IS_ENABLED(CONFIG_SPI_SLAVE) && spi_context_is_slave(&data->ctx)) { + timeout = K_FOREVER; + } else { + timeout = K_MSEC(1000); + } while (1) { - res = k_sem_take(&data->status_sem, K_MSEC(1000)); + res = k_sem_take(&data->status_sem, timeout); if (res != 0) { return res; }