From eccf541ea6e509536efdd252ade219a3450076a4 Mon Sep 17 00:00:00 2001 From: Fabrice DJIATSA Date: Fri, 13 Jun 2025 10:10:12 +0200 Subject: [PATCH] drivers: spi: stm32: dynamically update spi word/frame size Update the source_data and dest_data sizes with the frame size in bytes before performing the transfer. With these changes, we can handle cases where the buffers switch between 8-bit and 16-bit modes. Signed-off-by: Fabrice DJIATSA --- drivers/spi/spi_ll_stm32.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index 5d56ab106b1..f6e6bf7c176 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -1186,6 +1186,13 @@ static int transceive_dma(const struct device *dev, /* This is turned off in spi_stm32_complete(). */ spi_stm32_cs_control(dev, true); + uint8_t word_size_bytes = bits2bytes(SPI_WORD_SIZE_GET(config->operation)); + + data->dma_rx.dma_cfg.source_data_size = word_size_bytes; + data->dma_rx.dma_cfg.dest_data_size = word_size_bytes; + data->dma_tx.dma_cfg.source_data_size = word_size_bytes; + data->dma_tx.dma_cfg.dest_data_size = word_size_bytes; + while (data->ctx.rx_len > 0 || data->ctx.tx_len > 0) { size_t dma_len;