spi: spi_nxp_lpspi: DMA mode, returns -EIO or corrupted data Hi All I recently Encounter an issue with SPI DMA with Multiple Sensor communication, Where SPI transaction return -EIO or corrupted data. When Dig in to the drivers I found In DMA mode, spi_nxp_lpspi enables both LPSPI DMA request-enable bits at the start of every transfer but disables only one of them at the end. Whichever of the two DMA channels finishes second completes the SPI context without clearing its own DER bit, so every transfer leaks one request enable into the next one. In drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_dma.c, both bits are enabled together in transceive_dma() (:346): if (channel == dma_data->dma_tx.channel) {
spi_mcux_issue_TCR(spi_dev);
dma_data->state = LPSPI_TRANSFER_STATE_TX_DONE;
base->DER &= ~LPSPI_DER_TDDE_MASK;
} else {
dma_data->state = LPSPI_TRANSFER_STATE_RX_DONE;
base->DER &= ~LPSPI_DER_RDDE_MASK;
} In lpspi_dma_callback(), the channel that finishes first clears its own bit (:249–:253): if (channel == dma_data->dma_tx.channel) {
spi_mcux_issue_TCR(spi_dev);
dma_data->state = LPSPI_TRANSFER_STATE_TX_DONE;
base->DER &= ~LPSPI_DER_TDDE_MASK;
} else {
dma_data->state = LPSPI_TRANSFER_STATE_RX_DONE;
base->DER &= ~LPSPI_DER_RDDE_MASK;
} If I Clear the both bits , all transaction seems to be passed without any warnings. below is the patch I used @@ lpspi_dma_callback()
case LPSPI_TRANSFER_STATE_TX_DONE:
case LPSPI_TRANSFER_STATE_RX_DONE:
dma_data->state = LPSPI_TRANSFER_STATE_RX_TX_DONE;
/* TX and RX both done here. */
+ base->DER &= ~(LPSPI_DER_TDDE_MASK | LPSPI_DER_RDDE_MASK);
spi_context_complete(ctx, spi_dev, 0);
spi_context_cs_control(ctx, false);
break;
@@
error:
+ base->DER &= ~(LPSPI_DER_TDDE_MASK | LPSPI_DER_RDDE_MASK);
LOG_ERR("DMA callback error with channel %d.", channel);
spi_context_complete(ctx, spi_dev, ret);
spi_context_cs_control(ctx, false); Attached is a test application i used. it has the above solution build in to the app. My Question is , Is their a reason why driver only clear one bit, but not both of them ?
記事全体を表示