Embedded Systems Part 4.5 - DMA
[embedded-systems
]
(Since it’s so short, I decided to just call it Part 4.5)
Computers often need to process large amounts of data coming in from various peripherals and devices. Normally, the processor is responsible for moving data to and from peripherals and memory. However, when dealing with lots of data, this can quickly bog down the processor, as it would need to speed a lot of time and resources simply moving data around.
DMA, short for direct memory access, is a solution to this problem. As its name implies, DMA allows peripherals and devices to access system memory directly without the intervention of the processor. This frees up the processor to do other things (like actually processing the data). DMA can also be used to move data from one block of memory to another.
DMA can be accomplished in two ways, first is by using a DMA controller.
Take for example, this DMA controller in an STM32 MCU. We’re not going to dive deep into what’s going on inside the DMA controller, but as you can see from the diagram, a peripheral such as an ADC can request to directly access the system memory. The DMA controller then handles this request by taking the incoming data from the peripheral bus and placing it in memory.
Another method is via bus-mastering, where a device is granted control of the memory bus and directly write to system memory without the need of a DMA controller.
Microcontrollers generally have a dedicated DMA controller as it makes things simpler since bus-mastering would require each peripheral to have its own DMA logic, which can increase complexity, cost and power consumption. Bus-mastering is generally found in more complex systems such as PCs.