liveBook · Manning

Chapter 2: Setting up your Rust tool-chain

What you will learn in chapter 2 of Embedded Software with Rust

This chapter introduction previews the tools and workflows for setting up an embedded Rust development environment.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduction previews the tools and workflows for setting up an embedded Rust development environment.

2.1 Setting up your embedded Rust environment

This section introduces the upcoming setup of an embedded Rust toolchain and editor and states the assumed background.

2.1.1 A brief word about embedded Rust vs. desktop Rust

Contrasts the support available to desktop Rust programs with the minimal environment and runtime support typical of embedded Rust.

Key terms: no_std, standard library, heap allocation, static allocation, custom allocators, cortex-m-rt, riscv-rt, startup code, exception handling, bare-metal

2.1.2 Installing and using rustup

This subsection introduces rustup as Rust’s tool-chain manager and outlines how to install it, keep the tool-chain updated, and inspect installed components.

Key terms: rustup, tool-chain, cross-compile, targets, core Rust tool-chain, tool-chains, components

2.1.3 Managing embedded targets

This section explains how Rust targets select a compilation environment, how target support is managed, and what Rust’s support tiers indicate.

Key terms: target, rustc, architecture, Application Binary Interface, installed targets, rustup target remove, Tier 1, Tier 2, Tier 3, platform support

2.1.4 Targets and target triples explained

This section explains how Rust target triples identify an embedded program’s intended hardware and bare-metal environment.

Key terms: target triple, architecture, vendor, system, ABI, bare-metal

2.1.5 Common pitfalls in target setup

This section explains two common target-selection pitfalls: choosing the right floating-point ABI and identifying the device’s Arm architecture and features.

Key terms: ABI, target triple, eabihf, eabi, hardware floating-point, Arm sub-families, Cortex-M0+, Cortex-M3, Arm v6-M, Arm v7-M

2.1.6 Understanding rustc and compiler alternatives

This section positions rustc as the usual embedded Rust compiler and explains when a commercial tool-chain may be worth considering.

Key terms: rustc, optimization, cross-compilation, embedded architectures, commercial compilers, safety-critical, certified applications, validation

2.1.7 IDE and editor setup: VSCode

Recommends VSCode for most embedded Rust developers, identifies useful extensions, and notes alternatives for readers who prefer modal editors.

Key terms: VSCode, Rust Analyzer, Cortex-Debug, Debugger for probe-rs, Arm Assembly, Serial Monitor, vim, Helix, Zed, modal editor

2.2 Expanding cargo: Building, generating, and inspecting binaries

This section introduces why embedded Rust workflows must generate and inspect target-specific binaries, not just compile and link code.

Key terms: target-specific artifacts, ELF, raw binary (.bin), Intel HEX (.hex)

2.2.1 Building embedded binaries with cargo

This section explains how Cargo builds bare-metal Rust programs for an embedded target, where it puts debug and release artifacts, and what the resulting ELF files contain.

Key terms: Cargo, --target, cross-compile, rustc, no_std, debug build, release build, target/, build profile, ELF

2.2.2 Installing and using cargo-binutils

This section shows how to add cargo-binutils to the Rust toolchain and use its subcommands to inspect embedded binaries or convert them for flashing.

Key terms: cargo-binutils, LLVM tools component, rustup components, cargo nm, cargo size, cargo objdump, cargo readobj, ELF, cargo objcopy, raw binary

2.3 Oldies but goodies: The GNU binary utilities

This section explains why GNU binutils remain useful alongside Rust tooling for embedded firmware work and notes how developers can access them.

Key terms: GNU binary utilities, binutils, embedded firmware, apt, brew, Windows Subsystem for Linux (WSL)

2.3.1 Overview of key tools

This section shows how GNU binary utilities help inspect, verify, convert, and prepare embedded firmware binaries.

Key terms: file, hexdump, xxd, strings, nm, readelf, symbols, ELF, size, .text

2.4 Streamlining bare-metal Rust development

This section explains why project templates and cargo generate can make starting a bare-metal Rust project less laborious and error-prone.

Key terms: project templates, cargo generate, compatible repository, boilerplate setup

2.4.1 Installing the cargo-generate sub-command

This section explains that cargo-generate must be installed with Cargo before it can create projects from remote Git templates.

Key terms: cargo-generate, cargo generate sub-command, remote Git repository, template

2.4.2 Using a project template with cargo-generate

The section shows how cargo-generate uses stm32-template to create a configured embedded Rust project for an STM32 microcontroller.

Key terms: cargo-generate, stm32-template, STM32F103C8T6, last-release, Cargo project layout, .cargo/config.toml, target triple, memory.x, cortex-m-rt

2.4.3 Making sense of project’s settings

This section identifies the target and memory settings to check when adapting a generated project to a particular microcontroller.

Key terms: [build], .cargo/config.toml, target triple, memory.x, FLASH, RAM, linker, runtime, technical reference manual

2.5 Getting your firmware onto the device and execution/testing options

Introduces the step from building embedded Rust firmware to deploying it on hardware, including OpenOCD’s flashing role.

