-1

I am trying to learn the basics of DMA. I watched certain videos on YouTube for the same.

I have got a few queries:

  1. Can we set/reset bits of registers using DMA? Like if I want to set the 4th bit of GPIO_ODR, can I do it using DMA?

  2. Does DMA follow polling method or interrupt method?

  3. If incase I want to set and reset bits of the registers of the GPIO (general purpose input-output) peripheral, then what would be the workflow of DMA?

Will it be: CPU->DMA->Peripheral->Register

and then for reverting back

Register->Peripheral->DMA->CPU

Is this workflow correct?

Please help me with this. Also, it would be great if you explain in simple words because I am completely new to this topic. Thanks!

-Aditya Ubarhande

  • It seems as if the videos you watched are misleading you. By DMA you cannot implement arithmetic or logic operations like setting or resetting bits. DMA is mainly only copying data from source to destination, between memories or DMA-enabled peripherals and memory. Better search for a good printed or electronic book on embedded control, YouTube is rarely a quality source. – the busybee Aug 31 '21 at 05:52

1 Answers1

0

Disclaimer: My answer is based on my experience on DMA hardware of STM32 microcontrollers.

  1. If the DMA you're using have access to the memory region where hardware registers reside (like GPIO), then yes, you can move data to these registers and change the bits. But be aware that this doesn't give you bit-wise read-modify-write access. DMA writes (or reads) the memory region (can be 8, 16 or 32 bits etc.) all at once. On STM32, Timer triggered DMA driven GPIO access can be used for synchronous parallel port implementations. On the other hand, DMA is generally used for event triggered bulk memory transfers, so using it for one time manipulation of hardware registers makes little sense.

  2. In general, you arm the DMA and it generates an interrupt when its job is done (or half complete) or when some error occurs. DMA has its own control & status registers, so you can poll them instead of enabling & using interrupts. But most of the time, using interrupts is a better idea. It's also an option (probably a bad one) to fire & forget it, if you don't need to be notified when the transfer is complete.

  3. In general, for any DMA transfer you configure source address, destination address, data length & width and the triggering condition (unless it's a memory-to-memory transfer). Of course, there can be additional settings like enabling interrupts etc.

Tagli
  • 2,412
  • 2
  • 11
  • 14