Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing STM32 dma target location

Tags:

dma

stm32

I wonder if it is safe to read from the memory that dma is writing data to?

I have a stm32F1 with an adc setup to continuously perform conversions and transfer the data to a ram buffer using dma. I know I can use an adc interrupt to access the buffer safely, but how about accessing the buffer from a non-interrupt context? Could data be corrupted if I try to read from the same location that dma is writing?

like image 519
user2479653 Avatar asked Feb 11 '23 15:02

user2479653


1 Answers

Your data will not be corrupted - these chips have bus arbiter that grants access to bus (so also to RAM memory) to either DMA or the CPU (your code), so each transaction (single access to RAM, not necessarily access to whole variable) is atomic.

See this info in the RM0008 Reference manual:

3.1 System architecture

...

BusMatrix

The BusMatrix manages the access arbitration between the core system bus and the DMA master bus. The arbitration uses a Round Robin algorithm. In connectivity line devices, the BusMatrix is composed of five masters (CPU DCode, System bus, Ethernet DMA, DMA1 and DMA2 bus) and three slaves (FLITF, SRAM and AHB2APB bridges). In other devices, the BusMatrix is composed of four masters (CPU DCode, System bus, DMA1 bus and DMA2 bus) and four slaves (FLITF, SRAM, FSMC and AHB2APB bridges). AHB peripherals are connected on system bus through a BusMatrix to allow DMA access.

like image 113
Freddie Chopin Avatar answered Mar 03 '23 21:03

Freddie Chopin