Skip to content

Commit

Permalink
drivers: spi: mcux_flexcomm: fix DMA bug for 2-byte transfers
Browse files Browse the repository at this point in the history
The MCUX DMA controller only supports a single data_size
for a DMA transfer, not separate ones for source and
dest. An older version of the DMA driver used
dest_data_size as the DMA transfer size, but the
current one uses MIN(dest/source) as the trasnfer
size, which breaks case when SPI wants to do 2-byte
transfers.

Signed-off-by: Mike J. Chen <[email protected]>
  • Loading branch information
mjchen0 committed Jul 17, 2023
1 parent 0eed238 commit 006554f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/spi/spi_mcux_flexcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ static int transceive_dma(const struct device *dev,
SPI_Type *base = config->base;
int ret;
uint32_t word_size;
uint16_t data_size;

spi_context_lock(&data->ctx, asynchronous, cb, userdata, spi_cfg);

Expand All @@ -604,9 +605,11 @@ static int transceive_dma(const struct device *dev,

word_size = SPI_WORD_SIZE_GET(spi_cfg->operation);

data->dma_rx.dma_cfg.dest_data_size = (word_size > 8) ?
(sizeof(uint16_t)) : (sizeof(uint8_t));
data->dma_tx.dma_cfg.dest_data_size = data->dma_rx.dma_cfg.dest_data_size;
data_size = (word_size > 8) ? (sizeof(uint16_t)) : (sizeof(uint8_t));
data->dma_rx.dma_cfg.source_data_size = data_size;
data->dma_rx.dma_cfg.dest_data_size = data_size;
data->dma_tx.dma_cfg.source_data_size = data_size;
data->dma_tx.dma_cfg.dest_data_size = data_size;

while (data->ctx.rx_len > 0 || data->ctx.tx_len > 0) {
size_t dma_len;
Expand Down Expand Up @@ -830,7 +833,6 @@ static void spi_mcux_config_func_##id(const struct device *dev) \
.dma_cfg = { \
.channel_direction = MEMORY_TO_PERIPHERAL, \
.dma_callback = spi_mcux_dma_callback, \
.source_data_size = 1, \
.block_count = 2, \
} \
}, \
Expand All @@ -841,7 +843,6 @@ static void spi_mcux_config_func_##id(const struct device *dev) \
.dma_cfg = { \
.channel_direction = PERIPHERAL_TO_MEMORY, \
.dma_callback = spi_mcux_dma_callback, \
.source_data_size = 1, \
.block_count = 1, \
} \
}
Expand Down

0 comments on commit 006554f

Please sign in to comment.