Using IMXRT1172 LPSPI EDMA transfer API, DMA IRQ handler called before SPI transfer is done

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Using IMXRT1172 LPSPI EDMA transfer API, DMA IRQ handler called before SPI transfer is done

55 次查看
Mike_M3
Contributor III

Hi,

I've been using the LPSPI EDMA transfer API from the SDK (2.16.100) on IMXRT1172 to read and write SPI data simultaneously (i.e. a TX+RX transfer on two DMA channels with two buffers of the same size).  Unfortunately, it appears that the EDMA callback is getting called before the transfer actually finishes.  In the callback, checking LPSPI's SR, FSR, and RSR shows that SPI thinks it's still busy even though DMA thinks it's complete.  I.e. MBF is still set and TXCOUNT is 1.

SR = 0x01000100 (MBF, WCF)

FSR TXCOUNT = 1, RXCOUNT = 0

RSR = 0x00000002 (RXEMPTY, !SOF)

Now, if I was only doing TX, this could somewhat make sense as the SPI peripheral could still be clocking out the last byte loaded from DMA.  So in that case the DMA peripheral would actually be finished loading the last byte from RAM into the SPI data TX register, but SPI still had work to do to send it out.

However, when doing TX and RX simultaneously, I would have expected that if TXCOUNT was 1, then so would RXCOUNT be.  I.e. the DMA shouldn't be complete with RX until all the TX data is clocked out because the last byte needs to be transferred by DMA into RAM from the SPI RX data register, and this would only happen on the last clock cycle of the transfer.

Is this actually a problem?

If so, is it with the SDK?  Or with the hardware IP?

I was hoping to be able to check LPSPI SR in the DMA callback to determine if there are any SPI errors.

Thanks,

-m

0 项奖励
回复
2 回复数

19 次查看
mayliu1
NXP Employee
NXP Employee

Hi @Mike_M3 ,

Thank you so much for your interest in our products and for using our community.

DMA completion and SPI bus completion are two different concepts.

The eDMA callback indicates that the DMA engine has completed moving the configured number of bytes between memory and the LPSPI FIFO/register path. It does not necessarily mean that the LPSPI bus state machine has already completed the last frame or returned to idle.

For LPSPI bus completion, please check SR[TCF] or wait for SR[MBF] to clear.

mayliu1_0-1784876065178.png

mayliu1_1-1784876092476.png

 

Wish it helps you

Best Regards

May

0 项奖励
回复

13 次查看
Mike_M3
Contributor III

Yes, but in a TX/RX transfer, I would have expected the TX_COUNT and RX_COUNT to both be zero when DMA completes.  I.e., it should be impossible for RX DMA to complete before the last SPI clock, because the SPI peripheral wouldn't have shifted the last bit of the data into the RX FIFO until then, and DMA would not be able to copy the last byte into RAM until the last bit is shifted into the RX FIFO.  So in that case, both TX and RX should be completed before the DMA completes.  If it was only a TX transfer then yes, DMA could complete before SPI does and TX_COUNT could still be 1.

Thanks,

-m

