472 questions
Embedded systems interview questions
Every question we’d ask a firmware candidate, with a full worked answer on each page — from pointers and bit manipulation to RTOS scheduling, bus protocols, and on-chip debugging.
Programming Fundamentals
60 questions
Input & Output
- Why does scanf need an & in front of its arguments but printf doesn't?
- What does scanf return, and why should you check it?
- What's the difference between stdout and stderr, and when do you use each?
- You read a number with %d and then read a character with %c, but the %c doesn't wait for input. Why?
- Why is scanf("%s", name) dangerous, and what should you do instead?
while & do-while Loops
- What's the difference between while and do-while?
- What's a loop invariant, and how does it help you reason about a loop?
- Why does while (i >= 0) with an unsigned i never exit?
- What's the right way to write an event loop with while (1)?
- You wrote a while loop and the body never runs. What are the most likely causes?
for Loops, break & continue
- When should you reach for for instead of while?
- What's the difference between break and continue?
- How do you break out of two nested loops in C?
- Why does continue inside a while loop sometimes cause an infinite loop, but not inside a for?
- What's the difference between for (int i = 0; ...; i++) and for (int i = 0; ...; ++i)?
Functions
- What does "pass by value" mean in C, and what does it not let you do?
- What's the difference between local, global, and static variables?
- Why is int main() not the same as int main(void)?
- When should you use a prototype declaration versus defining the function before its caller?
- Why is having many global variables a code smell?
Errors & Debugging
- What's the difference between a compile-time error, a runtime error, and a logic error?
- The compiler prints fifteen errors. Where should you start?
- What is bisection in debugging?
- Why turn on -Wall -Wextra and -Werror?
- You added a printf to debug, the bug went away, and removing the printf brings it back. What's likely going on?
C Programming
55 questions
The C Compilation Pipeline
- Walk me through what happens when you compile a C program.
- What's the difference between a declaration and a definition?
- You get "undefined reference to uart_init". What stage failed and what are the likely causes?
- Why does changing one header file trigger a rebuild of many source files?
- On an embedded target, what extra build steps exist beyond a desktop compile, and why?
Pointers & Addresses
- What is a pointer, really?
- Why can't a normal function swap two ints, but a function taking pointers can?
- What are the ways a pointer can be invalid, and how do you guard against each?
- How do you read the declaration const int *p versus int *const p?
- On a microcontroller, how do you read or write a hardware register at a known address?
Dynamic Memory: malloc & free
- What's the difference between malloc and calloc?
- What is a memory leak, and why is it worse on an embedded device than a desktop?
- What's wrong with ptr = realloc(ptr, new_size);?
- What is use-after-free and why is it so dangerous?
- Why do many embedded/safety-critical projects forbid malloc after startup?
Stack vs Heap
- What's the difference between stack and heap allocation?
- What's wrong with returning a pointer to a local variable?
- Sketch the memory layout of a running C program.
- When would you choose the heap over the stack?
- What happens on a stack overflow, and how does it differ between a desktop and a no-MMU MCU?
Bit Manipulation & Masks
- How do you set, clear, and toggle a single bit without affecting the others?
- What's the difference between GPIOA->ODR |= (1u << 5) and GPIOA->ODR = (1u << 5)?
- Why should you write 1u << n instead of 1 << n for a mask?
- Your code reads a register field with if (reg & MASK == 0) and it never matches. Why?
- Is reg |= (1u << n) safe to use on a register that an interrupt also modifies?
Function Pointers & Callbacks
- How do you declare a pointer to a function, and why is typedef recommended?
- What is a callback and why is it useful?
- How would you replace a large switch statement that maps command codes to handlers?
- What happens if you call a NULL or mismatched function pointer?
- How do interrupt vector tables relate to function pointers?
Undefined Behavior & Pitfalls
- What is undefined behavior, and how is it different from a bug that produces a wrong value?
- Why might code work at -O0 but break at -O2?
- What's the difference between signed and unsigned integer overflow?
- What is the strict aliasing rule and how do you safely reinterpret bytes?
- How do you find undefined behavior in a codebase?
C++ for Embedded
50 questions
C++ vs C for Embedded
- Is C++ inherently slower or bigger than C on a microcontroller?
- What is name mangling and why does it matter when mixing C and C++?
- Which C++ features are safe on an MCU and which should you avoid?
- Give an example of valid C that won't compile as C++.
- Why must an interrupt handler written in C++ usually be declared extern "C"?
Constructors, Destructors & RAII
- What is RAII and why is it especially valuable in embedded?
- Write an RAII guard for a critical section. Why is it better than paired enable/disable calls?
- Why prefer the member initializer list over assigning members in the constructor body?
- In what order are destructors called, and why does it matter?
- If a class has a destructor that releases a resource, what else must you consider?
const Correctness & constexpr
- What is const correctness and why design for it from the start?
- What's the difference between const and constexpr?
- Why is constexpr especially valuable on a microcontroller?
- Does a const member function guarantee nothing it touches can change?
- Why prefer constexpr or enum class over #define for constants?
Function & Operator Overloading
- What is function overloading and when is the choice resolved?
- Can you overload a function on return type alone? Why or why not?
- What does operator overloading buy you, and when should you avoid it?
- Is overloading the same as polymorphism?
- Why is overloading safe to use on a microcontroller when some C++ features aren't?
What to Avoid on MCUs
- Why are C++ exceptions usually disabled on microcontrollers?
- What is RTTI and why do embedded builds often disable it?
- A teammate uses std::vector and std::string in firmware. What's your concern?
- How do you report errors in C++ firmware without exceptions?
- What compiler flags configure a bare-metal C++ build, and what does each do?
The HAL Pattern
- What is a HAL and what problem does it solve?
- What's the difference between runtime and compile-time polymorphism for a HAL, and when do you use each?
- Why does an abstract base class need a virtual destructor?
- How does the HAL pattern make firmware testable, and why does that matter?
- What's the downside of the HAL pattern, and how do you avoid over-abstracting?
Data Structures & Algorithms
57 questions
Time & Space Complexity
- What does Big-O notation actually describe?
- A hash table is "O(1) lookup." Why might you still not use one in an ISR?
- Does an algorithm that allocates nothing have O(1) space complexity?
- When would you choose an O(n²) algorithm over an O(n log n) one?
- What is the space-time tradeoff, and give an embedded example.
Arrays & Memory Layout
- Why is array indexing O(1)?
- Two nested loops summing a matrix have the same Big-O but different runtimes. Why?
- How is a 2D array laid out in memory in C, and how do you index a flat buffer as 2D?
- What's the difference between array-of-structs and struct-of-arrays, and when does each win?
- When is an array the wrong data structure?
Ring Buffers
- What is a ring buffer and why is it the go-to structure for a UART ISR?
- The buffer looks "empty" and "full" in the same state. Explain and fix.
- Why can a single-producer/single-consumer ring buffer be lock-free, and what's the catch?
- Why use a power-of-two capacity?
- The buffer is full and a new item arrives. What are your options?
Linked Lists
- What's the fundamental tradeoff between a linked list and an array?
- How do you use linked lists on a system with no heap?
- Can you delete a node from a singly linked list in O(1)?
- Why might a linked list be slower than an array even when Big-O says they're equal?
- What's an intrusive linked list and why is it favored in embedded/kernel code?
Stacks & Queues
- What's the difference between a stack and a queue?
- How would you implement a queue efficiently, and what's the naive mistake?
- Give a concrete embedded use for a stack and one for a queue.
- What does "peek" do, and why does the distinction from "pop" matter?
- What bounds must you check on a fixed-capacity stack or queue?
- An ISR enqueues bytes into a ring-buffer queue and the main loop dequeues them. Do you need a lock?
- How would you implement a FIFO queue using only two stacks, and what's the cost?
Static vs Dynamic Allocation
- Why is a pool allocator immune to fragmentation when general malloc isn't?
- What's the difference between a pool allocator and an arena allocator?
- When is plain static allocation the right answer?
- A pool allocator's alloc returns NULL. What does that mean and how do you handle it?
- Why does well-designed embedded firmware rarely need the general heap?
Finite State Machines
- What is a finite state machine and why is it the right tool for protocol parsing?
- Compare implementing an FSM as a switch statement versus a transition table.
- What's the difference between a Moore and a Mealy machine?
- What are the most common FSM bugs?
- When does a flat FSM become the wrong structure, and what do you do?
Embedded Systems Fundamentals
62 questions
What Is an Embedded System?
- What's the difference between a microcontroller and a microprocessor?
- When would you choose an MCU over an MPU (or vice versa)?
- Why does an MCU boot so much faster than an MPU?
- What does "real-time" mean, and why do embedded systems care about it?
- Someone says "the MPU protects memory regions." Is that the microprocessor?
Inside an MCU
- What's the point of a peripheral, why not have the CPU do everything?
- What's the difference between flash and SRAM on an MCU?
- Why doesn't my GPIO/UART/timer do anything even though I configured its registers correctly?
- What are AHB and APB?
- What does it mean that peripheral registers are "memory-mapped"?
The Memory Map
- What is a memory map and why does it matter?
- Walk through the regions of a typical Cortex-M memory map.
- How are the stack and heap arranged in SRAM, and what happens if they collide?
- What does the CPU read from address 0 at reset?
- What happens if you dereference a null pointer or access an unmapped address on a Cortex-M?
Registers & Memory-Mapped I/O
- How does writing to a C variable end up controlling hardware?
- Why is volatile required for register access?
- What's the advantage of a bit set/reset register (like BSRR) over read-modify-write on the output register?
- What is a write-1-to-clear flag and why is it a trap?
- Why might reading a register "just to check it" be a bug?
GPIO: Digital I/O
- What's the difference between push-pull and open-drain outputs?
- Why shouldn't you leave a GPIO input floating?
- You configured a GPIO pin correctly but it does nothing. What's the first thing to check?
- What is switch bounce and how do you handle it?
- How do you use a GPIO pin for a peripheral like UART TX instead of plain output?
Timers & Counters
- How do you configure a timer to interrupt at a specific frequency?
- What's the difference between output compare and input capture?
- What is SysTick and why do RTOSes use it?
- Your timer period is slightly off from what you calculated. What are the likely causes?
- What problems arise from a 16-bit timer counter?
PWM
- What is PWM and how does it produce an "analog" output from a digital pin?
- How is PWM generated using a timer?
- What's the tradeoff between PWM frequency and duty-cycle resolution?
- Why can't you drive a motor directly from a PWM-capable GPIO pin?
- How does PWM control a hobby servo, and how is that different from LED dimming?
- What is dead-time in a complementary PWM pair, and why does an H-bridge need it?
- Your PWM-controlled LED looks steady to the eye but flickers badly on camera video. What's going on and how do you fix it?
Clocks & the Clock Tree
- What's the difference between an internal RC oscillator and an external crystal, and when do you use each?
- What does the PLL do in the clock tree?
- Why must you set flash wait states before increasing the core clock?
- A peripheral's timing (UART baud, timer period) is wrong. How does the clock tree factor in?
- What's the correct sequence to switch the system clock to a PLL running off an external crystal?
The Watchdog Timer
- What is a watchdog timer and what problem does it solve?
- Where in your code should you kick the watchdog, and what's the common mistake?
- What's the difference between an independent watchdog and a window watchdog?
- How do you choose the watchdog timeout, and what goes wrong at the extremes?
- Why does your chip keep resetting when you pause at a breakpoint, and how do you handle long legitimate operations?
Boot Sequence & Startup Code
- What happens between reset and the first line of main()?
- How does a global variable get its initial value?
- What is the vector table and what's special about its first entry?
- Why must main() never return on a bare-metal system?
- A bootloader jumps to the application but the app's interrupts don't work. What's the likely cause?
Communication Protocols
46 questions
Serial vs Parallel, Sync vs Async
- Parallel sends 8 bits at once and serial sends 1, so why are fast modern buses serial?
- What's the difference between synchronous and asynchronous serial communication?
- What does duplex mean, and give an example of each kind?
- Is UART the same thing as RS-232?
- When would you choose a synchronous bus over an asynchronous one?
SPI
- Explain SPI's full-duplex shift-register model. Why do you "write to read"?
- What are CPOL and CPHA, and what happens if they're wrong?
- How does SPI address multiple devices, and what's the cost?
- SPI has no ACK or error checking. What are the implications?
- When does CS timing matter, and what bugs come from getting it wrong?
I2C
- Why does I2C use open-drain lines with pull-up resistors?
- Walk through how a master reads a register from an I2C device.
- What is clock stretching?
- You put two of the same sensor on an I2C bus and one doesn't respond. Why?
- The whole I2C bus is dead, SDA or SCL stuck. How do you diagnose it?
- What are the I2C bus speed modes, and what limits how fast you can actually run the bus?
Choosing UART, SPI, or I2C
- You need to drive a fast color display. Which bus and why?
- You have a board with eight sensors, an EEPROM, and an RTC, and very few free pins. Which bus?
- How does pin count scale differently across the three buses as you add devices?
- Why are UART, SPI, and I2C all poor choices for sending data across a machine or vehicle?
- In practice, how do you decide between two buses when either could work?
CAN Bus
- How does CAN arbitration work, and why is it called "non-destructive"?
- How is CAN addressing different from I2C or SPI?
- Why does CAN need exactly two 120 Ω termination resistors, and what happens without them?
- What makes CAN robust enough for vehicles? Describe its error handling.
- A CAN node keeps going "bus-off." What does that mean and what causes it?
Common Bus Bugs
- An I2C bus is completely dead, no device responds. What do you check first?
- Data on a bus is corrupted. How does the *pattern* of corruption narrow down the cause?
- What is bus contention and how does it show up on SPI and I2C?
- A bus works at low speed but fails when you increase the clock rate. What's going on?
- What's your general method for debugging a misbehaving bus?
Modbus & 1-Wire
- What is Modbus and what's its data model?
- What are the common pitfalls when reading Modbus registers?
- How does 1-Wire send both power and data on a single line?
- How are 1-Wire devices addressed, and how do you find them all on a bus?
- Why is 1-Wire timing tricky on a microcontroller, and how do you handle it?
Networking & IoT
45 questions
Ethernet Basics
- What's the difference between a MAC address and an IP address?
- What is the MAC/PHY split and why does it matter on an MCU?
- How does a modern switch differ from an old hub?
- What is the Ethernet MTU and why does it matter?
- A device's Ethernet link is up but throughput is terrible under load. What might be wrong?
Sockets
- Walk through the socket calls for a TCP client and a TCP server.
- What is network byte order and why does it matter?
- Why must you loop on send() and recv() with TCP?
- Why are blocking socket calls a problem on an MCU, and what are the alternatives?
- What's different about using sockets on a constrained embedded device versus a PC?
MQTT
- Why is MQTT's publish/subscribe + broker model well-suited to IoT?
- Explain MQTT QoS levels and a subtlety people get wrong.
- What are retained messages and Last Will, and what problems do they solve?
- MQTT itself isn't encrypted. How do you secure it?
- What are the failure modes and design pitfalls when deploying MQTT?
CoAP
- What is CoAP and why use it instead of HTTP?
- CoAP runs over unreliable UDP. How does it provide reliability when needed?
- What is CoAP Observe, and how does it compare to MQTT's model?
- What reachability problem does a CoAP device face that an MQTT device doesn't?
- What's the cost of securing CoAP, and how is it done?
RTOS & Real-Time Concepts
52 questions
Preemptive vs Round-Robin Scheduling
- What's the difference between preemptive and cooperative scheduling?
- Two tasks have the same priority and both are ready. What happens?
- What is starvation and how do you prevent it?
- How does FreeRTOS combine priority and round-robin scheduling?
- When is cooperative scheduling actually a good choice?
- When a higher-priority task becomes Ready, what actually happens at the hardware level to switch to it on a Cortex-M?
- Under preemptive priority scheduling, can a high-priority task ever be blocked by a low-priority one?
Context Switching
- What exactly happens during a context switch?
- How does a context switch work on a Cortex-M specifically?
- Why does FreeRTOS (on Cortex-M) perform the switch in PendSV rather than directly in SysTick?
- What's the cost of a context switch and why does it matter?
- How does the FPU affect context switching on a Cortex-M, and how is it handled?
Queues & Inter-Task Communication
- Why use a queue instead of a shared global protected by a mutex?
- What are the copy semantics of a FreeRTOS queue, and when do you send a pointer instead?
- How do you pass data from an ISR to a task?
- What goes wrong if you queue a pointer to a local variable?
- Besides queues, what inter-task communication primitives does an RTOS offer, and when would you use them?
Priority Inversion
- Explain priority inversion with a concrete scenario.
- What's the difference between bounded and unbounded priority inversion?
- How does priority inheritance solve priority inversion?
- What is the priority ceiling protocol and how does it differ from inheritance?
- You protected a shared resource with a binary semaphore and a high-priority task occasionally misses its deadline. What's likely wrong?
Hard vs Soft Real-Time
- What does "real-time" actually mean, isn't it just "fast"?
- What's the difference between hard, firm, and soft real-time?
- What is WCET and why is it central to hard real-time?
- How do you determine whether a set of tasks will meet their deadlines?
- What kinds of things destroy determinism, and how do you avoid them?
FreeRTOS: A Practical Tour
- Sketch how you'd structure a FreeRTOS app that processes UART data without losing bytes.
- What's special about calling FreeRTOS APIs from an ISR on a Cortex-M?
- What does FreeRTOSConfig.h control, and which settings matter most?
- What are the FreeRTOS heap schemes and when would you choose each?
- How do you debug a FreeRTOS system that crashes or behaves erratically?
Debugging & Toolchain
45 questions
The Toolchain
- What programs make up the toolchain, and what does each do?
- What is cross-compilation and how do you know a toolchain is for cross-compiling?
- Why do you run objcopy after linking, and what do size/objdump/nm tell you?
- On a bare-metal target, what plays the role of the "loader"?
- What kinds of mismatches in toolchain flags cause subtle build or runtime failures?
The Build Process & Makefiles
- How does Make decide what to rebuild?
- Why might changing a header file not trigger a rebuild, and how do you fix it?
- What do the automatic variables $@, $<, and $^ mean, and why use pattern rules?
- What's the infamous Makefile tab error, and what is .PHONY for?
- What can go wrong with incremental and parallel builds, and how do you guard against it?
Linker Scripts & Memory Sections
- What does a linker script do, and why do you need a custom one on bare metal?
- Explain VMA vs LMA and why .data must be copied at boot.
- What symbols does a linker script provide, and who uses them?
- The linker reports "region FLASH overflowed by N bytes." What does that mean and what do you do?
- Why do you wrap the vector table in KEEP() in the linker script?
On-Chip Debugging: JTAG & SWD
- What's the difference between JTAG and SWD?
- How does GDB physically reach into the MCU to halt it and read memory?
- Why does SWD dominate on ARM Cortex-M devices?
- You connect a probe but can't talk to the target. What do you check?
- How can you accidentally "lock yourself out" of debugging, and how do you avoid/recover?
Breakpoints & Watchpoints
- What's the difference between a breakpoint and a watchpoint?
- What's the difference between software and hardware breakpoints, and why does it matter on embedded?
- How would you find what's corrupting a global variable?
- Why might GDB refuse to set another breakpoint on an embedded target?
- What is a conditional breakpoint and what's the catch on embedded?
Logic Analyzer & Oscilloscope
- When would you reach for an oscilloscope versus a logic analyzer?
- What is triggering and why is it the key skill?
- A digital signal works most of the time but occasionally reads wrong. Which instrument, and why?
- Explain the GPIO-toggle trick and when you'd use it.
- Why does sample rate matter, and what goes wrong if it's too low?
printf Debugging & Logging
- On an MCU with no console, how does printf produce output?
- Why shouldn't you call printf in an interrupt handler or hot loop?
- What's wrong with semihosting for debugging output?
- How do you make logging suitable for a shipping product rather than ad-hoc prints?
- When do you use logging versus a debugger like GDB?
Reading a Datasheet
- What's the difference between absolute maximum ratings and recommended operating conditions?
- A spec sheet lists min, typical, and max. Which do you design to and why?
- What is an errata document and why must you check it?
- For an MCU, where do you find register definitions versus electrical limits?
- How do you use a timing diagram, and what's a real consequence of ignoring it?