5.5.8 · D3Embedded Systems & Real-Time Software

Worked examples — DMA — memory-to-memory, peripheral-to-memory without CPU

3,483 words16 min readBack to topic

This page is the exhaustive drill room for DMA. The parent note built the formulas; here we push them into every corner — every transfer direction, the tricky zero and degenerate inputs, the limiting cases, a real-world word problem, and an exam-style twist that hides a trap.

Everything rests on two formulas from the parent. Let us re-state them so no symbol is unearned:


The scenario matrix

Every DMA question you will ever face lands in one of these cells. The examples below are labelled [CELL n] so you can see the whole space is covered. (Recall from above: are the per-beat source/destination address steps in bytes; = forward, = fixed, = backward.)

Cell Case class What makes it special Covered by
1 Mem-to-mem, both addresses increment Ex. 1
2 Periph-to-mem, source fixed Ex. 2
3 Mem-to-periph, dest fixed Ex. 3
4 Address decrement mode (walk backward) Ex. 4
5 Degenerate: nothing moves — does time = 0? Ex. 5
6 Degenerate: wait states slow peripheral inflates every beat Ex. 6
7 Limiting case: width sweep throughput as Ex. 7
8 Real-world word problem audio streaming, must-not-miss deadline Ex. 8
9 Exam twist mixed units + the "started ≠ done" trap Ex. 9

The examples

[CELL 1] Mem-to-mem — both addresses walk forward

Compare this to memcpy and Block Copy done in software — the CPU would burn ~4 cycles/word here instead of freeing the pipeline.


[CELL 2] Periph-to-mem — source address is frozen


[CELL 3] Mem-to-periph — destination address is frozen

For continuous audio you would loop this with Circular and Double Buffering so the buffer refills while DMA drains the other half.


[CELL 4] Address-decrement mode — walking backward


[CELL 5] Degenerate input —


[CELL 6] Degenerate timing — wait states inflate every beat


[CELL 7] Limiting case — sweep the item width


[CELL 8] Real-world word problem — audio deadline


[CELL 9] Exam twist — mixed units + the "started ≠ done" trap


Scenario coverage check

Recall Did we hit every cell?

Mem-to-mem (Ex.1) ::: ✓ both deltas = +w Periph-to-mem (Ex.2) ::: ✓ source fixed (0), dest +w Mem-to-periph (Ex.3) ::: ✓ source +w, dest fixed (0) Decrement mode (Ex.4) ::: ✓ , timing unchanged degenerate (Ex.5) ::: ✓ t=0 but setup (four SCAM regs) ≠ 0 Wait states (Ex.6) ::: ✓ 5× penalty in t and throughput Width sweep limit (Ex.7) ::: ✓ , capped by bus width / alignment Real-world deadline (Ex.8) ::: ✓ ~1500× margin, meets audio deadline Exam twist (Ex.9) ::: ✓ async + cache coherency traps