0 项奖励
回复
%3CLINGO-SUB%20id%3D%22lingo-sub-2398412%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E4%BD%BF%E7%94%A8%20IMXRT1172%20LPSPI%20EDMA%20%E4%BC%A0%E8%BE%93%20API%20%E6%97%B6%EF%BC%8CDMA%20IRQ%20%E5%A4%84%E7%90%86%E7%A8%8B%E5%BA%8F%E5%9C%A8%20SPI%20%E4%BC%A0%E8%BE%93%E5%AE%8C%E6%88%90%E4%B9%8B%E5%89%8D%E8%A2%AB%E8%B0%83%E7%94%A8%E3%80%82%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2398412%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%82%A8%E5%A5%BD%EF%BC%8C%3C%2FP%3E%3CP%3E%E6%88%91%E4%B8%80%E7%9B%B4%E5%9C%A8%E4%BD%BF%E7%94%A8%20IMXRT1172%20%E4%B8%8A%E7%9A%84%20SDK%20(2.16.100)%20%E4%B8%AD%E7%9A%84%20LPSPI%20EDMA%20%E4%BC%A0%E8%BE%93%20API%20%E5%90%8C%E6%97%B6%E8%AF%BB%E5%8F%96%E5%92%8C%E5%86%99%E5%85%A5%20SPI%20%E6%95%B0%E6%8D%AE%EF%BC%88%E5%8D%B3%E5%9C%A8%E4%B8%A4%E4%B8%AA%E5%A4%A7%E5%B0%8F%E7%9B%B8%E5%90%8C%E7%9A%84%E7%BC%93%E5%86%B2%E5%8C%BA%E7%9A%84%E4%B8%A4%E4%B8%AA%20DMA%20%E9%80%9A%E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E%E5%AE%9A%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E4%BB%BB%E4%BD%95%20SPI%20%E9%94%99%E8%AF%AF%E3%80%82%3C%2FP%3E%3CP%3E%E8%B0%A2%E8%B0%A2%EF%BC%81%3C%2FP%3E%3CP%3E-m%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2398569%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Using%20IMXRT1172%20LPSPI%20EDMA%20transfer%20API%2C%20DMA%20IRQ%20handler%20called%20before%20SPI%20transfer%20is%20done%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2398569%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E5%97%A8%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F70127%22%20target%3D%22_blank%22%3E%40nxp16%3C%2FA%3E%20%EF%BC%8C%3C%2FP%3E%0A%3CP%3E%E9%9D%9E%E5%B8%B8%E6%84%9F%E8%B0%A2%E6%82%A8%E5%AF%B9%E6%88%91%E4%BB%AC%E4%BA%A7%E5%93%81%E7%9A%84%E5%85%B3%E6%B3%A8%E4%BB%A5%E5%8F%8A%E5%AF%B9%E6%88%91%E4%BB%AC%E7%A4%BE%E5%8C%BA%E7%9A%84%E4%BD%BF%E7%94%A8%E3%80%82%3C%2FP%3E%0A%3CP%3EDMA%20%E5%AE%8C%E6%88%90%E5%92%8C%20SPI%20%E6%80%BB%E7%BA%BF%E5%AE%8C%E6%88%90%E6%98%AF%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E6%A6%82%E5%BF%B5%E3%80%82%3C%2FP%3E%0A%3CP%3EeDMA%20%E5%9B%9E%E8%B0%83%E8%A1%A8%E6%98%8E%20DMA%20%E5%BC%95%E6%93%8E%E5%B7%B2%E5%AE%8C%E6%88%90%E5%9C%A8%E5%86%85%E5%AD%98%E5%92%8C%20LPSPI%20FIFO%2F%E5%AF%84%E5%AD%98%E5%99%A8%E8%B7%AF%E5%BE%84%E4%B9%8B%E9%97%B4%E7%A7%BB%E5%8A%A8%E9%85%8D%E7%BD%AE%E7%9A%84%E5%AD%97%E8%8A%82%E6%95%B0%E3%80%82%E8%BF%99%E5%B9%B6%E4%B8%8D%E4%B8%80%E5%AE%9A%E6%84%8F%E5%91%B3%E7%9D%80%20LPSPI%20%E6%80%BB%E7%BA%BF%E7%8A%B6%E6%80%81%E6%9C%BA%E5%B7%B2%E7%BB%8F%E5%AE%8C%E6%88%90%E6%9C%80%E5%90%8E%E4%B8%80%E5%B8%A7%E6%88%96%E8%BF%94%E5%9B%9E%E7%A9%BA%E9%97%B2%E7%8A%B6%E6%80%81%E3%80%82%3C%2FP%3E%0A%3CP%3E%E5%AF%B9%E4%BA%8E%20LPSPI%20%E6%80%BB%E7%BA%BF%E5%AE%8C%E6%88%90%E6%83%85%E5%86%B5%EF%BC%8C%E8%AF%B7%E6%A3%80%E6%9F%A5%20SR%5BTCF%5D%20%E6%88%96%E7%AD%89%E5%BE%85%20SR%5BMBF%5D%20%E6%B8%85%E9%99%A4%E3%80%82%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mayliu1_0-1784876065178.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22mayliu1_0-1784876065178.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F393138iABDEDECB3E9244AE%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22mayliu1_0-1784876065178.png%22%20alt%3D%22mayliu1_0-1784876065178.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mayliu1_1-1784876092476.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22mayliu1_1-1784876092476.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F393139iF966F04BCAB1891C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22mayliu1_1-1784876092476.png%22%20alt%3D%22mayliu1_1-1784876092476.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%E5%B8%8C%E6%9C%9B%E5%AF%B9%E4%BD%A0%E6%9C%89%E5%B8%AE%E5%8A%A9%3C%2FP%3E%0A%3CP%3E%E9%A1%BA%E7%A5%9D%E5%95%86%E7%A5%BA%EF%BC%81%3C%2FP%3E%0A%3CP%3E5%E6%9C%88%3C%2FP%3E%3C%2FLINGO-BODY%3E