Embedded development environment, integration and testing
Practical guide to setting up, integrating and testing an embedded development environment: toolchains, build systems, debugging, flashing, unit/HIL/integration testing, CI and common pitfalls.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two or three sentences: where an engineer uses this. Embedded products must be built, tested and debugged reliably before they go into field devices. Engineers use a correct development environment to cross-compile firmware, run unit and integration tests (including hardware-in-the-loop), debug on target hardware, and automate builds and tests in CI so releases are repeatable and safe.
Key ideas
Explain from first principles, define terms, give exact statements and diagrams to draw.
- Development environment — the collection of tools, libraries and hardware used to create and test firmware. This includes the toolchain, build system, debugger, board support package and target hardware.
- Toolchain — the set of programs that convert source code into a binary that can run on the target processor (compiler, assembler, linker, binary utilities). Example components: cross-compiler (compiler that runs on host and produces code for target), objcopy, ld (linker).
- Build system — an automated system that runs commands to produce the final binary from sources. Examples: Make, CMake. Important property: it should produce the same outputs given the same inputs (reproducible builds) and track dependencies.
- Topological build order — the correct order to build components where A depends on B must build B before A. State precisely: Given a directed acyclic graph (DAG) of dependencies, a topological ordering is a linear ordering of nodes such that for every directed edge u→v, u appears before v. Assumption: dependency graph has no cycles. University derivation: show Kahn's algorithm step-by-step (below) to produce an ordering; if algorithm cannot remove all nodes, a cycle exists.
- Debugger — a tool that lets you control program execution on the target (set breakpoints, inspect memory and registers). JTAG and SWD are physical debug interfaces that provide low-level access to the CPU debug hardware. GDB (GNU Debugger) communicates using the GDB remote protocol with a server such as OpenOCD/pyOCD/J-Link GDB Server for bare-metal targets, or with a remote stub like gdbserver on OS targets.
- Flashing / programming — writing the final binary into non-volatile memory (Flash, EEPROM). Often uses a bootloader (small program on device that receives firmware images) or an external programmer via JTAG/SWD.
- Unit test — test of a single function or module in isolation, typically executed on host or on-target with a test framework (example frameworks: Unity, CMock). Tests should be deterministic and fast.
- Integration test — test combining multiple modules or hardware and software together; checks interfaces and interactions.
- Hardware-in-the-loop (HIL) — a test setup where the target hardware is connected to simulated plant or peripherals so control loops and timing can be verified.
- Continuous Integration (CI) — automated process that builds and tests code on each commit to find regressions early. Essential steps include checkout, build, unit tests, static analysis, on-target tests (if available), and artifact storage.
Diagrams to draw (describe exactly):
- Toolchain flow: Draw boxes left-to-right labeled "Source (.c/.h/.s)" → "Compiler/Assembler" → "Object files (.o)" → "Linker (ld)" → "ELF" → "objcopy" → "Binary/hex" → "Flasher/Bootloader" → "Target Flash". Label arrows with commands like gcc -c, ld, objcopy -O binary.
- CI pipeline: vertical sequence boxes "Checkout" → "Static analysis" → "Build (cross-compile)" → "Unit tests (host)" → "On-target tests" → "Archive artifacts". Annotate runner (host vs hardware lab).
- Debug connection: Host PC (GDB) ↔ OpenOCD/gdbserver ↔ JTAG/SWD cable ↔ Target board. Label GDB commands: target extended-remote, load, continue.
Formulas
For this programming and process topic list syntax and commands to remember, each on its own line.
arm-none-eabi-gcc -mcpu=<cpu> -mthumb -O2 -g -c source.c -o source.o
- where
<cpu>is target core (e.g. cortex-m3). Producessource.oobject file; host is where compiler runs.arm-none-eabi-ld -T linker.ld *.o -o firmware.elf - links objects using
linker.ldscript to producefirmware.elf.arm-none-eabi-objcopy -O binary firmware.elf firmware.bin - converts ELF to raw binary for flashing.
arm-none-eabi-objcopy -O ihex firmware.elf firmware.hex - converts ELF to Intel HEX format (often required by bootloaders or programmers).
openocd -f interface.cfg -f target.cfg - starts OpenOCD server for JTAG/SWD. Exact config depends on hardware.
gdb-multiarch firmware.elf -ex "target extended-remote :3333" -ex "monitor reset halt" -ex "load" -ex "continue" - example GDB sequence to connect to target via OpenOCD (port 3333), reset and load binary.
make/cmake --build ./ninja - build system commands to remember for invocation.
git clone <repo>/git checkout <branch>/git commit -m "..."/git push - basic version control commands.
Worked examples
- Cross-compile and flash (typical exam-style steps): Given: source.c (10 KB), startup.s, linker.ld, target Cortex-M4. Steps:
- Command:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O0 -g -c source.c -o source.o(compile). - Command:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O0 -g -c startup.s -o startup.o(assemble). - Command:
arm-none-eabi-ld -T linker.ld startup.o source.o -o firmware.elf(link). State assumption: linker script places .text at 0x08000000. - Command:
arm-none-eabi-objcopy -O binary firmware.elf firmware.bin(binary). - Command:
openocd -f interface.cfg -f target.cfg &thenarm-none-eabi-gdb firmware.elfandtarget extended-remote :3333thenmonitor reset haltandloadto flash. Final: firmware flashed to 0x08000000. Units: file sizes in bytes; no physical unit needed. (Check commands and options for your toolchain.)
- Topological sort for build order (algorithm trace): Problem: Modules A depends on B and C, B depends on D, C depends on D. Graph edges: B→A, C→A, D→B, D→C. Nodes: A,B,C,D. Kahn's algorithm steps:
- Find nodes with in-degree 0: D.
- Remove D, append to order: [D]. Reduce in-degree: B and C now have 0.
- Remove B, append: [D,B]. Reduce in-degree: A depends on B and C; still has in-degree 1.
- Remove C, append: [D,B,C]. Now A in-degree 0.
- Remove A, append: [D,B,C,A]. Final topological order is D, B, C, A. If you cannot remove all nodes, there is a cycle.
- Unit testing on-target (model answer):
Goal: run 20 unit tests on target using Unity. Steps: compile test runner with
-DTEST_ON_TARGET, link with stubs for hardware peripherals, flash and run, collect results over serial. The full-marks answer lists: isolate I/O by stubbing, use deterministic clocks or fake timers, run tests automatically at boot, transmit results as TAP or JSON.
Common mistakes
- Assuming host tests equal target behavior: endianness, alignment, and peripheral timing differ.
- Running integration tests without hardware isolation: flaky tests that depend on lab state.
- Not checking for cycles in dependency graph; build hangs or repeats.
- Loading binary without resetting or halting CPU first: flash may appear to succeed but code does not run.
- Committing build artifacts (binaries) to Git; leads to merge conflicts and large repos.
For your exam
Kinds of questions: definitions (explain toolchain, JTAG), short notes (CI pipeline, unit vs integration tests), derivations (topological sort), numericals (timing calculations for flashing or test runtimes), programs/commands (write sequence of commands to cross-compile and flash), diagrams (draw debug connection and build flow). What a full-marks answer includes:
- Clear definitions of bold terms (toolchain, cross-compiler, JTAG, HIL, CI).
- Correct sequence of commands with explanation of each step and assumptions (linker address, flash size, debugger port).
- For algorithms: state assumptions (graph is DAG), show step-by-step trace (Kahn's algorithm) and explain detection of cycles.
- For testing questions: specify test isolation, repeatability, pass/fail criteria, and how to automate in CI; include fallback when hardware is not available (emulator or mocked peripherals).
Quick check
- What is a cross-compiler?
- Name two physical debug interfaces used with ARM microcontrollers.
- In a dependency graph, what does a cycle mean for a build system? Answers: 1) A compiler that runs on the host and produces code for a different target architecture (cross-compilation). 2) JTAG and SWD (Serial Wire Debug). 3) A cycle means there is no valid topological build order; the build dependencies are circular and must be resolved.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?