UART and DMA Data Transmission

Concept of DMA

DMA (Direct Memory Access) allows data transfer without direct control from the CPU. It creates a direct pathway for data transfer between RAM and I/O devices, significantly improving CPU efficiency.

UART and DMA Data TransmissionThere are several methods for UART data reception: the interrupt mode of UART isthe most commonly used data transmission method in microcontrollers, similar to a courier who needs the boss (CPU) to personally supervise:

  • • Each time a package (byte of data) is delivered, it reports back to the boss
  • • The boss must stop other tasks (like controlling a motor) to handle the package
  • • The advantage is simplicity and ease of understanding, like a small supermarket owner personally handling the cash register
  • • The disadvantage is that the boss can get too busy, and when there are too many packages (high-speed data transfer), it is easy to miss packages or delay other work

UART+DMA (Direct Memory Access) is an advanced courier system that does not require the boss to handle everything personally:

  • • The boss only needs to tell DMA: “Deliver 1000 packages from the warehouse (memory) to the workshop (peripheral)”
  • • DMA opens a dedicated channel, transporting data in bulk like a conveyor belt, allowing the boss to attend to other tasks
  • • Only after all packages are delivered does it inform the boss, “Task completed”

DMAMemory Access Technology is beneficial because it serves peripherals directly without CPU intervention, allowing the CPU to handle other tasks, thus improving system efficiency. For slow devices like UART, it mainly reduces CPU usage, but for high-speed devices like hard drives, it not only reduces CPU usage but also increases hardware throughput. For such devices, the speed at which the CPU supplies data is too low. The CPU can only access the bus once per bus cycle, and for ARM, it cannot directly move the value from address A in memory to address B. It must first move the value from address A to a register, and then from that register to address B. This means that for ARM, it takes two bus cycles to send the value from address A to address B. DMA, on the other hand, typically has burst transfer capabilities, allowing it to transfer several or even dozens of bytes of data at once, greatly enhancing the throughput capability of the device.UART and DMA Data Transmission

DMA transfer involves copying data from one address space to another. When the CPU initializes this transfer, the transfer itself is executed and completed by the DMA controller. A typical example is moving a block of external memory to a faster internal memory area. Such operations do not delay the processor’s work; instead, the CPU can handle other tasks.

There are four modes of DMA transfer:Memory → Memory, Memory → Peripheral, Peripheral → Memory, Peripheral → Peripheral

Differences Between DMA and Interrupts

The interrupt method issues an interrupt after the data buffer register is full, requiring the CPU to handle the interrupt, while the DMA method requests the CPU to handle the interrupt only after the entire block of requested data has been transferred. This greatly reduces the number of interrupts the CPU must handle. (Increased interrupt frequency can lead to data loss.) In the interrupt method, data transfer is controlled by the CPU during interrupt handling, while in the DMA method, it is completed under the control of the DMA controller without CPU intervention. This eliminates issues such as the CPU being unable to keep up with too many parallel devices and data loss due to speed mismatches.

There are several methods for UART data reception:

  • Polling Mode: The program loops to check if a new character has been received and reads it quickly enough to capture all bytes. Advantages: Easy to implement, but rarely used in real projects. Disadvantages: Easily misses received characters during burst data. Only suitable for low baud rates. The application must check for new data very quickly.
  • Interrupt Mode (without DMA): UART triggers an interrupt, and the CPU jumps to the interrupt routine to handle data reception. Advantages: Currently the most commonly used method in programs. Works well at low rates. Disadvantages: Requires executing the interrupt routine for each received character, wasting CPU resources.
  • DMA Mode: DMA is used to transfer data from the UART RX data register to user memory at the hardware level. Other than when the application needs to process received data, there is no need for application interaction. Advantages: The transfer from the UART peripheral to memory is completed by hardware without CPU interference. In cases of large data bursts, increasing the data buffer size can improve functionality. Disadvantages: If communication fails, DMA may not notify the application of all transmitted bytes.

Leave a Comment