Firmware & embedded C articles
Free, tested guides by Chinmay Gupta. Every code sample is compiled and run before it is published.
A ring buffer in C for a UART interrupt, step by step
Build a circular FIFO in C for UART receive interrupts. Understand head and tail, full versus empty, wraparound, capacity and ISR-safe atomic ordering.
What volatile really does in C, and what it does not
When should you use volatile in embedded C? Learn register access, ISR flags, atomicity, ordering and common mistakes, with tested examples.
Struct padding and alignment in embedded C
Why does sizeof(struct) exceed member sizes? See byte offsets, internal and tail padding, field ordering and portable serialization with tested C examples.
Fixed-point math in C for MCUs without an FPU
Learn Q15 and Q16.16 fixed-point math in C, including integer scaling, multiplication, rounding, saturation and tested examples for microcontrollers.
Priority inversion: what it is and how inheritance fixes it
Understand RTOS priority inversion with a three-task timeline, tested scheduler simulation, mutex inheritance and practical interview questions.
Bit tricks every firmware engineer should know
Clear the lowest set bit, isolate it, count bits, and find trailing zeros in C, with a portable fallback for __builtin_ctz. All code tested.
Storing settings in flash to recover from interrupted writes
Two-slot flash storage with sequence numbers and CRC, tested by cutting power at every single byte of an erase and write. Plus how wear levelling fits in.
Debouncing a button in C with a counter state machine
A tested, interrupt-free button debounce in C: sample at 1 kHz, change state only after N identical samples, and emit clean press and release events.
Data structures and algorithms for firmware: what to learn, in what order
A practical roadmap of the data structures and algorithms embedded engineers actually use, why they differ from web DSA, and how to choose under a RAM budget.
Firmware and embedded C interview questions, with answers
Ten common embedded C and firmware interview questions with precise answers and tested code: volatile, endianness, bit ops, ISRs, stack vs heap.
Firmware interviews in the AI era: what is changing and how to prepare
Writing code got cheap, so interviews lean harder on reviewing it: interrupt races, undefined behaviour, registers. A tested bug-hunt example and a prep plan.
Volatile vs atomic in embedded C: different contracts
Understand why volatile does not synchronize threads, how atomic operations differ, and what to check before using them on an embedded target.
Integer promotions: why uint8_t arithmetic surprises you
Learn how narrow integer types promote in C expressions, why narrowing is different from overflow, and how to write explicit byte arithmetic.
Decode little-endian fields without pointer casts
Use explicit byte assembly to decode a binary protocol field in C without relying on host endianness, unaligned access, or struct layout.
Why sizeof cannot recover a C array parameter's length
Understand the difference between a real array and an adjusted array parameter, and pass explicit lengths for safe firmware buffer interfaces.
memcpy vs memmove: overlapping buffer copies in C
Learn the overlap precondition of memcpy, when memmove is needed, and how to test buffer compaction without relying on undefined behavior.
Ring buffer capacity: full and empty are not the same
Compare reserved-slot circular buffer capacity with explicit-count designs, and test the exact wrap and full conditions in a single-threaded model.
Acquire and release: publishing data with C11 atomics
Understand release/acquire publication of ordinary memory, the limits of relaxed ordering, and why ownership matters in embedded concurrent code.
Fixed-point rounding with a widened intermediate in C
Work through a bounded scaled-integer multiplication example, define its rounding rule, and test negative values without relying on signed right shift.
Validate frame lengths before reading embedded buffers
Build a small length-prefixed frame validator in C with explicit remaining-length checks and boundary tests for truncated input.
Binary search lower bound with a half-open range in C
Use a half-open search interval to find the first element not less than a key in a sorted C array, with duplicate and empty-range tests.
Unsigned timer wraparound and elapsed time in C
Calculate elapsed ticks from a wrapping uint32_t clock with a documented observation bound and tests crossing the wrap boundary.
Priority inversion: review shared-resource wait times
Reason about lock ownership, scheduling interference and worst-case blocking in an RTOS without assuming priority inheritance fixes every deadline.
Saturating addition without overflowing signed C integers
Implement a bounded signed addition using a widened intermediate and explicit saturation, with positive, negative and boundary tests.
Host unit tests for firmware: what they actually prove
Separate pure C logic from hardware dependencies, use host tests for boundary behavior, and identify what still needs target-based validation.
C struct layout is not a binary serialization format
Learn to separate a C struct's object representation from an explicit byte-oriented format and test serialization without relying on padding bytes.
Firmware interviews: explain invariants before writing code
Practice explaining state invariants, preconditions, boundary cases and target assumptions when discussing embedded C solutions in interviews.
Free learning paths
The DSA for Firmware course turns these topics into lessons you practise.
- 28 lessons, each starting from a real firmware bug.
- 110 C exercises with tests, and a reference solution for every one.
- Lessons 1 and 2 are free. No sign-up.
Get the next article by email
One short email when a new article or free lesson is published. No spam. Unsubscribe at any time by replying to any email. See the privacy policy.