A device freezes randomly once every few days in the field. How do you debug it?
What the interviewer wants to hear
- Gather data: logs, reset reason, conditions, units affected
- Add fault handlers and save crash info in non-volatile or no-init memory
- Watchdog to recover while you investigate
- Check for stack overflow, memory corruption, deadlocks and race conditions
- Reproduce with stress testing, environment changes and hardware tools
Model answer
First I collect data: which units, firmware versions and conditions, like temperature, power events or network loss. If possible I read the reset reason register and any logs. Next I make the device tell me more when it fails: a HardFault handler that saves the stacked PC, LR and fault registers to no-init RAM or flash, a task-level watchdog that records which task stopped checking in, and a small ring buffer of recent events. The watchdog also gets the device back online while I investigate. Then I look at the usual suspects: stack overflow, so I check high-water marks; heap fragmentation; deadlock between two mutexes; race conditions on shared data; counter overflows after 49 days with a 32-bit millisecond tick; and peripherals like I2C buses getting stuck. To reproduce, I run stress tests, speed up timers, and vary power and temperature, using a debugger, logic analyser or oscilloscope to catch it.
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.
- 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?
- What is DMA, when would you use it, and what pitfalls do you watch for?
- 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?