cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple types of variables sending over SPi with DMA (solved)

megahercas6
Senior
Posted on November 07, 2014 at 08:57

Hello,

I have a project where i have multiple processors , and only one have communication link to computer. I have multiple formats to deal with, int32_t, u8,u16,f32. i could convert them to u16 and reassemble them, but could i just use DMA to transfer data to same variables on other processor without any need of conversion ?

Or simply in other words, how i can create fixed SRAM portion, where i will save variables in order i need without any gaps, so i simply could set dma address to my SRAM where i have different variables, and have exact same memory structure on other micro controller ?
6 REPLIES 6
chen
Associate II
Posted on November 07, 2014 at 12:23

Hi

I suggest you look at this in another way : OSI protocol stack layers.

The SPI that you have form the 2 lowest layers : Physical and data link.

What you want is to design a protocol or the 'packet' that get sent over SPI.

You may (or may not) want to add framing (head and tail markers)

You may (or may not) want to add error detection.

You have said that you want to have data type identification, which implies some kind of identification eg message identifiers. Each different msgId signifies a different data type eg int32_t, u8,u16,f32

megahercas6
Senior
Posted on November 07, 2014 at 23:11

well, i simply made i32_t data[5], used SPI in 16b mode, and dma with half word step with 20 elements in Circular buffer, works without to many problems

s32 does have grater range i need, so f32 will be scaled to s32

Posted on November 08, 2014 at 02:00

You could just create a struct and send it directly, two key things to keep in mind are the packing, and endian mode of the machines.

The STM32 is small/little endian, so 32-bit and 16-bit values go LSB first (SPI might have it's own bit ordering, but assume both configured the same). The float and double formats are IEEE defined, so values passed to a PC for example will be compatible. As will 8, 16, 32 and 64-bit values.

Things like ''long double'' can be a problem, but I doubt this is an issue here.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
megahercas6
Senior
Posted on November 08, 2014 at 09:12

Any ideas how to make bus safe ? (or should I worry about this)

Idea behind my worries is that it is possible to update variable, while DMA changes other half of bites, ( since it needs two transfers )

when all variables are static, it is not a problem, but they are changing fast, it could happen, or at least i think that way

Posted on November 08, 2014 at 13:35

You'd have to manage it. You'd either need to lock access or memcpy() an instant into a DMA buffer.

You might be able to hold two copies, with an index you toggle, so one reflect the data being DMA'd while the other is the one you update.

If you have to change multiple variables, you'd want to use a lock (mutex,semaphore depending on OS), and then use this everytime you access the structure. Perhaps you can use a changed flag to indicate if new data is present, or make a queuing structure/buffer.

Things will also depend on how many places in your code values are updated.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
megahercas6
Senior
Posted on November 08, 2014 at 16:19

question regarding multiple types and security is solved