2023-02-01 15:57:05 +00:00
|
|
|
# Welcome to Bare Metal Rust
|
2023-02-10 04:06:07 +00:00
|
|
|
|
2023-03-08 17:45:08 +00:00
|
|
|
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.
|
|
|
|
|
2023-02-17 00:46:42 +00:00
|
|
|
Today we will talk about 'bare-metal' Rust: running Rust code without an OS underneath us. This will
|
2023-02-10 04:06:07 +00:00
|
|
|
be divided into several parts:
|
|
|
|
|
2023-03-24 17:51:10 +00:00
|
|
|
- What is `no_std` Rust?
|
|
|
|
- Writing firmware for microcontrollers.
|
|
|
|
- Writing bootloader / kernel code for application processors.
|
|
|
|
- Some useful crates for bare-metal Rust development.
|
2023-02-15 04:52:47 +00:00
|
|
|
|
2023-02-17 00:46:42 +00:00
|
|
|
For the microcontroller part of the course we will use the [BBC micro:bit](https://microbit.org/) v2
|
2023-03-03 18:02:06 +00:00
|
|
|
as an example. It's a [development board](https://tech.microbit.org/hardware/) based on the Nordic
|
|
|
|
nRF51822 microcontroller with some LEDs and buttons, an I2C-connected accelerometer and compass, and
|
|
|
|
an on-board SWD debugger.
|
2023-02-17 00:46:42 +00:00
|
|
|
|
2023-03-17 16:39:58 +00:00
|
|
|
To get started, install some tools we'll need later. On gLinux or Debian:
|
2023-02-15 04:52:47 +00:00
|
|
|
|
|
|
|
```bash
|
2023-04-21 19:29:18 +01:00
|
|
|
sudo apt install gcc-aarch64-linux-gnu gdb-multiarch libudev-dev picocom pkg-config qemu-system-arm
|
2023-02-15 04:52:47 +00:00
|
|
|
rustup update
|
2023-03-21 17:24:49 +00:00
|
|
|
rustup target add aarch64-unknown-none thumbv7em-none-eabihf
|
2023-03-24 17:51:10 +00:00
|
|
|
rustup component add llvm-tools-preview
|
2023-02-15 04:52:47 +00:00
|
|
|
cargo install cargo-binutils cargo-embed
|
2023-03-20 14:09:00 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
And give users in the `plugdev` group access to the micro:bit programmer:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", MODE="0664", GROUP="plugdev"' |\
|
|
|
|
sudo tee /etc/udev/rules.d/50-microbit.rules
|
2023-03-03 18:02:25 +00:00
|
|
|
sudo udevadm control --reload-rules
|
2023-02-15 04:52:47 +00:00
|
|
|
```
|
2023-03-03 18:02:46 +00:00
|
|
|
|
2023-03-17 16:39:58 +00:00
|
|
|
On MacOS:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
xcode-select --install
|
2023-03-21 17:24:49 +00:00
|
|
|
brew install gdb picocom qemu
|
2023-03-23 14:43:48 +00:00
|
|
|
brew install --cask gcc-aarch64-embedded
|
2023-03-17 16:39:58 +00:00
|
|
|
rustup update
|
2023-03-21 17:24:49 +00:00
|
|
|
rustup target add aarch64-unknown-none thumbv7em-none-eabihf
|
2023-03-24 17:51:10 +00:00
|
|
|
rustup component add llvm-tools-preview
|
2023-03-17 16:39:58 +00:00
|
|
|
cargo install cargo-binutils cargo-embed
|
|
|
|
```
|