Key terms: linked binaries, OpenOCD, GDB, debug probe, flashing

2.5.1 Common debug interfaces

Compares SWD, JTAG, and UART bootloaders for programming and debugging microcontrollers, explaining why SWD is usually preferred for Cortex-M projects.

Key terms: Serial Wire Debug (SWD), Joint Test Action Group (JTAG), Cortex-M, boundary scan, trace, UART bootloaders, firmware, initial flashing, field updates

2.5.2 Installing and using OpenOCD

Introduces OpenOCD, how to install and configure it for a debugger and target, and what happens when it flashes firmware.

Key terms: OpenOCD, SWD, JTAG, openocd.cfg, scripts directory, interface/, target/, flashing, firmware, verifies

2.5.3 Vendor-specific CLI alternatives

This subsection compares vendor-specific firmware flashing utilities with OpenOCD and gives STM32 and ESP32 examples.

Key terms: vendor-specific tools, OpenOCD, flashing, STM32, st-flash, stlink, ST-Link, ESP32, esptool.py

2.5.4 Example: Running the firmware on the board

Walks through building and running a minimal semihosting “Hello World” firmware on a connected STM32 board.

Key terms: stm32-template, semihosting, ARM Cortex-M3 target, OpenOCD console

2.5.5 Testing and execution without hardware

This section explains when emulation and simulation help test embedded software without hardware and identifies several available platforms.

Key terms: emulation, simulation, continuous integration, automated testing, QEMU, Renode, PICSimLab, Wokwi

2.6 A Pragmatic Bare-Metal Development Environment with the Knurling Tools

Introduces Knurling as an optional, productivity-focused alternative for bare-metal Rust development.

Key terms: Knurling suite, bare-metal Rust, edit–build–flash cycle, OpenOCD/GDB-based workflows

2.6.1 Key Tools in the Knurling Ecosystem

This section identifies the complementary Knurling tools and explains what each contributes to building, deploying, observing, and starting an embedded Rust project.

Key terms: probe-rs, Cargo runner, .cargo/config.toml, cargo-flash, cargo-embed, RTT terminal, GDB server, Embed.toml, defmt, defmt-rtt

2.6.2 Installing and setting up Knurling tools

This subsection outlines how to set up Knurling tools and create a project, while noting that the generated template still needs microcontroller-specific configuration.

Key terms: cargo binstall, flip-link, Knurling-based project, Cortex-M

2.6.3 Contrasting Knurling and traditional embedded Rust workflows

This section contrasts the manual steps of a traditional embedded Rust workflow with Knurling’s faster build-and-run workflow and more efficient logging.

Key terms: stm32-template, cargo generate, probe-rs, OpenOCD, RTT, defmt, semihosting, real-time requirements, binary-encoded

2.6.4 Practical Example: "Hello World" with Knurling on the Blue Pill board

Walks through adapting a Knurling app template for the Blue Pill, then running it on hardware and observing RTT output.

Key terms: Knurling app template, Cargo.toml, src/bin, phoenix.rs, memory.x, .cargo/config.toml, runner, probe-rs, STM32F103C8, Cortex-M3

2.6.5 Traditional vs Knurling workflows

This section contrasts Knurling’s productivity benefits with traditional tools’ value for low-level debugging and explains why the book continues with GDB and OpenOCD.

Key terms: Knurling ecosystem, OpenOCD, semihosting (hprintln!()), GDB, flash-and-run development loop

2.7 Running embedded Rust code in an emulator

This section introduces emulation as a way to test embedded Rust firmware without relying on a physical development board.

Key terms: emulator, firmware testing and validation, development boards

2.7.1 The value and trade-offs of emulation

This section explains why emulation helps embedded development and which tests still require physical hardware.

Key terms: emulators, continuous integration (CI), regression testing, functional correctness, cycle-accurate timing, peripherals, board-specific quirks

2.7.2 QEMU: The workhorse emulator for embedded Rust

This section explains when QEMU is useful for embedded Rust and how to adapt and run a bare-metal project on an emulated board.

Key terms: QEMU, system mode, peripheral emulation, physical board, Blue Pill, STM32VLDISCOVERY, HAL feature, Cargo.toml, memory.x, RTT

2.7.3 The Renode emulation solution

This section explains when Renode is a useful alternative to QEMU for embedded-system emulation.

Key terms: Renode, QEMU, heterogeneous, multi-core, functional accuracy

2.7.4 The PICSimLab graphical emulation environment

This section introduces PICSimLab as a graphical emulator for interacting with simulated microcontroller circuits and peripherals.

Key terms: PICSimLab, graphical simulation environment, microcontroller circuits, common peripherals, visual feedback

2.7.5 The Wokwi graphical emulator

This subsection introduces Wokwi’s simulation strengths and how it is used for embedded Rust development.

Key terms: Wokwi, VSCode extension, real-time peripheral simulation, ESP32, ESP8266

2.8 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 1: The Foundations of embedded Rust development Chapter 3: Project structure and configuration →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.