Skip to content

Commit ff5afd8

Browse files
Johan Carlssonmmahadevan108
authored andcommitted
drivers: spi: mcux_flexcomm: wait for specific dma tx status.
when sending multiple bytes only the DMA_STATUS_COMPLETE status is interesting. otherwise the semaphore will be signaled twice. Signed-off-by: Johan Carlsson <[email protected]>
1 parent 46042f7 commit ff5afd8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/spi/spi_mcux_flexcomm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct stream {
5454
uint32_t channel; /* stores the channel for dma */
5555
struct dma_config dma_cfg;
5656
struct dma_block_config dma_blk_cfg[2];
57+
int wait_for_dma_status;
5758
};
5859
#endif
5960

@@ -314,6 +315,9 @@ static void spi_mcux_dma_callback(const struct device *dev, void *arg,
314315
} else {
315316
/* identify the origin of this callback */
316317
if (channel == data->dma_tx.channel) {
318+
if (status != data->dma_tx.wait_for_dma_status) {
319+
return;
320+
}
317321
/* this part of the transfer ends */
318322
data->status_flags |= SPI_MCUX_FLEXCOMM_DMA_TX_DONE_FLAG;
319323
} else if (channel == data->dma_rx.channel) {
@@ -418,12 +422,14 @@ static int spi_mcux_dma_tx_load(const struct device *dev, const uint8_t *buf,
418422
blk_cfg->block_size = sizeof(uint32_t);
419423
blk_cfg->source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
420424
blk_cfg->dest_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
425+
data->dma_tx.wait_for_dma_status = DMA_STATUS_COMPLETE;
421426
} else {
422427
blk_cfg->source_address = (uint32_t)&data->dummy_tx_buffer;
423428
blk_cfg->dest_address = (uint32_t)&base->FIFOWR;
424429
blk_cfg->block_size = len;
425430
blk_cfg->source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
426431
blk_cfg->dest_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
432+
data->dma_tx.wait_for_dma_status = DMA_STATUS_BLOCK;
427433
}
428434
} else {
429435
if (last_packet) {
@@ -449,10 +455,12 @@ static int spi_mcux_dma_tx_load(const struct device *dev, const uint8_t *buf,
449455
blk_cfg->block_size = sizeof(uint32_t);
450456
blk_cfg->source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
451457
blk_cfg->dest_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
458+
data->dma_tx.wait_for_dma_status = DMA_STATUS_COMPLETE;
452459
} else {
453460
blk_cfg->source_address = (uint32_t)buf;
454461
blk_cfg->dest_address = (uint32_t)&base->FIFOWR;
455462
blk_cfg->block_size = len;
463+
data->dma_tx.wait_for_dma_status = DMA_STATUS_BLOCK;
456464
}
457465
}
458466

0 commit comments

Comments
 (0)