Setting up ESP32 environment based on Rust

Installing Rust#

Refer to Rust Installation/Update/Packaging

Switching Rust to nightly#

rustup install nightly
rustup default nightly

Installing ESP32 Tools#

There are two ways to develop ESP32 with Rust:

  • Develop using the std library
  • Develop using the core library (no_std) for bare-metal development


This must be installed when building applications using the Rust standard library std

cargo install ldproxy


Tool for flashing ESP devices

# cargo-espflash is used for cross-compiling and flashing
cargo install cargo-espflash
cargo install espflash


Serial monitor for esp32 and esp8266

# cargo-espmonitor is used for serial monitoring of esp32 and esp8266
cargo install cargo-espmonitor
cargo install espmonitor

Only for RISC-V targets#

To build Rust applications for Espressif chips based on the RISC-V architecture, follow these steps:

  1. Install the nightly toolchain and rust-src component
rustup toolchain install nightly --component rust-src
rustup default nightly
  1. Set the target
  • For no_std bare-metal applications, run
# For ESP32-C2 and ESP32-C3
rustup target add riscv32imc-unknown-none-elf
# For ESP32-C6 and ESP32-M2
rustup target add riscv32imac-unknown-none-elf

Creating a New Project#

Install cargo-generate:

cargo install cargo-generate

Once the above tools are installed, you can use the corresponding templates to generate projects. There are two templates available:

  1. esp-template - Bare-metal no_std project template
  2. esp-idf-template - Template with std support

You can clone both templates to your local machine so that you don't have to download them from GitHub in the future:

mkdir ~/.espressif
cd ~/.espressif
git clone
git clone

Then, create a project based on a template. For example, create a project using the esp-idf-template:

cargo generate ~/.espressif/esp-idf-template/

create espidf project

Configuring the Project#

Open .cargo/config.toml and add the following lines to the bottom of the [env] section. Keep the rest of the content unchanged.

cd xxx
vi .cargo/config.toml
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }

Running the Project#

# Cross-compile the project
cargo build --release
# Cross-compile and run the project
cargo run --release

cargo run

Checking Hardware#

If you encounter any issues, refer to Checking Hardware


Official Website#, wokwi is a web-based online simulation platform.

To write code locally, you can install the web simulation:

cargo install wokwi-server
  1. Create a new project
  2. Take note of the id of the web URL


  1. Then, locally enter
# Compile
cargo build --release
# Run
wokwi-server -c esp32c3 -i 网页端的id target/riscv32imac-esp-espidf/release/espidf-demo



Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.