Skip to main content
ATHED.1
Associate
December 14, 2021
Question

DMA circular | Changing data in mem-to-peripheral mode

I was wondering.

What will happen when changing/writing data of the memory you assigned as buffer for DMA in circular mode.

Will it be ok, garbage? Is there maybe a shadow register?

Is this for every mem-to-peripheral interface the same?

I'm very curious.

This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
December 14, 2021

It will move whatever you have flushed to memory via write-buffers or cache write-thru.

Typically you'd modify the inactive half of a ping-pong buffer at the HT/TC interrupts.

>>I'm very curious.

Enough to test/evaluate?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
KnarfB
Super User
December 14, 2021

Nothing special will happen. DMA and MCU core have both access to the memory. (Note that DMA might not have access to all addresses depending on the bus matrix.) The destination peripheral acts in the same way as if the data was written by the MCU.

So if you overwrite the DMA buffer, DMA will use these new values as soon as they were really written to the main memory (beware of caches, depending on core). To know when the time has come to overwrite parts of a DMA buffer, use the completion and half-completion IRQs/callbacks. They let the firmware know, what part of the DMA buffer is safe to write. Data streaming applications use that alot, e.g. for transfering audio packets via DMA.

hth

KnarfB

ATHED.1
ATHED.1Author
Associate
December 14, 2021

Thanks for the explanation! 

Another related question; Is there a way to set an interval for a DMA transfer in circular mode? 

It can of course be done in normal mode with a timer interrupt, but isn't there something that can do this in circular mode?

KnarfB
Super User
December 14, 2021

Works the same. You have to route a timer update event to a DMA. There was a recent topic here (with a link to code): https://community.st.com/s/question/0D53W00001FltXkSAJ/how-to-use-timer-event-dma-from-memory-to-gpio

hth

KnarfB