RISC-V
Targets Only
To build Rust applications for the Espressif chips based on RISC-V
architecture, do the following:
-
Install the proper toolchain with the
rust-src
component:- For
no_std
(bare-metal) applications, you can use bothstable
ornightly
:
rustup toolchain install stable --component rust-src
or
rustup toolchain install nightly --component rust-src
- For
std
applications, you need to usenightly
:
rustup toolchain install nightly --component rust-src
The above command downloads the rust source code.
rust-src
contains things like the std-lib, core-lib and build-config files.
Downloading therust-src
is important because of two reasons :- Determinism - You get the chance to inspect the internals of the core and std library. If you are building software that needs to be determinate, you may need to inspect the libraries that you are using.
- Building custom targets - The
rustc
uses therust-src
to create the components of a new custom-target. If you are targeting a triple-target that is not yet supported by rust, it becomes essential to download therust-src
.
For more info on custom targets, read this Chapter from the Embedonomicon.
- For
-
Set the target:
-
For
no_std
(bare-metal) applications, run:rustup target add riscv32imc-unknown-none-elf # For ESP32-C2 and ESP32-C3 rustup target add riscv32imac-unknown-none-elf # For ESP32-C6 and ESP32-H2
This target is currently Tier 2. Note the different flavors of
riscv32
target in Rust covering differentRISC-V
extensions. -
For
std
applications:Since this target is currently Tier 3, it doesn't have pre-built objects distributed through
rustup
and, unlike theno_std
target, nothing needs to be installed. Refer to the *-esp-idf section of the rustc book for the correct target for your device.riscv32imc-esp-espidf
for SoCs which don't support atomics, like ESP32-C2 and ESP32-C3riscv32imac-esp-espidf
for SoCs which support atomics, like ESP32-C6, ESP32-H2, and ESP32-P4
-
-
To build
std
projects, you also need to install:LLVM
compiler infrastructure- Other
std
development requirements - In your project's file
.cargo/config.toml
, add the unstable Cargo feature-Z build-std
. Our template projects that are discussed later in this book already include this.
Now you should be able to build and run projects on Espressif's RISC-V
chips.