Introduction

WARNING: This is only published because it's convenient, don't use this for anything

(feel free to skip sections you know about)

Scope

The following topics are covered in the core chapters:

  • How to write, build and flash an embedded program.
  • Basic operation of a GPIO, ubiquitous in microcontrollers.

Non-goals

  • Teaching electric circuit theory or electronics.

    We'll cover the minimum required to understand how some devices work along the way.

  • Covering Rustic, low level details.

    We won't be talking about linker scripts, the boot process, or how to glue those two into a minimally working Rust program.

Rust

This book is meant to be understandable for non-rust users, but not sufficient for doing anything with the information contained herein. For learning rust itself, the Rust Book is often recommended. While the syntax will no be explained, a couple necessary key concepts are listed here:

  • Traits

    Traits are comparable to interfaces in other languages

  • Crates

    Crates are the compilation unit of the rust compiler and can either be runnable binaries or libraries to be used in other crates

  • no_std

    The default rust standard library std contains features that aren't necessarily available on all targets, such as memory allocation or network support. For such targets, a stripped down version, core, is provided, that only contains features that don't require os support.

Rust embedded ecosystem

The rust embedded ecosystem, as propagated by the embedded-wg, is based on several foundational crates (we're only considering arm devices here):

  • cortex-m and cortex-m-rt

    These crates provide abstractions for the ARM Cortex-M cpus and the runtime. This includes initializing ram, implementing interrupts and much more.

  • embedded-hal

    The embedded-hal crate includes various traits, that can be used by device drivers to interface with external components, without being the specific to one MCU. The traits are usually implement by a microcontroller-specific hal.

  • PACs

    The Peripheral Access Crates are used as a basic interface to the registers of the peripherals included in the microcontroller. Most are generated using svd2rust, which translated a manufacturer-provided svd file to rust code.

  • HALs

    Hardware Abstraction Libraries wrap the code generated by the PACs into something more usable and provide safe abstractions for the peripherals. These abstractions usually consist of some chip-specific setup and an implementation of the matching embedded-hal traits for actually using the peripheral

There are also some other ecosystems, which aren't discussed here, but are also useful:

Most of the crates in the rust embedded ecosystem are listed in the awesome-embedded-rust list.