Modern C++ for Embedded Systems
Building class-based hardware abstraction layers on the Sandwizz Breadboard
- Edition
- Sandwizz edition
- Version
- Review draft 1.0: all 21 chapters, 7 appendices and the Lab Companion
- Date
- November 2026
Review draft: the whole book is written. Measurements marked as coming from the digital twin will be repeated on the board.

Contents
- Preface
- Part I · Foundations
- 1The Foundation of Hardware-Constrained Systems
- 1.1The comfortable illusion
- 1.2The Pentagon of Constraints
- 1.3Power, polling and interrupts
- 1.4The silicon spectrum
- 1.5Anatomy of a microcontroller
- 1.6Choosing a language
- 1.7The C++ we use
- 1.8The hardware abstraction layer
- 1.9The Sandwizz ecosystem
- 1.10The component kit
- 1.11Installing the dashboard
- 1.12Connecting the board
- 1.13Lab 1.1: light without code
- 2From Code to Silicon
- 2.1Ruining the magic
- 2.2Host and target
- 2.3Decoding arm-none-eabi-gcc
- 2.4The ABI: a contract written in registers
- 2.5Stage one: the compiler sees one file at a time
- 2.6Stage two: the linker and the memory map
- 2.7Sections: where everything lives
- 2.8The illusion of main
- 2.9Falling off the end of main
- 2.10Getting the program into the chip
- 2.11Sharing the processor with the board
- 2.12The Heisenbug and the price of printf
- 2.13Debugging without stopping the world
- 2.14The code editor
- 2.15Lab 2.1: Hello, bare metal
- 2.16Lab 2.2: Where does my data live?
- 2.17Lab 2.3: The price of printf
- 2.18Lab 2.4: Breakpoints while the board runs
- 3Forging the Hardware Abstraction Layer
- 3.1The keyword that saves your hardware
- 3.2Dead stores and vanishing loops
- 3.3The blind brain and the bus
- 3.4Memory-mapped I/O
- 3.5A register is a physical thing
- 3.6Bit masks
- 3.7Read-modify-write and the race
- 3.8Four ways to an atomic change
- 3.9Bit-banding
- 3.10What your program may touch
- 3.11From raw pointers to a struct overlay
- 3.12The DigitalOut class
- 3.13A row that is known at compile time
- 3.14Zero cost? Measure it
- 3.15Lab 3.1: The warning light
- 3.16Lab 3.2: The vanishing delay loop
- 3.17Lab 3.3: Atomic flags with bit-banding
- Part II · Inputs, Time and Events
- 4Digital Inputs and Contact Bounce
- 5Interrupts and Concurrency
- 5.1Why interrupts
- 5.2Exceptions on the Cortex-M3
- 5.3Entering and leaving a handler
- 5.4The NVIC: enabling, pending and priorities
- 5.5Interrupts on the Sandwizz Breadboard
- 5.6Writing an interrupt handler in C++
- 5.7Shared data and races
- 5.8Critical sections
- 5.9Atomic operations
- 5.10A lock-free queue
- 5.11Lab 5.1: A timer interrupt
- 5.12Lab 5.2: A button with interrupts
- 5.13Lab 5.3: A race you can count
- 5.14Lab 5.4: A rotary encoder
- 6Time, Timers and Scheduling
- 6.1Where time comes from
- 6.2Three counters and their limits
- 6.3Surviving the wrap
- 6.4Time with types: std::chrono
- 6.5Waiting without blocking
- 6.6Many jobs, one processor: cooperative scheduling
- 6.7Timer interrupt or task?
- 6.8Hardware timers
- 6.9Lab 6.1: Drift
- 6.10Lab 6.2: A scheduler
- 6.11Lab 6.3: A counter in hardware
- Part III · Driving the World
- 7Pulse-Width Modulation, Light and Sound
- 7.1What PWM is
- 7.2Why the average is all that counts
- 7.3PWM in hardware
- 7.4PWM in software
- 7.5Brightness and the eye
- 7.6One interface, two kinds of polymorphism
- 7.7Sound
- 7.8PWM as a digital-to-analogue converter
- 7.9Lab 7.1: PWM in software
- 7.10Lab 7.2: Breathing, with and without gamma
- 7.11Lab 7.3: A melody
- 7.12Lab 7.4: PWM as an analogue output
- 8Motors and Motion
- Part IV · Sensing the World
- 9Analogue Signals, Filters and Fixed Point
- 10Memory without a Heap
- 10.1Storage duration: where and for how long
- 10.2The stack
- 10.3Why not the heap?
- 10.4Containers with a fixed capacity
- 10.5Pools
- 10.6Vocabulary types instead of pointers
- 10.7Layout and padding
- 10.8Lab 10.1: Where things live
- 10.9Lab 10.2: Fragmentation
- 10.10Lab 10.3: Vocabulary types
- 10.11Lab 10.4: How deep is the stack?
- Part V · Talking to Other Chips
- 11Serial Communication and the UART
- 12I²C, Buses and Device Drivers
- 12.1The bus
- 12.2A transaction
- 12.3Drivers as class templates
- 12.4The decorator: adding behaviour without changing anything
- 12.5Errors as values
- 12.6A display driver
- 12.7A sensor driver
- 12.8Lab 12.1: Who is on the bus?
- 12.9Lab 12.2: An OLED display
- 12.10Lab 12.3: A sensor driver
- 12.11Lab 12.4: A weather display
- 13SPI, Shift Registers and Multiplexing
- 14A Command Line for the Board
- Part VI · Building Systems
- 15Direct Memory Access and Double Buffering
- 16Power, Energy and Sleep
- 17Reliability, Watchdogs and Faults
- 18State Machines
- 19Testing Embedded C++
- 20Architecture and a Complete Product
- Part VII · Beyond Software
- 21Hardware in Verilog
- Appendices
- AC++ for Embedded Developers
- BThe Sandwizz BSP and the Book's HAL
- CCortex-M3 Cheat Sheet
- DComponents and Extension Parts
- EAnswers to Selected Exercises
- FGlossary
- GFurther Reading
- Part VIII · Lab Companion
- L1Before You Start
- L2Lights, Buttons and Time
- L2.1Which setup for which lab
- L2.2Setup A: an LED, a resistor and three roles
- L2.3Setup B: the warning light
- L2.4Setup C: a button and an LED
- L2.5Setup C2: a hardware debouncer
- L2.6Setup D: a rotary encoder
- L2.7Setup E: a counter in hardware
- L2.8Setup F: two LEDs that breathe
- L2.9Setup G: a passive buzzer
- L2.10Setup H: a voltage from PWM
- L3Motors, Sensors and Text
- L4Buses, Displays and a Product
- L5Parts
- L6When It Does Not Work
- L7For Teachers and Study Groups
All figures and listings · use the search field at the top to look up a term, a class or a function.
Copyright and licences
Copyright © 2026 Microaware ApS. Sandwizz® is a trademark of Microaware ApS. All rights not granted below are reserved.
The book. The text, figures and pictures are licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International licence (CC BY-NC-ND 4.0, creativecommons.org/licenses/by-nc-nd/4.0). You may copy and share it free of charge and unchanged, with credit to Microaware ApS.
The book's code. The programs in the book and the HAL you build in it (the projects and HAL headers that come with the book, and the listings printed from them) are licensed under the MIT licence. You may use, change and share them in your own projects, also commercially, as long as the copyright notice and the licence text go with them. The licence text is in the LICENSE file next to the code.
The Sandwizz BSP and the firmware. The Sandwizz BSP (sandwizz.h and the runtime that programs link against) and the firmware on the board are proprietary: © Microaware ApS, all rights reserved, in source and in binary form. They are not covered by the licences above. A program from the book links against the BSP: the MIT licence covers the program's own code, not the BSP.