What is DMA, when would you use it, and what pitfalls do you watch for?
What the interviewer wants to hear
- DMA moves data between peripherals and memory without the CPU
- Good for ADC streams, UART/SPI bulk transfers and audio
- Circular and double-buffer (half/full transfer) modes
- Cache coherency on cores with data cache
- Buffer lifetime, alignment and memory regions DMA can reach
Model answer
DMA is a hardware engine that copies data between peripherals and memory, or memory to memory, without the CPU moving each byte. I use it for continuous or bulk data, such as ADC sampling at high rates, receiving UART streams, SPI display updates or audio. A common pattern is circular mode with half-transfer and transfer-complete interrupts, so the CPU processes one half of the buffer while DMA fills the other. Pitfalls: on cores with a data cache, like Cortex-M7, I must clean the cache before a transmit and invalidate it after a receive, or place buffers in non-cacheable memory, with buffers aligned to cache lines. The buffer must stay valid for the whole transfer, so never a local stack variable that goes out of scope. Some DMA controllers cannot reach every RAM region, so I check the bus matrix in the reference manual.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Embedded Systems Engineer questions
- How would you write a driver for a new I2C temperature sensor?
- Explain the difference between a mutex and a semaphore in an RTOS, with examples.
- A device freezes randomly once every few days in the field. How do you debug it?
- Explain the memory layout of a typical microcontroller program: .text, .data, .bss, stack and heap.
- When would you use fixed-point arithmetic instead of floating point on a microcontroller?
- Design firmware that receives text commands over UART, like "SET LED 1", and responds reliably.
- Explain how the CAN bus works and why it is popular in automotive and industrial systems.
- Your firmware is close to the flash and RAM limits of the MCU. How do you reduce memory usage?
- How would you design a watchdog strategy for firmware running several RTOS tasks?