A variable is randomly overwritten in devices running in the field, but you cannot reproduce it on your desk. How do you find the cause?
What the interviewer wants to hear
- Collect evidence: fault registers, crash dumps, logs in no-init RAM
- Check stack overflow and buffer overruns near the variable using the map file
- Use the MPU or data watchpoints to trap the bad write
- Look for DMA, ISR races and dangling pointers
- Reproduce field conditions: stress, temperature, power, timing
Model answer
I start by getting evidence from the field: a fault handler that saves registers, stack trace and fault status to no-init RAM or flash, plus logs that are uploaded after reboot. Then I look at the map file to see what is next to the corrupted variable, because overwrites usually come from a neighbour: an array overrun, a task stack that grew into it, or a DMA buffer with the wrong length. I add canaries around suspect buffers and enable stack overflow checks. To catch the write in the act, I use the Cortex-M data watchpoint unit, which can trigger on writes to that address even without a debugger, or configure the MPU to make the region read-only except in known code. I review ISR races, dangling pointers and DMA to freed buffers, and reproduce field conditions with stress tests, high traffic, temperature and power dips.
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Embedded Systems Engineer questions
- Design the firmware for a battery-powered sensor that must run for 5 years on a coin cell and report data every 15 minutes.
- How would you secure an IoT device's firmware against tampering and cloning?
- How do you make sure a real-time system always meets its deadlines?
- How do you build a strong automated testing strategy for embedded firmware?
- How do you choose a microcontroller for a new product?
- Design a secure, fail-safe over-the-air firmware update system for a fleet of IoT devices.
- You receive the first prototype of a new custom board. How do you bring it up?
- What changes when you write firmware for a safety-critical product, such as automotive or medical?
- How do you safely share data between interrupt handlers and tasks while keeping interrupt latency low?