Welcome to Bare Metal Rust

这是单独为裸机 Rust 开设的课程,为期一天,主要面向熟悉 Rust 基础知识的人员(例如已学完 Comprehensive Rust),最好也有一些使用其他语言(例如 C)进行裸机编程的经验。

今天,我们将探讨 bare-metal Rust:即在没有操作系统支持的情况下运行 Rust 代码。该部分主要分为以下内容:

  • 什么是 no_std Rust?
  • 编写微控制器固件。
  • 为应用处理器编写引导加载程序 / 内核代码。
  • 有助于裸机 Rust 开发的一些实用 crate。

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.

首先,请安装我们稍后需要用到的一些工具。在 gLinux 或 Debian 上:

sudo apt install gcc-aarch64-linux-gnu gdb-multiarch libudev-dev picocom pkg-config qemu-system-arm
rustup update
rustup target add aarch64-unknown-none thumbv7em-none-eabihf
rustup component add llvm-tools-preview
cargo install cargo-binutils cargo-embed

然后,向 plugdev 组中的用户授予 micro:bit 编程器的访问权限:

echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", MODE="0664", GROUP="plugdev"' |\
  sudo tee /etc/udev/rules.d/50-microbit.rules
sudo udevadm control --reload-rules

在 MacOS 上:

xcode-select --install
brew install gdb picocom qemu
brew install --cask gcc-aarch64-embedded
rustup update
rustup target add aarch64-unknown-none thumbv7em-none-eabihf
rustup component add llvm-tools-preview
cargo install cargo-binutils cargo-embed