drivers: stm32: SPI: cannot send several buffers if frame size is 16 bits

First `spi_context_buffers_setup` must use a `dfs` of 1 or 2 depending on
the frame size.

Signed-off-by: Daniel Gaston Ochoa <dgastonochoa@gmail.com>
This commit is contained in:
Daniel Gaston Ochoa 2023-04-26 18:10:14 +01:00 committed by Carles Cufí
parent 3003777810
commit 9eed160a06
2 changed files with 18 additions and 9 deletions

View file

@ -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, static inline void *spi_context_get_next_buf(const struct spi_buf **current,
size_t *count, 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. */ /* This loop skips zero-length buffers in the set, if any. */
while (*count) { while (*count) {
if (((*current)->len) != 0) { if (((*current)->len / dfs) != 0) {
*buf_len = (*current)->len; *buf_len = (*current)->len / dfs;
return (*current)->buf; return (*current)->buf;
} }
++(*current); ++(*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_count = ctx->current_tx ? tx_bufs->count : 0;
ctx->tx_buf = (const uint8_t *) ctx->tx_buf = (const uint8_t *)
spi_context_get_next_buf(&ctx->current_tx, &ctx->tx_count, 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->current_rx = rx_bufs ? rx_bufs->buffers : NULL;
ctx->rx_count = ctx->current_rx ? rx_bufs->count : 0; ctx->rx_count = ctx->current_rx ? rx_bufs->count : 0;
ctx->rx_buf = (uint8_t *) ctx->rx_buf = (uint8_t *)
spi_context_get_next_buf(&ctx->current_rx, &ctx->rx_count, spi_context_get_next_buf(&ctx->current_rx, &ctx->rx_count,
&ctx->rx_len); &ctx->rx_len, dfs);
ctx->sync_status = 0; 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 *) ctx->tx_buf = (const uint8_t *)
spi_context_get_next_buf(&ctx->current_tx, spi_context_get_next_buf(&ctx->current_tx,
&ctx->tx_count, &ctx->tx_count,
&ctx->tx_len); &ctx->tx_len, dfs);
} else if (ctx->tx_buf) { } else if (ctx->tx_buf) {
ctx->tx_buf += dfs * len; 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 *) ctx->rx_buf = (uint8_t *)
spi_context_get_next_buf(&ctx->current_rx, spi_context_get_next_buf(&ctx->current_rx,
&ctx->rx_count, &ctx->rx_count,
&ctx->rx_len); &ctx->rx_len, dfs);
} else if (ctx->rx_buf) { } else if (ctx->rx_buf) {
ctx->rx_buf += dfs * len; ctx->rx_buf += dfs * len;
} }

View file

@ -628,7 +628,11 @@ static int transceive(const struct device *dev,
} }
/* Set buffers info */ /* 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) #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_fifo)
/* Flush RX buffer */ /* Flush RX buffer */
@ -729,7 +733,11 @@ static int transceive_dma(const struct device *dev,
} }
/* Set buffers info */ /* 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) #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi)
/* set request before enabling (else SPI CFG1 reg is write protected) */ /* set request before enabling (else SPI CFG1 reg is write protected) */