Welcome to Bare Metal Rust

This is a standalone one-day course about bare-metal Rust, aimed at people who are familiar with the basics of Rust (perhaps from completing the Comprehensive Rust course), and ideally also have some experience with bare-metal programming in some other language such as C.

Today we will talk about ‘bare-metal’ Rust: running Rust code without an OS underneath us. This will be divided into several parts:

  • What is no_std Rust?
  • Writing firmware for microcontrollers.
  • Writing bootloader / kernel code for application processors.
  • Some useful crates for bare-metal Rust development.

For the microcontroller part of the course we will use the BBC micro:bit v2 as an example. It’s a development board based on the Nordic nRF52833 microcontroller with some LEDs and buttons, an I2C-connected accelerometer and compass, and an on-board SWD debugger.

To get started, install some tools we’ll need later. On gLinux or Debian:

  1. sudo apt install gdb-multiarch libudev-dev picocom pkg-config qemu-system-arm
  2. rustup update
  3. rustup target add aarch64-unknown-none thumbv7em-none-eabihf
  4. rustup component add llvm-tools-preview
  5. cargo install cargo-binutils
  6. curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-tools-installer.sh | sh

And give users in the plugdev group access to the micro:bit programmer:

  1. echo 'SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0d28", MODE="0660", GROUP="logindev", TAG+="uaccess"' |\
  2. sudo tee /etc/udev/rules.d/50-microbit.rules
  3. sudo udevadm control --reload-rules

On MacOS:

  1. xcode-select --install
  2. brew install gdb picocom qemu
  3. rustup update
  4. rustup target add aarch64-unknown-none thumbv7em-none-eabihf
  5. rustup component add llvm-tools-preview
  6. cargo install cargo-binutils
  7. curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-tools-installer.sh | sh