Memory Technologies

What Is DMA (Direct Memory Access)? From Basics to High-Speed Storage Solutions

DMA (Direct Memory Access) is a key technology in embedded system design that enables high-speed data transfers without CPU intervention. This article explains its fundamental operating principles, its integration with UART, SPI, and ADC, as well as bus contention and key considerations when writing to non-volatile memory.

Understanding the Basic principles of DMA (Direct Memory Access)

DMA is a fundamental technology for data transfer in embedded systems. Understanding its basic mechanism and how it differs from conventional data transfer methods is the first step towards efficient design.

What Is DMA? How Data Moves Without CPU Involvement

DMA (Direct Memory Access) is a mechanism for directly transferring data between peripheral devices and memory, or between peripherals and memory, or from memory-to-memory, without CPU involvement. While the CPU handles all read and write operations in normal data transfer, DMA uses a DMA controller (DMAC) to handle the transfer process. The CPU only needs to instruct the DMAC on the source address, destination address, and transfer size, allowing it to perform other tasks concurrently during the transfer. This significantly improves the overall system throughput and responsiveness.

Differences from PIO and Why DMA is Necessary

Before DMA, the prevailing approach was PIO (Programmed I/O). In the PIO method, the CPU directly executes all data transfer processes, meaning the CPU cannot perform other tasks during the transfer, and software overhead is added to the processing time. On the other hand, because the DMAC directly executes the transfer process in hardware, DMA allows for transfers that are both faster and lighter on the CPU than PIO when handling large amounts of data. The advantages of DMA are particularly evident in workloads that generate a steady stream of data, such as continuous ADC sampling and serial communication.

The Role of the DMA Controller (DMAC) and Bus Arbitration

The DMA controller (DMAC) is a dedicated hardware that controls data transfers on behalf of the CPU. The DMAC accesses the source and destination through the system bus. Because the CPU also uses the same bus, access to the bus must be arbitrated. This mechanism is known as bus arbitration, and the hardware responsible for performing it is called a bus arbiter. While the CPU is using the bus, the DMAC must wait. Conversely, while the DMAC has control of the bus, the CPU cannot access it. Correctly understanding this relationship during the design phase is key to building a stable embedded system.

Applying DMA in Embedded Systems

After understanding the fundamentals of DMA, the next step is to examine how it is applied in practical embedded systems. The core of implementation lies in configuring the DMA controller built into the microcontroller and coordinating it with the various peripheral devices.

Configuring On-Chip DMA: Channels and Basic Settings

Many microcontrollers have a built-in DMA controller, and a configuration with multiple channels is common. Each channel is mapped to specific peripherals, and it is necessary to select the appropriate channel based on the peripheral being used. Settings include the source address, destination address, transfer size, whether address increment is enabled, and the transfer mode. By accurately setting these during initialization, automatic transfer can be achieved without software intervention. Incorrect settings can lead to data corruption or system lockups, so careful examination of the datasheet is essential before implementation.

Improving Efficiency Through DMA Integration with UART, SPI, and ADC

DMA is particularly effective in embedded development when used in combination with peripherals such as UART, SPI, and ADC. In UART applications, integrating the transmit and receive buffers with DMA can significantly reduce the number of interrupts, improving CPU processing efficiency. Since SPI is intended for high-speed communication, the CPU can struggle to keep pace with the link without DMA. Combining DMA with the ADC’s continuous conversion mode eliminates the need for the CPU to read each value individually, allowing sampled data to be stored in memory automatically and continuously. These applications make it possible to realize systems with high real-time performance.

DMA Transfer Modes and Their Applications

DMA controllers typically offer normal, circular, and burst transfer modes. Normal mode is a simple operation where DMA stops upon completion of a specified data transfer size, suited to one-shot transfers. Circular mode automatically returns to the starting address after transfer completion, making it suitable for applications requiring continuous data transfer, such as ADC continuous sampling or audio streams. Burst mode improves bus efficiency by transferring multiple bytes at once, contributing to faster transfers of large amounts of data, but note, however, that burst mode extends bus occupancy.

Challenges and Design Considerations When Using DMA

While DMA offers significant benefits, incorrect design can seriously impact system stability. Understanding these practical challenges and applying appropriate countermeasures is essential.

The Impact of Bus Contention and Cycle Stealing on Real-Time Control

Since DMA and the CPU share the same bus, the DMAC temporarily takes bus ownership from the CPU when DMA performs a transfer. This phenomenon is called “cycle stealing.” Bus occupation due to DMA transfers can disrupt the execution timing of the main process, especially in embedded systems requiring microsecond-level timing precision. Effective countermeasures include avoiding burst mode and selecting cycle-stealing mode, or splitting the transfer data to shorten the occupation time for each transfer. Clearly defining the system’s response requirements in advance and carefully selecting the DMA bus mode leads to improved design quality.

DMA Transfers to Non-Volatile Memory: Design Considerations

When writing data to non-volatile memory using DMA, a design that fully considers the write characteristics of the memory device is required. For devices that require a certain amount of time to write, such as flash memory, starting the next DMA transfer before the write is complete risks data corruption. Furthermore, for devices with a limited number of write endurance, frequent DMA writes accelerate wear-out. In contrast, FeRAM (FRAM, ferroelectric memory) possesses characteristics of high write speed and extremely high write endurance, making it a strong option for applications involving frequent writes via DMA.

Key Points and Future Prospects for Applying DMA in Embedded Design

This article has covered DMA from basic operation through embedded application and design pitfalls. DMA is a technology that can significantly improve system performance when properly designed and utilized, but to maximize its effectiveness, it is essential to determine the transfer conditions and understand the characteristics of the memory device. The following sections distill the practical takeaways for working designers and the outlook ahead.

Summary of Key Points for Applying DMA in Embedded Systems

Effective DMA use starts with an accurate picture of how much data moves and how often. For single transfers of small amounts of data, PIO may have a shorter total processing time, so the decision to introduce DMA must be made carefully. Furthermore, it is important to estimate the impact of bus arbitration on CPU processing in advance and weigh it against the system’s real-time requirements. In addition, by carefully designing the timing of transfer completion interrupts and buffer management, the advantages of DMA can be maximized.

Guidelines for Selecting DMA Design Based on System Requirements

The choice of DMA design varies greatly depending on the system’s application and constraints. For control systems where real-time performance is paramount, a design that minimizes bus occupancy time, primarily using cycle-stealing mode, is appropriate. On the other hand, for data acquisition systems where throughput is paramount, actively utilizing burst mode or circular mode can improve transfer efficiency. Furthermore, the characteristics of the target memory device directly influence the selection of the DMA design. Comprehensively evaluating write speed, endurance, and interface specifications, and combining the optimal memory and DMA configuration for the application requirements, leads to improved design quality and ensures long-term reliability.

Why FeRAM Pairs Well with DMA

In applications requiring high-frequency, high-speed writing via DMA, FeRAM offers advantages over flash memory and EEPROM. FeRAM supports byte-level writes and high-speed writes, making it highly compatible with configurations that continuously transfer data via DMA, and minimizing bottlenecks caused by write latency. Additionally, because no erase step is needed before writing—unlike with flash memory—system design is considerably simpler when paired with DMA. For embedded applications requiring frequent updates of sensor logs and configuration values, a combination of DMA and FeRAM can be an effective solution.

RAMXEED FeRAM Product Lineup

Share this article