diff --git a/drivers/spi/spi_context.h b/drivers/spi/spi_context.h index 004c34bad3..1aed41173e 100644 --- a/drivers/spi/spi_context.h +++ b/drivers/spi/spi_context.h @@ -270,12 +270,13 @@ static inline void spi_context_unlock_unconditionally(struct spi_context *ctx) static inline void *spi_context_get_next_buf(const struct spi_buf **current, size_t *count, - size_t *buf_len) + size_t *buf_len, + uint8_t dfs) { /* This loop skips zero-length buffers in the set, if any. */ while (*count) { - if (((*current)->len) != 0) { - *buf_len = (*current)->len; + if (((*current)->len / dfs) != 0) { + *buf_len = (*current)->len / dfs; return (*current)->buf; } ++(*current); @@ -298,13 +299,13 @@ void spi_context_buffers_setup(struct spi_context *ctx, ctx->tx_count = ctx->current_tx ? tx_bufs->count : 0; ctx->tx_buf = (const uint8_t *) spi_context_get_next_buf(&ctx->current_tx, &ctx->tx_count, - &ctx->tx_len); + &ctx->tx_len, dfs); ctx->current_rx = rx_bufs ? rx_bufs->buffers : NULL; ctx->rx_count = ctx->current_rx ? rx_bufs->count : 0; ctx->rx_buf = (uint8_t *) spi_context_get_next_buf(&ctx->current_rx, &ctx->rx_count, - &ctx->rx_len); + &ctx->rx_len, dfs); ctx->sync_status = 0; @@ -340,7 +341,7 @@ void spi_context_update_tx(struct spi_context *ctx, uint8_t dfs, uint32_t len) ctx->tx_buf = (const uint8_t *) spi_context_get_next_buf(&ctx->current_tx, &ctx->tx_count, - &ctx->tx_len); + &ctx->tx_len, dfs); } else if (ctx->tx_buf) { ctx->tx_buf += dfs * len; } @@ -387,7 +388,7 @@ void spi_context_update_rx(struct spi_context *ctx, uint8_t dfs, uint32_t len) ctx->rx_buf = (uint8_t *) spi_context_get_next_buf(&ctx->current_rx, &ctx->rx_count, - &ctx->rx_len); + &ctx->rx_len, dfs); } else if (ctx->rx_buf) { ctx->rx_buf += dfs * len; } diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index cf5f28e824..fa66b850d4 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -628,7 +628,11 @@ static int transceive(const struct device *dev, } /* Set buffers info */ - spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); + if (SPI_WORD_SIZE_GET(config->operation) == 8) { + spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); + } else { + spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 2); + } #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo) /* Flush RX buffer */ @@ -729,7 +733,11 @@ static int transceive_dma(const struct device *dev, } /* Set buffers info */ - spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); + if (SPI_WORD_SIZE_GET(config->operation) == 8) { + spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); + } else { + spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 2); + } #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) /* set request before enabling (else SPI CFG1 reg is write protected) */