Firmware
An embedded engineer interview on writing microcontroller firmware that meets tight memory, timing, and power limits and recovers safely from faults and power loss.
These prompts are original practice. They are not questions from a named employer or a live hiring loop.
1.A greenhouse sensor node prints every received byte with printf inside its UART (serial port) receive interrupt service routine (ISR). At higher data rates, bytes go missing. What is the most likely cause?
2.As a general rule, what should an interrupt service routine (ISR) do?
3.After the first coin is inserted, a parking meter freezes. The debugger shows the CPU entering the coin-sensor interrupt handler over and over, and the main loop never runs. What is the most likely cause?
4.On a pump motor controller, the encoder interrupt sometimes misses edges while a long analog-to-digital converter (ADC) interrupt is running at the same priority. What is the best fix?
5.What does interrupt latency measure?
6.A weather station's main loop disables interrupts while it computes a checksum over a 4 KB buffer. The serial receiver starts losing bytes. What is the best fix?
7.A formatting helper uses a static char buffer. It is called from the main loop and from a timer interrupt handler. Output sometimes looks scrambled. What is the problem?
8.Beehive scale firmware waits with while (!
sample_ready) {}. A timer interrupt setssample_ready= 1. It works with optimization off but hangs at -O2. What is the most likely cause?9.Which statement about the volatile keyword in C is true?
10.On an 8-bit microcontroller, a timer interrupt increments a 32-bit millisecond counter. The main loop sometimes sees the count jump ahead by about 256 and then go back. What is the most likely cause?
11.On an 8-bit microcontroller, main loop code reads a 32-bit tick counter that a timer interrupt updates. Which approach gives a consistent value?
12.On a bike-share dock, two tasks each run hits++ on a shared counter. Over a day, the total is lower than the real number of events. Why?
13.On a sprinkler board, main does PORTB |= LED_BIT, and an interrupt does PORTB &= ~VALVE_BIT on the same port. The valve sometimes turns back on. What is the best fix?
14.A helper disables interrupts on entry and always re-enables them on exit. It is called from inside another critical section, and a rare data corruption appears. What is the fix?
15.A serial receive interrupt writes bytes into a ring buffer and advances head. The main loop reads bytes and advances tail. Why can this work without a lock on a single-core chip?
16.On a dual-core chip in a cold-storage logger, core A fills a buffer and then sets a volatile ready flag. Core B sees the flag but sometimes reads stale buffer data. What is the fix?
17.In an irrigation controller, a low-priority logging task holds a mutex on the flash chip. A high-priority valve task waits for it. A medium-priority network task then runs for seconds. What is this called?
18.A real-time operating system (RTOS) shows priority inversion: a high-priority task waits on a mutex held by a low-priority task that keeps getting preempted. What is the standard fix?
19.In a real-time operating system (RTOS), when should you use a mutex rather than a binary semaphore?
20.In a vending machine, task A locks the serial port and then the I2C (inter-integrated circuit) bus. Task B locks the I2C bus and then the serial port. Both tasks sometimes freeze forever. What is the best fix?
21.A fixed-priority scheduler runs three periodic tasks with periods of 1 ms, 10 ms, and 100 ms, each due by its next period. Under rate-monotonic scheduling, which task gets the highest priority?
22.In a smart thermostat, the highest-priority task polls a sensor in a tight loop with no delay. The display and network tasks never run. What is the best fix?
23.A data-logging task calls
delay(10 ms)after its work, which takes 1 to 3 ms. Samples drift and are not spaced evenly. What is the better approach?24.A serial receive interrupt posts each byte to a queue, and sometimes the queue is full. What should the interrupt handler do?
25.A cooperative scheduler runs a handful of tasks in a loop. One task now does a 40 ms image compression in a single call, and button presses feel laggy. What is the core problem?
26.A developer adds a 2 KB local array to a task that has a 1 KB stack. Other tasks start crashing at random. What is the most likely cause?
27.How can you measure the peak stack use of a task on a small microcontroller with no memory protection?
28.A cafe point-of-sale terminal runs for weeks, then malloc fails for a 512-byte request even though the heap report shows 3 KB free in total. What is the most likely cause?
29.Long-running firmware suffers from heap fragmentation. Which change best removes the risk?
30.A sensor hub parses JSON from the network with a recursive parser. A message with deeply nested arrays crashes the device. What is the best fix?
31.On a typical 32-bit microcontroller, adding a 4 KB table of fixed values grows both flash and RAM use by 4 KB. What change most likely saves the RAM?
32.On a bare-metal board with no memory protection, the heap grows up and the stack grows down in the same RAM region. What happens if they meet?
33.A fan speed controller runs a filter in floating point on a microcontroller with no floating-point unit (FPU). The loop misses its 1 ms deadline. What is a common fix?
34.In Q15 fixed-point format, stored in a signed 16-bit integer, what range of values can be represented?
35.You multiply two Q16.16 fixed-point numbers held in 32-bit integers. What is the correct approach?
36.A chip has a single-precision floating-point unit. The line y = x * 0.3; with float x runs much slower than expected. What is the most likely cause?
37.A soil moisture probe sums 1000 readings from a 12-bit analog-to-digital converter (ADC) to average them. The average is often far too low. What is wrong?
38.A fixed-point audio filter on a door chime makes loud clicks on strong input. Wrapping overflow sends large positive values to large negative ones. What is the usual fix?
39.An uptime counter on a ferry ticket kiosk adds 1 to a 32-bit float every millisecond. After a few hours, the value stops increasing. Why?
40.A battery gauge converts a 12-bit reading to millivolts with mv = (raw / 4095) * 3300 using integer math. It nearly always shows 0. What is the fix?
41.A status register's flags are write-1-to-clear. Code clears one flag with STATUS |= FLAG_RX. Other pending flags sometimes vanish. Why?
42.Which C statement sets bit 5 of a control register without changing the other bits?
43.Why are memory-mapped hardware registers accessed through volatile pointers?
44.On a little-endian microcontroller, the 32-bit value 0x12345678 is stored at address 0x100. Which byte is at address 0x100?
45.A little-endian tide gauge sends a struct of 32-bit integers straight from memory to a server that expects network byte order. The numbers arrive scrambled. What is the best fix?
46.A struct holds a uint8_t followed by a uint32_t. On a typical 32-bit compiler, sizeof reports 8, not 5. Why?
47.Parser code casts a byte buffer pointer at offset 1 to uint32_t * and reads through it. On some cores this causes a hard fault. What is a safe fix?
48.On a new board for a tool rental locker, the I2C (inter-integrated circuit) bus reads all zeros or hangs, and the scope shows the lines never go high. What is the most likely cause?
49.An I2C (inter-integrated circuit) bus with 47 kilohm pull-ups works at 100 kHz but fails at 400 kHz. The scope shows slow, rounded rising edges. What is the best fix?
50.A temperature sensor datasheet lists its write address as 0x90. The I2C (inter-integrated circuit) driver takes a 7-bit address, and every transfer gets a NACK (not acknowledged). What is the likely fix?
51.A display on SPI (serial peripheral interface) returns values that look shifted by one bit, or garbage, though the wiring is correct. What should you check first?
52.A UART (serial port) link from a farm gate controller shows framing errors and random characters. Both ends are set to 8 data bits, no parity, 1 stop bit. What is the most likely cause?
53.A UART (serial port) runs at 115200 baud with 8 data bits, no parity, and 1 stop bit. Roughly how many data bytes per second can it carry?
54.A GPS module streams at high baud into a chip whose UART (serial port) has a 1-byte buffer. With a per-byte interrupt, bytes are lost when the CPU is busy. What is a good fix?
55.A 12-bit analog-to-digital converter (ADC) uses a 3.3 V reference. About how much input voltage does one step represent?
56.A vibration sensor is sampled at 1 kHz. The data shows a strong 100 Hz tone, but the real vibration is at 900 Hz. What explains it, and what fixes it?
57.A chip's analog-to-digital converter (ADC) reads a sensor through a 100 kilohm divider with the shortest sample time. Readings are low and seem to depend on the channel read before. What is the best fix?
58.A general-purpose input/output (GPIO) pin wired to a switch reads random values when the switch is open. What is the most likely cause?
59.On a chip with a data cache, DMA (direct memory access) fills a buffer from the network. The CPU then reads old data from that buffer. What is the fix?
60.A garage door keypad counts one press of a button as three or four presses. What is the most likely cause?
61.Which software method is a sound way to debounce a push button?
62.A toy robot has a bump switch wired to an edge interrupt. Each bump triggers dozens of interrupts and stalls other work. What is a good approach?
63.A water meter's firmware refreshes the watchdog from a 10 ms timer interrupt. Later, the main loop hangs, but the device never resets. Why?
64.A warehouse robot runs five real-time operating system (RTOS) tasks. How should the watchdog be refreshed so a hang in any task causes a reset?
65.What extra failure does a window watchdog catch that a basic watchdog misses?
66.A fleet of lobby kiosks reboots now and then, and nobody knows why. What should firmware do at every boot to help?
67.During a firmware update, erasing a large flash region takes longer than the watchdog timeout, and the device resets midway. What is the best fix?
68.A new release crashes early in boot, so a solar charge controller resets by watchdog again and again. How can firmware break the loop?
69.A trail counter sleeps at 10 uA (microamps) and wakes once a minute for 1 second at 6 mA. Ignoring self-discharge, about how long will a 1100 mAh battery last?
70.A prototype draws 300 uA in deep sleep, but the datasheet says the chip needs 5 uA. Several unused pins are left as unconnected inputs. What is the likely cause?
71.A team argues whether to run a sensor's processing at 64 MHz and then sleep, or at 8 MHz for longer. What should you do first?
72.A key fob checks its button in a busy loop, so the chip never sleeps and the battery lasts weeks. What is the best fix?
73.After waking from its deepest sleep mode, a wildlife camera has lost a counter that was in RAM, and it runs from the reset vector. Why?
74.A soil sensor sends each reading over radio as soon as it is taken, every 30 seconds. Radio on-time dominates power use. What is usually the biggest win?
75.A tracker on a coin cell works on the bench supply but resets whenever its radio transmits. What is the most likely cause?
76.A timeout check uses if (now >= start + timeout) with unsigned 32-bit tick counts. When does it fail?
77.A pharmacy fridge monitor locks up after about 49.7 days of uptime. What is the most likely cause?
78.A heart-rate strap samples its sensor in the main loop after other work, so samples are uneven and the filter output is noisy. What is the best fix?
79.A light strip protocol is bit-banged with GPIO (general-purpose input/output) writes. Colors glitch whenever network interrupts fire. What is the most robust fix?
80.A delay function counts a loop to 4000 to wait 1 ms. After a compiler update, the delays become much shorter. Why, and what is better?
81.A weather balloon logger's UART (serial port) works on the bench but shows garbled data at -30 C. It runs from the chip's internal RC oscillator. What is the most likely cause?
82.Firmware writes a new config byte over an old one in NOR flash without erasing first. Old value 0xF0, new value 0x3C. What will it most likely read back?
83.A heater logs a counter by erasing and rewriting the same flash page every minute. The flash is rated for 10,000 erase cycles. Roughly when will that page wear out?
84.Firmware updates its settings by erasing a flash sector and rewriting it. If power fails between the erase and the write, the settings are lost. What is the better design?
85.While erasing a sector of its only flash bank, a chip stalls the CPU and an interrupt is serviced late. Why?
86.When saving a record to flash, which order of steps best survives a power loss at any moment?
87.At boot, how should a data logger decide whether a stored settings record is safe to use?
88.An over-the-air (OTA) update scheme has two image slots, A and B. Which flow best protects against a bad new image?
89.A new image in a smart lock's B slot crashes on every boot before it can confirm itself. With a trial boot scheme, what should the bootloader do?
90.When should a newly updated image confirm itself as good in an over-the-air (OTA) update scheme?
91.Why check a cryptographic signature on a firmware image, not only a cyclic redundancy check (CRC), before an over-the-air (OTA) update is installed?
92.An attacker reinstalls an older, properly signed firmware with a known flaw on a drone. Which defense stops this?
93.A toaster oven controller updates firmware in place over its only image slot. Some units become bricks after a power cut during updates. What is the most effective design change?
94.Why do teams keep the bootloader small and update it rarely, if ever?
95.An app built for address 0x08000000 is installed in a slot at 0x08010000 behind a bootloader. It crashes right after the bootloader jumps to it. What is the most likely cause?
96.What does a brownout detector do on a microcontroller?
97.A meter's settings flash is sometimes corrupt after the mains supply dips. The brownout detector is off. What is the most important first change?
98.An energy meter must save its running total when mains power is lost. What is a common design?
99.A board has a slowly rising power supply and sometimes starts up in a strange state. What is a common fix?
100.After an unexpected reset, how can firmware tell if the state it kept in RAM is still good to use?
101.An e-bike controller takes 400 ms to write its log to flash when the battery is unplugged, but the supply only lasts 20 ms. Records are often corrupt. What is the best fix?
102.A drone's motor controller is being debugged over JTAG (Joint Test Action Group). Stopping at a breakpoint while motors spin causes faults. What is the safer approach?
103.How can you measure how long an interrupt handler takes on a board with only a logic analyzer?
104.A field device sometimes hard-faults, and no debugger is attached. What is a useful thing for the fault handler to do?
105.Adding printf calls makes a race condition in a cash register's firmware go away. What is the better way to trace it?
106.A bug only happens when the debugger's memory window shows a peripheral's status register. Without the window, the bug goes away. What is the likely reason?
107.A barometer sensor on the I2C (inter-integrated circuit) bus stops replying after a few hours. What is a good first step?
108.A bug shows up only in the optimized release build, not in the debug build. Which cause is most common in firmware?