# Embedded Systems Interview Questions

Practical answers and hands-on C challenges on a simulated STM32.

For GPIO and register basics, see the [Firmware Engineer guide](https://ohmwork.io/study-guides/for/firmware-engineer-interview).

https://ohmwork.io/study-guides/for/embedded-systems-interview-questions

Start practicing: [First Shift](https://ohmwork.io/challenge/116-first-shift)

## From public job postings

- RTOS tasks and scheduling: 57 of 114
- Task communication and RTOS pitfalls: 0 of 114
- Interrupts and concurrency: 22 of 114
- Memory, startup and the linker: 19 of 114
- Embedded C coding problems: 56 of 114
- Serial protocols and command handling: 53 of 114
- CAN bus: 36 of 114
- Debugging a running system: 41 of 114
- State machines and control loops: 27 of 114
- Low power and fault recovery: 26 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.

## RTOS tasks and scheduling

57 of 114 jobs

### What happens in main() before an RTOS scheduler starts?

main() sets up the hardware and anything else that happens once, creates the tasks, then calls `vTaskStartScheduler()`, which does not return while the scheduler runs. Each task it creates is a function with an endless loop that blocks when it has nothing to do. A FreeRTOS task must never return; one that has finished deletes itself with `vTaskDelete(NULL)`. On a Cortex-M, code after the scheduler start runs only if the scheduler failed to start, usually for lack of heap.

Practice it: [First Shift](https://ohmwork.io/challenge/116-first-shift)

### How does an RTOS scheduler decide which task runs?

In a preemptive priority scheduler the highest priority ready task runs, and it preempts a lower one the moment it becomes ready. Tasks of equal priority take turns each tick only with preemption and time slicing on (`configUSE_TIME_SLICING`, on by default). Priorities usually follow timing needs, rate or deadline monotonic being a common start, adjusted for criticality. In FreeRTOS a bigger number is more urgent, the reverse of the Cortex-M NVIC.

Practice it: [Right of Way](https://ohmwork.io/challenge/117-right-of-way)

### Why block with vTaskDelay instead of a busy wait loop?

A blocked task uses no processor time: the scheduler runs other tasks, or the idle task, until the delay ends. A busy loop keeps its task ready, so it holds the processor from every lower priority task and, with time slicing, shares it with tasks of its own priority, slowing them down. It also burns power the idle task could save.

Practice it: [Seesaw](https://ohmwork.io/challenge/25-rtos-hello)

### How do you run a task at a fixed rate without drift?

`vTaskDelay(n)` counts from when it is called, so the time the work took is added to every period and the schedule drifts. `vTaskDelayUntil(&last_wake, period)` (`xTaskDelayUntil` in newer FreeRTOS) wakes at fixed multiples of the period from the previous wake time, however long the work took, as long as the work fits in the period.

Practice it: [Clockwork](https://ohmwork.io/challenge/34-rtos-timer)

## Task communication and RTOS pitfalls

### How do you pass data from one task to another?

Through a queue. `xQueueSend` copies the item in, and `xQueueReceive` blocks the reader until an item arrives, so neither side needs a lock and nothing is read twice. Size the queue for the longest burst the producer makes before the consumer catches up; when it is full the sender blocks for the wait time it gave, then fails, and the code must decide what then. A shared global with a ready flag breaks as soon as the producer writes again before the reader is done.

Practice it: [Hopper](https://ohmwork.io/challenge/119-hopper)

### What does a critical section cost in an RTOS?

On a Cortex-M3, M4 or M7 port, `taskENTER_CRITICAL()` masks interrupts up to `configMAX_SYSCALL_INTERRUPT_PRIORITY`, the tick among them; more urgent interrupts still run. No other task runs until it exits. SysTick keeps counting and its interrupt runs on exit, but a section that spans two ticks loses one, so kernel time falls behind. Hold one only around the few reads and writes that must happen together, not around the work that produces the data.

Practice it: [Famine](https://ohmwork.io/challenge/31-task-starvation) PRO

### How do you size a task's stack, and how do you catch an overflow?

Size it for the deepest call path the task can take: locals, nested calls, library calls such as printf, and the registers the processor saves on the task's stack when an interrupt arrives (more with the FPU in use). Then measure: `uxTaskGetStackHighWaterMark` reports the least free stack seen so far, and `configCHECK_FOR_STACK_OVERFLOW` can catch an overrun at a context switch and call a hook, though not every overrun. An overflow corrupts whatever sits next to the stack, often another task's control block, so the task that fails is not always the one at fault.

Practice it: [Quiet Pulse](https://ohmwork.io/challenge/35-stack-smash) PRO

## Interrupts and concurrency

22 of 114 jobs

### What does an interrupt's pending bit tell you, and what does it not?

That at least one triggering edge happened since it was last cleared: not which edge, and not how many. Two edges before the handler runs set it once, so they count as one. Arm only the edge that marks the event and keep the handler short; if every pulse must be counted at high rates, let a timer count them in hardware.

Practice it: [Stampede](https://ohmwork.io/challenge/14-isr-event-logger)

### Why should an interrupt handler not call printf?

printf and the stream it writes to keep their work in progress in state that every call shares, so a handler that prints while main is inside printf breaks both lines. printf is also slow, may allocate memory, and may wait on the UART, all of which stretch the handler. Have the handler record what happened in a flag, counter or queue, and print from one place in main or a task.

Practice it: [Crosstalk](https://ohmwork.io/challenge/128-crosstalk)

### A buffer fills faster than it drains. What should the code do?

Pick a policy and make it explicit: refuse the newest item or overwrite the oldest, and count what was dropped so the loss is visible. Code with no policy often writes over items nobody has read and still reports them as new. Size the buffer for the longest burst you must survive, and track full and empty exactly, with a count, free running indexes, or by keeping one slot free, since with wrapped indexes, equal read and write can mean either.

Practice it: [Uplink](https://ohmwork.io/challenge/21-telemetry-queue) PRO

## Memory, startup and the linker

19 of 114 jobs

### What runs between reset and main()?

A Cortex-M core loads the stack pointer from the first word of the vector table and jumps to the reset handler in the second. The startup code copies initialized data (.data) from flash to RAM, zeroes .bss, runs the C library's and any C++ constructors, and calls main; ST's startup code also calls `SystemInit`, which can set the clocks and enable the FPU. The copy loops use linker symbols such as `_sdata`, which are addresses: use `&_sdata` (or declare it as an array) and never the value stored there.

Practice it: [Cold Start](https://ohmwork.io/challenge/20-boot-hang)

### Where do code, constants, globals and locals live in memory?

On a typical microcontroller, code and const data sit in flash (.text and .rodata). Initialized globals and statics live in RAM in .data, their starting values copied from flash at boot; zero-initialized ones live in .bss, cleared at boot. Locals live on the stack, and malloc takes from the heap. Writing a const object is undefined behavior in C; a store to flash may be ignored, set an error flag or fault, depending on the part, and the compiler may answer reads from the initializer anyway. Settings that change at run time need a RAM copy.

Practice it: [Lost in Translation](https://ohmwork.io/challenge/66-lost-in-translation) PRO

### Is dynamic allocation safe in firmware?

It is often avoided: the heap can fragment until a request fails long after boot, allocation time varies, and a leak fails only when memory runs out, far from the code at fault. Many systems allocate everything at start up or use fixed size block pools. Where buffers are allocated and passed between tasks, decide who owns each one: whoever holds it last frees it, on every path, error paths included.

Practice it: [Stops at Twelve](https://ohmwork.io/challenge/36-ration) PRO

## Embedded C coding problems

56 of 114 jobs

### How do you read a multi-byte number sent high byte first?

Build it from the bytes with shifts: `(uint16_t)((b[0] << 8) | b[1])`, or for 32 bits `((uint32_t)b[0] << 24) | ((uint32_t)b[1] << 16) | ((uint32_t)b[2] << 8) | b[3]`. That means the same on every CPU. A cast or memcpy reads the bytes in the CPU's own order, little endian on an STM32, so the value comes out swapped. Cast to `uint32_t` before shifting by 24, or the byte shifts into the sign bit of an int.

Practice it: [Weather Report](https://ohmwork.io/challenge/107-weather-report)

### Why not read a packet by casting its bytes to a struct?

The compiler lays out a struct, not the wire: it may add padding between members to align them, so every field after a gap reads the wrong bytes. The struct also takes the CPU's byte order. Either build each field from the bytes, or pack the struct, fix the byte order, and assert that its size matches the wire, such as `_Static_assert(sizeof(struct pkt) == 7, "pkt")`.

Practice it: [Crossed Wires](https://ohmwork.io/challenge/65-misaligned) PRO

### How do you print a fixed point value without floating point?

Split it into sign and magnitude first. For hundredths, -50 must print -0.50, but `-50 / 100` is 0 and `-50 % 100` is -50, because C division rounds toward zero, so the sign is lost from the whole part. Print the sign yourself, then `mag / 100`, then `mag % 100` with `%02u`. Take the magnitude in an unsigned type so the most negative value still works.

Practice it: [Readout](https://ohmwork.io/challenge/00-hello)

### A sensor byte above 127 reads as negative. Why?

It was stored in a signed 8-bit type: 200 is 0xC8, which as an `int8_t` is -56, and a negative value slips under an upper bound check. Whether plain char is signed is implementation defined: GCC makes it unsigned on ARM EABI and signed on x86, and `-fsigned-char` or `-funsigned-char` changes that. Keep raw bytes in `uint8_t` and convert only as the datasheet says.

Practice it: [Fallback](https://ohmwork.io/challenge/17-sensor-degraded-mode)

## Serial protocols and command handling

53 of 114 jobs

### How do you read commands typed on a serial console?

Collect bytes into a line buffer and act only when the line ends (CR or LF), so a command is the line as it stands when Enter is pressed. Apply edits such as Backspace to the buffer as they arrive, never index outside it, and when a line is too long, discard it and report an error instead of writing past the end. Compare the whole line with each command; a prefix match accepts typos.

Practice it: [Dispatcher](https://ohmwork.io/challenge/06-uart-command-parser) PRO

### SPI only exchanges bytes. How do you read a register?

Full duplex SPI shifts one byte out and one byte in at the same time, so to read you must send something. With chip select low, send the register address (with the device's read bit, often bit 7), then send a dummy byte such as 0x00 to clock the answer in. The byte received while the address went out is meaningless, but read it: unread on an STM32F4, the answer overruns it and is thrown away.

Practice it: [Postcard](https://ohmwork.io/challenge/60-spi-write-read)

### How do you read several registers from an I2C device in one transaction?

Write the first register address, then send a repeated START with the read bit, so the bus is never released in between, and read the bytes in one go; many devices advance the register address by themselves, some only with an auto increment bit set in the address. ACK every byte except the last, NACK the last so the device stops sending, then send STOP. On an STM32F4 the NACK must be set up before the last byte arrives, so the end of a read is time critical.

Practice it: [Scroll](https://ohmwork.io/challenge/61-scroll) PRO

### More practice

- [Afterthought](https://ohmwork.io/challenge/43-crosstalk) PRO: Diagnoses a sensor board that prints its first reading and then stops

## CAN bus

36 of 114 jobs

### How does a CAN node decide which frames to keep?

With acceptance filters: each filter bank matches the ID against a value and a mask, or a list of IDs, and only matching frames reach a receive FIFO. Filter in hardware, because every unwanted frame on a busy bus takes a slot in the same small FIFO (three frames each on an STM32F4) and can push out the frames you need. On an STM32F4 a filter bank passes nothing until it is activated.

Practice it: [Cocktail Party](https://ohmwork.io/challenge/113-cocktail-party)

### How do you keep an urgent CAN message from waiting behind routine traffic?

On the wire, the frame with the lowest ID wins arbitration, so urgent messages get low IDs. In the receiver, give the urgent ID its own path: on an STM32F4, a filter that sends it to the second FIFO, served first or by its own interrupt. Sharing a FIFO with routine frames, it waits behind them and can be lost when the FIFO overflows.

Practice it: [Big Red Button](https://ohmwork.io/challenge/114-big-red-button) PRO

### A CAN node stops communicating after repeated bus errors. Why?

Every node counts its transmit and receive errors. Above 127 it becomes error passive, and when its transmit error count passes 255 it goes bus off and stops taking part in the bus. It stays off until it recovers: on an STM32F4, set ABOM for automatic recovery after 128 runs of 11 recessive bits, or have firmware detect bus off and restart the controller. Code that only waits for frames cannot tell a quiet bus from a controller that has shut itself off.

Practice it: [Flatline](https://ohmwork.io/challenge/77-flatline) PRO

### More practice

- [Dispatch Bay](https://ohmwork.io/challenge/75-dispatch-bay) PRO: Diagnoses a CAN node whose log stays blank while its commands are on the bus

## Debugging a running system

41 of 114 jobs

### Serial output is garbled. How do you find the cause?

Steady garbage is usually a baud mismatch, and that usually means the clock is not what the code assumes. Measure the bit time with a scope or logic analyzer, then read the clock and UART registers on the running board instead of trusting comments or the schematic: an STM32 boots on its internal oscillator, and firmware must switch to the crystal itself. A rate exactly double or half the target points to a wrong clock assumption.

Practice it: [Drift](https://ohmwork.io/challenge/49-drift) PRO

### A variable changes though no code writes it. What do you suspect?

A write that ran past its target: an array or string with no bound check, a stack overflow, a stray pointer, or DMA into the wrong buffer. Look in the linker map file for what sits just before the variable, and set a data watchpoint on its address to stop on the write that changes it. Then fix the write that overflows; moving or guarding the victim only waits for the next thing it hits.

Practice it: [Quicksand](https://ohmwork.io/challenge/67-quicksand) PRO

### How do you get debug output when the serial port is taken?

On a Cortex-M3, M4 or M7, send it over the trace port: the ITM puts characters on the SWO pin for the debug probe to read. With newlib, printf hands every character to `_write`, so a `_write` that writes to ITM stimulus port 0 moves the whole console. Other options are toggling a spare pin for a scope, or logging to a RAM buffer the debugger reads.

Practice it: [Back Channel](https://ohmwork.io/challenge/127-back-channel)

## State machines and control loops

27 of 114 jobs

### Should firmware act on input events or on input state?

It depends on the input. State suits levels you can read again at any time: it is right from the first read, even on a board that boots with the button already held and never sees the press. Events suit edges, counts and things that come and go between reads. Many designs use events to wake up and state to decide.

Practice it: [Light Switch](https://ohmwork.io/challenge/03-button-press)

### How do you keep a state machine responsive to faults?

Latch the fault if it can come and go, and check it, with every other exit condition, on each pass through the machine, in every state. A state that waits out a fixed dwell with a blocking delay is blind to the fault for that whole time, unless something else acts on it. Keep the wait as a condition, time since the state began compared with the dwell, tested on each pass after the fault check.

Practice it: [Automaton](https://ohmwork.io/challenge/73-automaton) PRO

### What is integrator windup, and how do you prevent it?

When the output saturates at a duty limit, a clamp or a slew limit, the error persists and the integral keeps growing on drive the actuator never delivered. When the error reverses, that stored integral must unwind first, so the output overshoots. Stop integrating while the output is limited, or feed back the gap between commanded and delivered output, and clamp the integral.

Practice it: [Slingshot](https://ohmwork.io/challenge/90-windup) PRO

## Low power and fault recovery

26 of 114 jobs

### What do WFI and sleep on exit do on a Cortex-M?

`WFI` stops the core until an interrupt arrives; the handler runs, then execution continues after the WFI. With SLEEPONEXIT set in the SCB's SCR register, the core instead goes back to sleep as soon as the handler returns to thread mode, so the code after the WFI does not run. That suits a design whose work is all in handlers; with work in the main loop, the loop stops until SLEEPONEXIT is cleared.

Practice it: [Hibernation](https://ohmwork.io/challenge/78-hibernation)

### A drive stops on a fault and never restarts after the fault clears. Why?

The fault flag is latched: it records that the fault happened, not that it is still there, and it stays set until firmware clears it, often by writing 1 to it. Read the flags, log them, and clear the ones you read when you are ready to retry; a fault still present sets its bit again. Restarting without clearing usually stops again at once.

Practice it: [Seized](https://ohmwork.io/challenge/89-locked-rotor) PRO
