Question
DMA and Concurrency Concepts
Posted on August 22, 2013 at 18:12
I'm new to ARM and have been doing a lot of work/research on DMA on the STM32F4 Discovery board. I have multiple DMA streams working correctly for SPI to an OLED and some LED controllers but I have a fundamental question I can't seem to locate the answer to anywhere. My background is in x86 development (including multi-threading) but in higher level languages and I can't figure out how much of my experience applies to ARM and DMA.
For example, I have a byte array containing a ''video frame'' of data for my LED controllers in RAM (think an application like an LED video wall). I start the stream and it begins sending the data to the LED controllers. If I were to immediately start rendering the next frame and manipulate the data that's in the same array while DMA is still transferring and accessing it what happens? Do I need to implement my own locking mechanism to prevent modifying the data until the DMA transfer complete interrupt fires? Should I implement double-buffering to DMA transfer from one buffer while manipulating a second? Is it safe as far as the chip is concerned to modify the data if I don't care that it might send data from a previous frame mixed with data with a currently rendering frame? (I think this would effectively result in a visual ''tearing'' effect in my example case.)I really feel like I need a really firm grasp of this concept so I can effectively use all of the extra MCU cycles freed up by using DMA without stepping on DMA's toes or wasting RAM. I'll happily read a document on the subject if anyone has such a resource but I've just been unable to locate much information on the topic. Any help is appreciated!