Firmware Engineer Interview Questions
Embedded C interview questions, answers, and hands-on STM32 challenges.
From public job postings
| Skill | Postings |
|---|---|
| Embedded C and register access | 72 of 114 |
| GPIO and board bring-up | 59 of 114 |
| Interrupts and shared state | 22 of 114 |
| Timers | 5 of 114 |
| UART | 33 of 114 |
| SPI | 36 of 114 |
| I2C | 30 of 114 |
| DMA | 9 of 114 |
| RTOS and concurrency | 57 of 114 |
| Watchdog and recovery | 12 of 114 |
How we counted
In November 2026, we read 114 open US job postings with “firmware” or “embedded” in the title, up to 8 per employer. We used employers’ hiring listings and counted topic mentions.
Employers can request exclusion from the next count at support@ohmwork.io.
Embedded C and register access
72 of 114 jobs
How do you read a hardware register from C?
Cast the register's fixed address to a pointer to a volatile integer of the register's width, then dereference it. On an STM32F4, *(volatile uint32_t *)0xE0042000 reads the 32-bit debug ID register. Access a register only at the widths the reference manual allows; vendor headers wrap the same idea in named structs and macros.
Practice it: Nameplate
Why does a pointer to a hardware register need volatile?
A register can change, or must be written, outside the code the compiler sees. Without volatile, the compiler may reuse an earlier read or drop a write it thinks has no effect, so a loop that polls a status bit can spin forever. volatile makes the compiler perform every read and write of that object, in program order relative to other volatile accesses. It does not make an access atomic, and it orders nothing else: the compiler may still move ordinary accesses around it. It is not a memory barrier either; a Cortex-M4 rarely needs one.
Practice it: Wait for It
How do you describe a peripheral's registers in C?
As a struct of volatile members in register order, with reserved words where the memory map has gaps, and a pointer to that struct at the peripheral's base address. Each member's offset must match the reference manual, so use fixed-width types and check offsets with offsetof or a static assert. CMSIS headers such as the STM32 GPIO_TypeDef are built this way.
Practice it: Floor Plan
How do you change one field of a register without touching the others?
Read the register, clear the field with a mask, OR in the new value shifted into place, and write it back. That read, modify, write is not atomic: if an interrupt handler also writes the register, mask that interrupt around it. Where the hardware offers set and clear registers, such as GPIO BSRR on an STM32, use them instead.
Practice it: As Found
Code works at -O0 but fails at -O2. What do you check first?
Anything shared with hardware or an interrupt handler that is not volatile, delay loops the optimiser removed, and undefined behaviour such as an uninitialised variable, a signed overflow or an out of bounds write. Higher optimisation does not cause these bugs; it exposes them.
Practice it: Phantom
GPIO and board bring-up
59 of 114 jobs
How do you set one pin high without disturbing the other pins on the port?
On an STM32, write the pin's bit to BSRR: the low 16 bits set pins and the high 16 bits reset them, and bits written as 0 change nothing. Because it is a single write, an interrupt cannot corrupt it. A read, modify, write of ODR also works, but an interrupt that changes the same port between the read and the write loses its change.
Practice it: Traffic Light
A button reads pressed when it is not. Where do you look first?
The pull resistor and the polarity. An input with no pull up or pull down floats and reads noise. A button wired to ground with a pull up reads 0 when pressed, so the logic is inverted. Then check the pin's mode bits and whether the input bounces.
Practice it: Upside Down
Why does a button need debouncing, and how do you do it?
Mechanical contacts bounce for a few milliseconds, so one press produces several edges. Sample the pin at a fixed rate and accept a new level only after it has stayed the same for a set time, such as 20 ms. Interrupting on every raw edge counts the bounces.
Practice it: Steady
More practice
- Heartbeat Blinks an LED on bare metal, the first program on a new board
- Switchboard Configures pins across GPIO ports and mirrors inputs to outputs
Interrupts and shared state
22 of 114 jobs
What does it take for a pin interrupt to reach its handler on an STM32?
Enable the SYSCFG clock and route the pin to its EXTI line, choose the rising or falling edge, unmask the line in EXTI, and enable the matching IRQ in the NVIC. The handler's name must match the vector table entry, and it must clear the line's pending bit.
Practice it: Knock
Why must an interrupt handler clear the peripheral's flag?
While the peripheral's flag is set, its interrupt request stays asserted, so the NVIC pends the interrupt again and the handler runs again as soon as it returns; the main loop starves. Clear the flag early in the handler (for a pin, write 1 to its bit in EXTI_PR). The write can take a few cycles to reach the peripheral, so clearing it as the last instruction can let the handler run one extra time; reading the register back before returning avoids that.
Practice it: Stonewall
What goes wrong when main and an interrupt both update one counter?
count++ compiles to a load, an add and a store. If the interrupt runs between main's load and store and changes count, main stores a stale value and the interrupt's update is lost. Update the variable in one place only, or mask that interrupt around main's read, modify, write (or use LDREX and STREX on a Cortex-M3 or M4). volatile is still needed so each side sees the other's writes, but volatile alone does not prevent the lost update.
Practice it: Tally
Why keep interrupt handlers short?
While a handler runs, interrupts of the same or lower priority wait, so a long handler adds latency to them and can drop events. Do the minimum in the handler (read the data, clear the flag, hand off to the main loop or a task) and give urgent interrupts a higher priority, which on a Cortex-M is a lower number.
Practice it: Chokepoint
More practice
Timers
5 of 114 jobs
How do you get a 1 ms interrupt from a 16 MHz timer clock?
The counter ticks at the timer clock divided by (PSC + 1) and the update interrupt fires every (ARR + 1) ticks. PSC = 15 gives 1 MHz, and ARR = 999 gives 1 ms. Check the timer's real clock first: by default on an STM32F4 it is twice the APB clock if the APB prescaler is not 1.
Practice it: Timekeeper
How do you measure elapsed time with a counter that wraps?
Subtract the start count from the current count in unsigned arithmetic of the counter's width. The result is correct across a wrap, as long as the interval is shorter than one full period of the counter.
Practice it: Vigil
More practice
UART
33 of 114 jobs
How do you work out the baud rate register value?
On an STM32F4 with 16x oversampling, BRR is the peripheral clock divided by the baud rate. At 16 MHz and 115200 baud that is 138.9, so BRR = 139 (0x8B), about 0.1% off, well inside the tolerance. The usual mistake is dividing the wrong bus clock.
Practice it: Tuning Fork
Characters go missing at full speed. What are your options?
If the code does not read each byte before the next one arrives, the receiver sets its overrun flag and bytes are lost. Read each byte in the receive interrupt into a ring buffer, or let DMA fill the buffer, and handle the overrun flag so reception continues (on an STM32F4, read SR then DR to clear it).
Practice it: Echo Tail
How do you turn a noisy byte stream into reliable packets?
Frame each packet with a start marker, a length and a checksum, and parse with a state machine that drops the packet and resynchronises on the next start marker when the checksum fails or bytes stop arriving. Reply with ACK or NAK so the sender knows to retry.
Practice it: Wire Tap
More practice
SPI
36 of 114 jobs
What do clock polarity and phase decide?
CPOL sets the level the clock idles at, and CPHA sets whether data is sampled on the first or the second clock edge of each bit. Together they give modes 0 to 3, and the device's datasheet says which one it uses. A wrong mode usually shows up as data shifted by one bit or as garbage.
Practice it: Identity Crisis
Every SPI read comes back 0xFF. What do you check?
0xFF usually means MISO is idling high because the device is not driving it. Check that chip select is asserted, and held low for the whole transaction (many devices end the command when it rises), then the SPI mode, the clock rate and the device's power and reset.
Practice it: Ghost on the Bus
How do you change one bit in a device's register over SPI?
Read the register over the bus, change the bit, and write the whole register back, so the other bits keep their values. Writing a constant instead silently changes the bits you did not mean to touch.
Practice it: Flight Recorder
More practice
I2C
30 of 114 jobs
The device does not acknowledge its address. What do you check?
The address format first: datasheets give either the 7-bit address or the 8-bit byte with the read or write bit, and using one where the other belongs is the most common mistake. Then power, the pull up resistors, and whether another device is holding the bus. Scanning every address shows which ones answer.
Practice it: Census
Why does an I2C bus need pull up resistors?
SDA and SCL are open drain: devices can only pull the lines low, and the resistors pull them high. Their value sets the rise time. Too large and the edges are too slow for the bus speed; too small and a device cannot sink enough current to pull the line low.
The bus locks up after a reset. Why, and how do you recover?
If the MCU resets in the middle of a read, the device can still be holding SDA low, waiting for clocks to finish its byte. Toggle SCL as a GPIO up to nine times until SDA goes high, then send a STOP before using the bus again.
More practice
- Thermometer Wakes an I2C temperature sensor by writing one of its registers
- Dead Air Diagnoses a sensor board that goes silent before its first reading
DMA
9 of 114 jobs
When is DMA worth it over one interrupt per byte?
When bytes arrive or leave fast or often enough that the cost of entering and leaving an interrupt for each one matters. DMA moves the whole block and interrupts at the end, or at half and full, leaving the CPU free.
Practice it: Conveyor
What happens if the CPU reads a buffer while DMA is still filling it?
It can read a mix of old and new data. In circular mode, use the half transfer and transfer complete interrupts to process the half that DMA is not writing. On a core with a data cache, the cache must also be cleaned or invalidated around the transfer.
Practice it: Flood
More practice
- Intake Diagnoses a DMA receive whose log does not match the frame the sensor sent
RTOS and concurrency
57 of 114 jobs
What is priority inversion, and how do you fix it?
A high priority task waits for a mutex held by a low priority task, and a medium priority task preempts the low one, so the high priority task waits on the medium one. A mutex with priority inheritance lifts the holder to the waiter's priority until it releases the mutex. FreeRTOS mutexes have it; binary semaphores do not. Keep the code that holds the mutex short.
Practice it: Behind Schedule
When do you use a mutex, and when a semaphore?
A mutex guards a shared resource: the task that takes it gives it back, and it has priority inheritance. A binary semaphore signals an event from one task, or from an interrupt, to another. Never use a mutex inside an interrupt handler.
Practice it: Baton
How does an interrupt hand work to an RTOS task?
The handler uses the FromISR form of the call, such as xSemaphoreGiveFromISR or xQueueSendFromISR, then calls portYIELD_FROM_ISR with the woken flag so a higher priority task runs as soon as the handler returns. Its priority must be one that may call the RTOS, which on FreeRTOS for a Cortex-M means numerically at or above configMAX_SYSCALL_INTERRUPT_PRIORITY.
Practice it: Turnstile
More practice
Watchdog and recovery
12 of 114 jobs
Where should the watchdog be fed, and where never?
Feed it from one place in the main loop or a supervisor task, and only after checking that every critical task has made progress. Never feed it from a timer interrupt: the interrupt keeps running while the main code is hung, so the watchdog never fires.
Practice it: Kennel
How do you tell after boot that the watchdog reset the chip?
Read the reset flags before anything clears them. On an STM32F4, RCC_CSR has a flag for each reset source (IWDGRSTF for the independent watchdog); record which are set, then clear them all with RMVF so the next reset reads cleanly.
More practice
- Night Watch Starts a watchdog timer and feeds it from the main loop
- Dead Man's Switch Uses a watchdog so that a stalled sensor restarts the board