MKS22 SPI1 module DMA for TX and RX

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

MKS22 SPI1 module DMA for TX and RX

跳至解决方案
1,646 次查看
chris_f
Contributor V

I'm trying to use multiple DMA channels to fill PUSHR and empty POPR on _both_ SPI modules of an MKS22.

SPI0 is working fine but SPI1 is not behaving as expected.

If I only use DMA to fill PUSHR, that works fine.

I noticed that the MKS22 only has one DMA request line for SPI1 so it looks like it isn't possible to use DMA for both TX and RX for SPI1. Is that right? Is there a workaround?

标签 (1)
标记 (1)
1 解答
1,470 次查看
miduo
NXP Employee
NXP Employee

Hello,

Your understand is correct. From the reference manual, Table 22-1, there listed that SPI0 use dedicated DMA source numbers for TX and RX. However, for SPI1, the DMA source are shared( Transmit or Received).That is the reason why your situation is.

pastedImage_1.png

在原帖中查看解决方案

3 回复数
1,469 次查看
fcw
Contributor IV

There is a work-around. This is hinted in the DMA multiplexer "Chip Configuration" section of the controller's reference manual, but the manual doesn't go into detail.

If you have a PIT timer available:

1. Perform receive side setup in the same manner as for SPI0.

2. Set up the transmit side DMA on channel 0..3 depending on the PIT timer channel to be used. Select one of the always-enabled request sources in the channel configuration register, and set the TRIG bit.

3. Configure the DMA transmit descriptor for memory-to-register transfer.

4. Set the PIT timer period. The period of the timer must be a bit longer than the SPI byte transfer time so that the transmit buffer is empty when the transmit DMA channel writes the next byte. Trial and error with an oscilloscope, or calculate it...

5. Set the SPI chip select. It mayt be possible for the SPI controller to do this, I'm doing it in code.


6. Enable the receive-side DMA transfer. Nothng happens since no SPI clocks are generated.

7. Enable the transmit-side DMA transfer. Transfer occurs.

8. Negate the chip select via interrupt callback when the transfer completes.

I'm guessing something similar works using one of the flex timer channels as trigger source, but I haven't verified that.

1,469 次查看
chris_f
Contributor V

Thanks for the suggestion Fred. If I understand correctly, there's still an interrupt for every transfer. It's that interrupt for every transfer that I need to avoid due to the 30+ cycle overhead. I've solved my problem by interspersing SPI1 sends/reads through other predictable code patterns.

0 项奖励
回复
1,471 次查看
miduo
NXP Employee
NXP Employee

Hello,

Your understand is correct. From the reference manual, Table 22-1, there listed that SPI0 use dedicated DMA source numbers for TX and RX. However, for SPI1, the DMA source are shared( Transmit or Received).That is the reason why your situation is.

pastedImage_1.png