cancel
Showing results for 
Search instead for 
Did you mean: 

SPI with DMA

love-peace2001
Associate II
Posted on June 13, 2014 at 16:30

Hello;

I want to use DMA to transmit and receive data between a Slave and Master STM32 Boards.

My question is how can i configure the DMA to transfer many different Array for example? i mean i want the slave to send something like:

- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)TxBuffer;

- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Tx1Buffer;

- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Tx1Buffer;

Depending of Command received from the Master.

Thanks in advance
6 REPLIES 6
Posted on June 13, 2014 at 17:00

The DMA unit does not support scatter-gather type operations, you would need to initialize each transaction, and point it a specific buffer, of a specific size.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francescatodiego
Associate II
Posted on June 14, 2014 at 09:53

as

clive

says

you can not

do it

automatically

I

configure

DMA

and SPI

at the beginning

then

I start the SPI TX with this code

DMA_MemoryTargetConfig (Spi[id].tx_stream, txptr, DMA_Memory_0) ;

DMA_SetCurrDataCounter (Spi[id].tx_stream, txlen) ;
DMA_StreamEventFlagClear (Spi[id].tx_stream, DMA_IT_FLAGS) ;
DMA_Cmd (Spi[id].tx_stream, ENABLE);
SPI_DMACmd (Spi[id].base, SPI_DMAReq_Tx, ENABLE);

love-peace2001
Associate II
Posted on June 14, 2014 at 22:42

Thanks guys for your responses, what i want to say is :

I want to send :

- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)TxBuffer; when I receive certain command.

OR :

- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Tx1Buffer; when an another command is received.

OR:

- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Tx1Buffer; when other command is received.

@ clive: you would need to initialize each transaction, and point it a specific buffer, of a specific size. Yes I figured about it, but I have to do that in interrupt handler detects rising and falling edges of the slave select line . The problem is this initialized will take much time and so data will be lost

love-peace2001
Associate II
Posted on June 15, 2014 at 18:26

My application is as described in the schematic below :

0690X000006057zQAA.png

I want to make an application that consists of :

- The Master sends a command to the Slave , then a data

- The Master sends continuously different commands, The Slave process the command then send response depending the received command to the Master.

The Updating frequency is about 20Khz.

I tried to make this application with SPI interruption but I faced some problems in the Master side to receive data sent by the Slave.

I want to make it using DMA, but I don't know how to go.

I wonder if someone had already made this kind of application because i really need help to make progress.

Thanks in advance,

Note: The CS is handled by interruption where the SPI reception is activated in low edge

Posted on June 15, 2014 at 22:17

If the latency of setting up the DMA in the EXTI is too high, would suggest you deliver the first byte(s) to the SPI manually, and set the DMA up for the subsequent bytes.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
love-peace2001
Associate II
Posted on June 17, 2014 at 17:49

Ok clive, thank you for you response. I tried to use DMA but it's so complicated for my case (because i have many different addresses and data to handle, also have time constraint). So now I'm concentrating to optimize the SPI handler to reduce the latency.

I use the debug mode and I have noticed that the TX FIFO buffer is always at level=3, consequence the next transaction is corrupted, how can I Clear this TX buffer?

Best regards