cancel
Showing results for 
Search instead for 
Did you mean: 

SPI DMA stall time

jonathan239955_st
Associate II
Posted on September 10, 2015 at 17:17

I'm trying to use SPI with DMA and have had an issue in that data packets are sent too close to one another, based on the SPI stall time needing to be 2us between packets. Is there anyway I can set this through the SPI or DMA? I don't really want to have to idle the processor whilst waiting for this stall time to pass...

#stm32 #dma #spi
7 REPLIES 7
Posted on September 10, 2015 at 17:46

You can trigger the DMA not from SPI itself, but from a timer.

JW
jonathan239955_st
Associate II
Posted on September 10, 2015 at 18:41

I'm not sure that would work for me, unless I only use DMA to transfer 1 packet at a time. What I was looking at is passing the DMA a buffer of say 10 values I want to send via SPI and set it off, but somehow manage to have a stall time between each packet instead of the DMA rattling through them as fast as it can. Using DMA to send one packet at a time almost seems redundant?

Maybe I've missed something in your suggestion?

Posted on September 10, 2015 at 22:29

> I'm not sure that would work for me, unless I only use DMA to transfer 1 packet at a time.

Why not?

The timer would be set to generate a DMA-connected event (e.g. update) at a pace equal to required distance between starts of successive word (byte, ''packet''). That event would trigger the DMA to transfer a word (byte) from memory to SPI_DR. Why wouldn't this scheme be good enough?

You may be not aware of the fact that the DMA channel (stream) can transfer data between any two addresses, not being constrained to the peripheral which  triggered the transfer (there are limitations, though, e.g. 'F2/'F4 DMA1 is constrained at the peripheral port to the same APB bus where the trigger source sits - this is why it's important to tell which mcu family are you talking about).

JW

jonathan239955_st
Associate II
Posted on September 11, 2015 at 09:40

Ah, I think I get what you're saying now. So I could set up the DMA to just transfer one byte, get it to increment the memory address and then re-enable it off a timer without having to re-initialise everything, causing it to just send the next byte? I'll have a play, thanks!

Posted on September 11, 2015 at 11:05

No.

Set up the timer so that it triggers a DMA, then set the DMA's destination (peripheral) address to SPI_DR, source (memory) address to your buffer, and its NDTR to the size of buffer, and enable the timer.

JW

jonathan239955_st
Associate II
Posted on September 11, 2015 at 11:13

When you say trigger, you just mean enable the DMA? Or is there something I'm missing that lets you trigger the DMA to only transfer one item from its buffer at a time?

Posted on September 11, 2015 at 11:31

> When you say trigger, you just mean enable the DMA?

By ''trigger'' I mean the signal (wire) which comes a peripheral to the DMA, ''telling'' the DMA that it should start a transfer. Look at Fig.32 in RM0090rev10, it's what comes from the left side in the picture, REQ_STRx_CHy (''request'' is the traditional term for this signal; I should stop using ''trigger''). Look at Fig.33 in RM0090, it's the wires which go out of the peripherals on the right side, go through bottom and come into the DMA controller in the left side.

> Or is there something I'm missing that lets you trigger the DMA to only transfer one item from its buffer at a time?

For timers, there is an acknowledge going from the DMA back to the timer (this is not drawn on the figures), so that when the DMA performs the transfer, it pulses the acknowledge to clear the request, thus timer-initiated transfers are usually single ones (there is an exception but you don't need to be bothered by that at this moment).

JW