From 30a8f87d6aec18496c87af498f7ed780bf405231 Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Thu, 19 Sep 2024 13:20:49 -0500 Subject: [PATCH] drivers: spi_mcux_lpspi: Fix synchronous DMA CS Fix the chip select when using the synchronous API with DMA path. Note need to use TxDataRequest flag instead of ModuleBusy flag now because module busy flag will not deassert until PCS deasserts. This does not fix CS for the non-DMA path, because that would require a large driver rework. Do not skip configuration when calling transceive with the same spi_cfg because we need to write a new command word. Signed-off-by: Declan Snyder --- drivers/spi/spi_mcux_lpspi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi_mcux_lpspi.c b/drivers/spi/spi_mcux_lpspi.c index ab50ed0fbd3..99c7756e5c7 100644 --- a/drivers/spi/spi_mcux_lpspi.c +++ b/drivers/spi/spi_mcux_lpspi.c @@ -199,11 +199,6 @@ static int spi_mcux_configure(const struct device *dev, uint32_t clock_freq; uint32_t word_size; - if (spi_context_configured(&data->ctx, spi_cfg)) { - /* This configuration is already in use */ - return 0; - } - if (spi_cfg->operation & SPI_HALF_DUPLEX) { LOG_ERR("Half-duplex not supported"); return -ENOTSUP; @@ -517,6 +512,8 @@ static int transceive_dma(const struct device *dev, return ret; } + base->TCR |= LPSPI_TCR_CONT_MASK; + /* DMA is fast enough watermarks are not required */ LPSPI_SetFifoWatermarks(base, 0U, 0U); @@ -531,6 +528,11 @@ static int transceive_dma(const struct device *dev, if (ret != 0) { goto out; } + + while (!(LPSPI_GetStatusFlags(base) & kLPSPI_TxDataRequestFlag)) { + /* wait until previous tx finished */ + } + /* Enable DMA Requests */ LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable); @@ -539,9 +541,6 @@ static int transceive_dma(const struct device *dev, if (ret != 0) { goto out; } - while ((LPSPI_GetStatusFlags(base) & kLPSPI_ModuleBusyFlag)) { - /* wait until module is idle */ - } /* Disable DMA */ LPSPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable); @@ -551,6 +550,7 @@ static int transceive_dma(const struct device *dev, spi_context_update_rx(&data->ctx, 1, dma_size); } spi_context_cs_control(&data->ctx, false); + base->TCR = 0; out: spi_context_release(&data->ctx, ret);