The Embedded New Testament

The "Holy Bible" for embedded engineers


Project maintained by theEmbeddedGeorge Hosted on GitHub Pages — Theme by mattgraham

Introduction to DMA

What is DMA?

DMA refers to the ability of an I/O device to transfer data directly to and from memory without going through the CPU. Contrast DMA with programmed I/O where the CPU explicitly copies data using loads & stores.

Why use DMA?

Why not use DMA?

What registers to set in DMA Controller?

DMA transfer steps

Diagram

DMA_Steps

Details
  1. Program makes I/O request to device
  2. CPU does initiation routine (usu. part of device driver)
    • use programmed I/O (stores) to set up control regs
    • device-specific parameters
    • DMA parameters (buffer address/length)
    • last write: enable (start) bit
  3. I/O device interface does transfer
    1. Arbitrate for bus mastership
    2. Put address on bus, assert control signals to do read/write (looks just like CPU to memory)
    3. Likely use burst transfer if available
    4. Size/type may be programmable via control reg
    5. I/O device supplies/consumes data
    6. Increment address, decrement byte count
    7. If byte count > 0, repeat
    8. Release bus to give other devices a chance
    9. if byte count == 0, set completion bit in status reg, generate interrupt
  4. CPU ISR runs completion routine (also part of driver)
    1. check for errors, retry if necessary
    2. notify program that transfer is done (e.g., set flag variable in memory)
    3. set up next transfer if appropriate (call initiation routine)
  5. Program notices that request is complete