Direct memory access (DMA) allows peripherals to transfer data directly to and from memory without requiring the CPU to handle each cycle. As the CPU’s role is minimized, DMA enables the CPU to perform other high-priority tasks and ensures faster data transfers in the background.
How does the DMA controller work to reduce the load on the CPU?
The key benefits of the DMA controller in microcontrollers are that it offloads data transfer tasks from the CPU, allows the CPU to perform other operations during transfers, and enables high-speed data transfer between I/O and memory. The working of a DMA controller can be broken down into six steps, as shown in Figure 1.
In the first step, the CPU initializes the DMA controller by programming its registers with source address, destination address, number of bytes/words to transfer, direction of transfer, and transfer mode. While the direction of memory can be either read-from-memory or write-to-memory, the transfer mode can be single, block, or demand.
The second step is when an I/O device sends a DMA request signal to the DMA controller for data transfer. In the next step, known as bus arbitration, the DMA controller requests control of the system buses from the CPU by asserting the bus request signal. Once the CPU completes its ongoing instruction, it grants bus control to the DMA controller by asserting the bus grant signal.
Data transfer happens in the fourth step when the DMA controller generates memory addresses and control signals to read/write data directly between memory and the I/O device. It increments the addresses and decrements the transfer count after each byte/word transfer.
In the fifth step, when the specified number of bytes have been transferred, the DMA controller terminates the transfer and releases control of the system buses back to the CPU. The controller also generates an interrupt to signal the completion process to the CPU. In the last step, the CPU services the interrupt and resumes standard processing.
How is DMA used in Smartwatch for efficient data transfer?
One of the several use cases of DMA can be seen in smartwatches (Figure 2). The DMA has been used in high throughput data flow, such as Bluetooth, gyroscope, accelerometer, and LCD screen. The DMA ensures that there is a smooth flow of data between RAM and peripherals.
The core processor is seen to be behind the memory protection unit (MPU), where the data flow is regulated through memory-mapped I/O (MMIO) operations. Therefore, the DMA takes up the load of the CPU to ensure that routine data transfer is taken care of by itself to free up the CPU for higher-priority tasks.
Case study
Researchers at the University of Castilla-La Mancha, Spain, and the Ulster University, Belfast, have successfully used DMA to improve energy efficiency and writing speed compared to existing file systems when using microSD cards as a storage system for wearable devices.
A PSoC (CYBLE-222014-01) microcontroller with an ARM Cortex-M0 architecture was used along with two microSD as storage systems, one with 4 GB and the other with 8 GB. The serial peripheral interface (SPI) protocol was used as an interface because of its lower power consumption compared to standard interfaces such as UART, I2C, and SPI.
The evaluation comparison was conducted between FatFs, a standard embedded file system used in wearable devices, and the proposed DMA system with an SPI interface. The results are shown in Figure 3, where both the processes were compared for average energy consumption and time required for writing 15,872 bytes from RAM to the microSD card.
It is clear from the chart that the use of DMA at 2 Hz resulted in lesser energy consumption, 3.4 times and 7.8 times compared to FatFs, for the 4 GB and 8 GB cards, respectively. At 5 Hz, DMA’s energy savings had increased to 3.7 times and 10.6 times compared to FatFs for 4 GB and 8 GB cards, respectively.
The writing speed has also increased using DMA for 15,872 bytes from RAM to the SD card. DMA at 2 Hz led to a faster performance at 2.3 times and 3.9 times compared to FatFs for the 4 GB and 8 GB cards, respectively. While at 5 Hz, the improvements were 2.2 times and 7.8 times compared to FatFs for the 4 GB and 8 GB cards, respectively.
Summary
DMA helps speed up data transfer and lower power consumption by reducing the CPU’s involvement. As seen in the smartwatch example, DMA efficiently handles streaming data like accelerometers, heart rate monitors, etc. This is because DMA transfers this data to memory buffers without waking the CPU for every sample.
DMA is also helpful in parallel operation, depending on the microcontroller architecture, and improves real-time responsiveness. In the long run, it leads to enhanced battery life, an essential feature in low-power applications such as smart watches, drones, etc., where connection to a reliable and continuous power supply is absent.
References
D-Box: DMA-enabled Compartmentalization for Embedded Application, NDSS Symposium
What Is Direct Memory Access (DMA)? Meaning, Types, Principles, Working, and Benefits, spiceworks
Direct Memory Access (DMA) Controller in Computer Architecture, Geeksforgeeks
Direct Memory Access-Based Data Storage for Long-Term Acquisition Using Wearables in an Energy-Efficient Manner, MDPI
Leave a Reply