Overview
Curated: · Written: · Reviewed:
Hardware-Software Co-Design & Peripheral Drivers
In one line
Split each requirement between silicon, CPU and DMA, then check the split at the pins. Reach for it when a driver has a rate, deadline, power or safety requirement that the split must meet.
Key definitions
- Effect chain: requirement, API call, register or bus write, physical effect, observable evidence. A break at any link is a bug.
- Completion signal: the flag, interrupt or retired bus transaction the reference manual names as the end of the operation. An enable bit is not one.
- W1C: write-one-to-clear. Writing 1 clears the bit; writing 0 leaves it unchanged.
- Ownership handoff: the CPU owns a DMA buffer until it is armed, the DMA owns it until the TC flag, then the CPU owns it again.
- Common-cause failure: a shared clock, reference or ADC channel that defeats both a function and its monitor.
- Latency vs jitter: latency is hardware event to first handler instruction; jitter is what breaks a deadline.
Formulas and complexity
Interval between FIFO-full interrupts, 8N1 (10 bits per byte):
16-byte FIFO at 12.5 Mbaud: 16 x 10 / 12.5e6 = 12.8 µs. If the worst-case ISR takes 18 µs, the FIFO overflows, bytes are lost, and DMA becomes a requirement.
12-bit ADC LSB with a 3.3 V reference:
A 1% reference error is 33 mV, about 41 counts.
How it works
Bring-up order: enable the clock, release reset, configure pin mux and registers, then enable the peripheral and its interrupts or DMA requests.
DMA receive: the CPU arms the buffer, the DMA writes it, the TC interrupt fires, a DSB orders the access, and the driver invalidates the RX range by address before reading it.
Hypothetical worked case (figures assumed for illustration): SPI RX on an 84 MHz AHB clock. If the length is read 12 cycles after the enable write, that is 12 / 84e6 = 143 ns. If the DMA is still writing at that point, the length is stale. Moving the ownership change to the TC interrupt removes the race.
When to use and when not to
| Option | Choose when | Cost |
|---|---|---|
| Fixed-function logic | Fixed, high-rate or hard deadline; must run while the CPU sleeps | Silicon area, no field fix without a respin |
| CPU / firmware | Behaviour changes across releases; low rate | Cycles, latency, power |
| DMA | Bulk, regular transfer; CPU has other work | Bus contention, cache maintenance, a second completion model |
| Non-cacheable MPU region | DMA buffers where cache maintenance is unwanted | Slower CPU access to the region |
Traps interviewers probe
- Treating the enable bit or API return as completion. Fix: wait for the TC flag or IRQ, issue a DSB, then read the data.
- Read-modify-write on a status register. An ISR that sets a bit between the load and the store loses that event. Fix: snapshot once, decode, and clear with a single write of the handled bits.
- Freeing or reusing a DMA buffer before completion. Fix: free it from the completion path, never after polling a few bytes.
- Invalidating RX after the CPU has touched the buffer. That discards the CPU's own writes. Fix: clean TX before the transfer, invalidate RX before the read, both by address; or map the region non-cacheable.
- Monitor sharing a reference or ADC channel with the function. Fix: give the monitor an independent channel and reference and, for high integrity, its own comparator path.
Interview tips
Open by naming the effect chain and the completion signal before any register. Then give the requirement, the split, and the evidence: a scope capture on the pin and the logged length at completion.
Expect these follow-ups:
- How do you know the transfer completed? TC flag or IRQ, then DSB, then invalidate.
- What if the ISR is late? Show the arithmetic against the FIFO interval.
- Where does cache maintenance go? Clean TX before, invalidate RX before the read, by address.
- How do you test it? Unit models, bus models, HIL, fault injection, scope trace; state the fidelity of each.
- What is the errata process? Read the revision ID, branch to the matching sequence, and fail closed on unknown revisions.
30-second outline: "The requirement is X. Silicon does Y, the CPU does Z, and DMA moves W. Completion is the TC flag, then a DSB, then an address-based invalidate before the read. I prove it with a scope on the pin and a logged length at completion. If the ISR is late, the FIFO fills in 12.8 µs and bytes drop."
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.