Learn embedded C and firmware
135 lessons from your first C program to RTOS, drivers, wireless and embedded Linux, with runnable examples and quizzes.
1. Programming foundations
Write your first C programs. No experience needed.
1.1 C from zero
- Microcontrollers and your first program · What a microcontroller is, how code gets onto it, and the parts of a C program.
- Variables and operators · Storing values, doing arithmetic, comparing, and the two surprises of integer maths.
- Decisions and loops · Choosing with if and switch, repeating with while and for, and the loop that never ends.
- Functions · Splitting a program into named pieces, passing values in and getting results back.
- Binary and hexadecimal · Bits, bytes, hex digits and negative numbers, the way hardware actually stores values.
- Arrays and text · Many values under one name, looping over them safely, and strings.
- A first look at pointers · Addresses, and how a function reaches a variable that belongs to its caller.
- Structs, enums and typedef · Grouping values into structs, the dot and the arrow, naming choices with enum, and shorter names with typedef.
2. Embedded C
The C that firmware is built from, and the C++ that fits a microcontroller.
2.1 Data and memory
- Integers and data types · Fixed-width types, integer promotion, overflow and the signed/unsigned rules that bite.
- Undefined behaviour · Undefined, unspecified and implementation-defined behaviour, and why the optimiser makes UB dangerous.
- Bit manipulation · Masks, shifts, fields and the idioms every register access is built from.
- Pointers · Addresses, arithmetic, const, void pointers and object lifetime.
- Scope, linkage and storage duration · What static really means, declarations versus definitions, and where each variable lives.
- Arrays and strings · Decay, bounds, safe copying, and parsing and formatting without the heap.
- Structs, unions, alignment and byte order · Alignment and unaligned access, padding, packing, byte order, unions and bit-fields.
2.2 C for hardware
- Registers, volatile and const · How C talks to hardware: memory-mapped registers, what volatile and const promise, register structs and read-modify-write.
- Inline functions and macros · The preprocessor, macro pitfalls, inline functions and X-macros.
- Function pointers and callbacks · Callbacks, dispatch tables and the context pointer that makes them reusable.
- Buffers and data structures · Ring buffers, pools, lists and bitmaps on static memory.
- Fixed-point and signal processing · Scaling, rounding, saturation and filters without floating point.
2.3 C++ for embedded
- C++ classes and OOP for embedded · Classes, constructors, inheritance, virtual calls and what they cost.
- C++ embedded constraints and the STL · No heap, no exceptions, no RTTI: the C++ that fits a microcontroller.
- RAII and smart pointers · Tying resources to scope: lock guards, critical sections and unique_ptr.
- Templates and constexpr · Compile-time computation, type-safe registers and zero-cost abstractions.
3. How a microcontroller works
Electronics basics, the processor, interrupts and time, and everything between your source code and a running chip.
3.1 Electronics for firmware
- Hardware fundamentals for firmware engineers · Reading schematics, pull-ups, regulators and decoupling.
- Digital logic for firmware engineers · Logic levels, gates, flip-flops, setup and hold, and timing diagrams.
- Analog circuits and sensor front ends · Dividers, RC filters, op-amps and interfacing common sensors.
- Reading datasheets and schematics · Where the answers are, min/typ/max, calculating from the tables and reading register maps.
3.2 Processor, interrupts and time
- MCU cores and clocking · Cortex-M families, RISC-V, PLLs and power modes.
- CPU fundamentals for embedded · Pipelines, caches, DMA coherency, barriers and buses.
- Reading Arm assembly · Enough Thumb-2 to read compiler output, check volatile and find a fault.
- Calling conventions and the stack · The AAPCS: arguments, return values, saved registers and stack frames.
- Interrupts, timing and concurrency · How interrupts work on a Cortex-M, priorities, latency, races, rollover-safe time, non-blocking code and debouncing.
- The Cortex-M exception model · Faults, SVC and PendSV, MSP and PSP, EXC_RETURN and fault handlers.
3.3 From source to running code
- The compilation pipeline · Preprocessor, compiler, assembler and linker, and what each one produces.
- Toolchains and cross-compilation · Target triplets, sysroots, float ABI and the flags that must agree.
- Make and CMake for embedded · Rules, dependencies, toolchain files and a sane firmware build.
- Linker scripts · MEMORY, SECTIONS, the location counter, KEEP and ALIGN.
- ELF, map files and binary inspection · Reading what the linker built with size, nm, objdump and the map file.
- Memory layout and startup code · From reset to main: copying .data, zeroing .bss and the C runtime.
- Boot, vector table and clock bring-up · Reset sources, the vector table and bringing up the clock tree.
3.4 Two Cortex-M33 cores: the Raspberry Pi Pico 2
- Floating point on the Cortex-M33 · The Pico 2's FPU and double coprocessor, float or fixed point, and rounding.
- DSP instructions on the Cortex-M33 · SIMD and saturating instructions, Q15 mixing and FIR filters from C.
- Two cores on the RP2350 · Starting core 1, the SIO FIFOs, spin locks and splitting the work.
4. Peripherals and protocols
The on-chip peripherals every product uses, the buses that connect chips together, and storing data that must survive power-off.
4.1 Core peripherals
- GPIO · Pin modes, push-pull versus open-drain, pulls, edge interrupts and debouncing.
- Timers and PWM · Prescalers, auto-reload, input capture, output compare and dead time.
- ADC · Resolution, sampling, noise, oversampling and DMA.
- DMA · Transfer modes, circular buffers, half-transfer interrupts and cache coherency.
- Watchdog timer · Independent and windowed watchdogs, and feeding them correctly.
4.2 Serial communication
- UART · Baud rate, framing, errors, flow control and DMA reception.
- SPI · Clock modes, chip select, multiple devices and throughput.
- I2C · Addressing, repeated start, clock stretching and bus recovery.
- Protocols, framing and checksums · Checksums, CRCs, byte order, framing and parsing a byte stream.
- CAN · Arbitration, bit timing, frames, CAN FD and error handling.
- USB · Enumeration, descriptors, endpoints, transfer types and device classes.
4.3 Industrial, automotive and audio buses
- RS-485 and Modbus · Differential multi-drop wiring, driver enable, and the Modbus RTU protocol.
- LIN and 1-Wire · Two cheap single-wire buses: automotive LIN and 1-Wire sensors.
- I2S audio and Ethernet · Streaming audio between chips, and wired Ethernet from MAC to PHY.
4.4 Storage
- Flash, EEPROM and FRAM · Erase before write, endurance, wear levelling and surviving power loss.
- Embedded file systems · FatFs, LittleFS and designing a reliable data logger.
- SPI flash and SD cards · Serial NOR commands, the page boundary trap, and SD card bring-up in SPI mode.
- Checksums and CRCs · Detecting corruption: sums versus CRCs, CRC parameters, tables and protecting stored records.
5. Firmware architecture
Structuring firmware that stays correct as it grows: state machines, an RTOS and well-designed drivers.
5.1 State machines
- State machine fundamentals · States, events, transitions, actions, Mealy and Moore.
- State machine patterns in C · Switch, transition tables and state-function pointers compared.
- Event-driven state machines · From polling to events, queues and run-to-completion.
- Hierarchical state machines · Nested states, entry and exit actions, and statecharts.
5.2 Real-time operating systems
- RTOS fundamentals · Hard and soft real time, tasks, states, and FreeRTOS versus Zephyr.
- RTOS scheduling and timing · Preemption, context switches, ticks and rate-monotonic analysis.
- RTOS synchronisation primitives · Mutexes, semaphores, queues, event flags and priority inversion.
- ISR-to-task patterns · Deferring work out of interrupts with semaphores, queues and notifications.
- Inside an RTOS kernel · Task control blocks, ready lists, the tick and the context switch.
5.3 Designing firmware
- Driver design: HAL versus bare metal · Layering a driver so it is testable, portable and still fast.
- Embedded C code patterns · Error handling, opaque handles, ring buffers, tables and other everyday shapes.
- Firmware architectures · Superloop, interrupts, event-driven or an RTOS: how to structure firmware and when to choose each.
- Error handling and fault strategy · Error codes, assertions, safe states and keeping evidence of what went wrong.
6. Quality and engineering practice
Finding bugs methodically, testing without hardware, measuring power, and the everyday practice of a firmware team.
6.1 Debugging and testing
- Debugging embedded systems · JTAG and SWD, GDB, hard faults and a method for finding bugs.
- Testing and code coverage · Unit tests on the host, mocks, HIL, coverage and static analysis.
- Power profiling and measurement · Measuring microamps to amps and finding where the energy goes.
- Logic analyzers and oscilloscopes · Seeing what really happens on the wires: sample rates, decoding, triggers and what to look for.
6.2 Engineering practice
- Git and releases for firmware · What goes in the repository, branches and tags, versions built into the image, and releases you can rebuild.
- Code review for embedded C · What to look for in firmware changes, how to comment, and what to leave to tools.
- Static analysis and MISRA in practice · Warnings worth enabling, the essential type model, common MISRA findings, deviations and legacy code.
- Working with vendor SDKs and HALs · SDK layers, generated code, HAL handles, status codes and callbacks, and when to go below the HAL.
- Board bring-up, step by step · From first probe connection to clocks, console, memory tests and a power-on self-test.
- Requirements and design notes · Testable requirements, traceability, one-page design notes and the documents a firmware team keeps.
7. Specialisations
Go deep in the area your target job needs. Each module stands on its own.
7.1 Networking
- TCP/IP fundamentals · Layers, the handshake, flow and congestion control, and lwIP.
- Sockets API basics · Socket lifecycle, TCP versus UDP, blocking and select/poll.
- TLS for embedded systems · Handshakes, certificates, PSK, DTLS and fitting TLS in RAM.
- MQTT · Publish/subscribe, topics, wildcards, QoS, retained messages and wills.
- HTTP, REST and CoAP for IoT · REST design, HTTP versions, JSON versus CBOR, and CoAP.
7.2 Wireless
- Choosing a wireless technology · Range, data rate, power and cost: a decision guide.
- Bluetooth Low Energy · Advertising, GAP roles, GATT, connection parameters and pairing.
- Wi-Fi for embedded · Station and AP modes, provisioning, power save and security.
- Cellular IoT: NB-IoT and LTE-M · The two LPWA standards, PSM, eDRX and AT commands.
- LoRa and LoRaWAN · Spreading factor, link budget, device classes and ADR.
- Mesh networking: Zigbee, Thread and Matter · Self-healing meshes and the IP-based smart home stack.
- Ultra-wideband (UWB) · Pulse radio, time-of-flight ranging, TWR and TDoA.
7.3 Embedded Linux
- The Linux boot process · ROM code, U-Boot, the kernel, initramfs and init.
- Linux build systems · Yocto, Buildroot and OpenWrt: layers, recipes and images.
- The device tree · Nodes, compatible strings, overlays and how drivers find hardware.
- Linux drivers and kernel modules · Modules, character devices, platform drivers and probe.
- Linux IPC mechanisms · Pipes, shared memory, sockets, message queues, signals and D-Bus.
- Linux userspace basics · Root filesystem, flash filesystems, init systems and BusyBox.
7.4 Safety and security
- Safety and security standards · IEC 61508, ISO 26262, IEC 62304, DO-178C and MISRA C.
- Safety mechanisms · Defensive code, watchdog strategy, memory checks and redundancy.
- Secure boot and cryptography · Chains of trust, key storage, crypto accelerators and attacks.
- OTA updates and rollback · A/B slots, delta updates, rollback and signing.
7.5 Power and EMC
- Low-power design techniques · Battery budgets, duty cycling, sleep modes and wake sources.
- Signal integrity and EMC · Rise times, reflections, grounding and passing EMC.
- Power supplies and batteries · LDOs and switching regulators, battery chemistries, battery-life budgets and brown-outs.
7.6 Signals, control and motors
- Digital filters: FIR and IIR · Moving averages, FIR and IIR filters, biquads and notch filters.
- The FFT and frequency analysis · Bins, resolution, windows and spectral leakage, and Goertzel.
- PID control · Feedback loops, the three terms, anti-windup and tuning.
- Motors and motor control · DC motors and H-bridges, steppers, BLDC commutation and FOC.
- Sensors and sensor fusion · Integrating sensors, calibration, IMUs and complementary and Kalman filters.
7.7 Rust and TinyML
- Rust for embedded · Ownership and borrowing, no_std, embedded-hal, RTIC and Embassy.
- Rust patterns for C programmers · Result and ?, Option, enums as state machines, type-state and calling C.
- TinyML: machine learning on MCUs · Quantised models, TensorFlow Lite Micro and fitting the budget.
- Features for TinyML · Windows, RMS and band energy, Goertzel, normalisation and a nearest-centroid classifier.
Advanced tracks
- Automotive ECU diagnostics · Every ECU in a car answers a workshop tester. Learn the two protocols that carry that conversation, ISO-TP and UDS, and the fault memory, security and coding rules behind them, at the depth a tier-one supplier interviews for. Then write the diagnostics of a body control module on an STM32.
- Reliability, power and security engineering · The skills that separate firmware that works on the bench from firmware that survives ten years in the field: recovering from resets, brown-outs, flipped bits and locked buses; budgeting every microamp of a battery's life; and defending the device against someone who holds it, from signed updates with rollback to constant-time checks and glitch-resistant decisions. Then harden a sensor node on an STM32 while the simulator injects every one of those faults.
More guides
- Embedded C quick reference · The idioms, sizes and rules worth having on one page before an interview.
- Hardware kit and labs · What to buy to move from the simulator to real boards, at three budgets, and a lab that takes each guided build onto real hardware.
- Presenting your projects · Turning your builds into a portfolio: the repository and README, the résumé line, and telling the story in an interview.