Below is a compact “shopping list” + step-by-step setup guide for getting real Rust code onto an ESP32.
I’ll split it into Hardware, Software/Toolchain, and a tiny “first blinky” so you can verify everything works.
1. Hardware
| Must-have | Purpose | Notes |
|---|
| ESP32 development board (ESP32-WROOM, WROVER, DevKit-C, etc.) | The MCU you’ll flash | If you own an ESP32-C3 board (RISC-V core) things are slightly easier, but everything below still applies. |
| USB-to-micro/USB-C cable | Power + serial flashing | Needs to carry data, not just charge. |
| Host computer (Windows, macOS, Linux) | Build environment | A Raspberry Pi works too. |
| — | | |
Optional but nice:
| Nice-to-have | Why |
|---|
| External 5 V supply | More reliable power for Wi-Fi/BLE tests |
| JTAG probe (ESP-PROG / J-Link) | On-chip debugging with probe-rs, GDB, VS Code |
| Breadboard + LED + resistor | Quick hardware tests (“blinky”) |
2. Software / Toolchain
There are TWO big flavors of “Rust on ESP32”:
-
RISC-V ESP chips (ESP32-C2 / C3 / H2 / C6) → supported by upstream Rust
Target triple: riscv32imc-unknown-none-elf
-
The original Xtensa-LX6/LX7 ESP chips (ESP32, S2, S3, etc.) → needs a custom Rust fork
Target triple: xtensa-esp32-xxx-elf (installed via espup)
I’ll show both; pick the path that matches your board.
2-A. Common prerequisites
# 1. Install Rust tooling
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Windows: use rustup-init.exe
rustup update
# 2. Add some convenient cargo sub-commands
cargo install espflash # flashes & monitors over USB-serial
cargo install cargo-binutils cargo-espflash
rustup component add llvm-tools-preview # for objdump, size etc.
You’ll also want a recent rust-analyzer or VS Code “Rust” extension for IDE features.
2-B. If you have an ESP32-C3 (RISC-V)
rustup target add riscv32imc-unknown-none-elf
# Optional clang/binutils if you plan to link C code
sudo apt install gcc-riscv32-unknown-elf # (Linux/Debian example)
Rust ecosystem crates:
# Cargo.toml snippet
[dependencies]
esp32c3-hal = "0.13" # Hardware Abstraction Layer
riscv-rt = "0.11"
panic-halt = "0.2" # or panic-probe
Build & flash:
cargo espflash --release # auto-detects the USB port
cargo size --release -- -A # check binary size
2-C. If you have a classic ESP32 / S2 / S3 (Xtensa)
Xtensa still needs a forked compiler + LLVM; espup makes that painless.
curl https://raw.githubusercontent.com/esp-rs/espup/main/install.sh | bash
# chose 'nightly' + 'esp' during the prompt; restart terminal
espup install # installs xtensa-rust, GCC cross-tools & sets env vars
rustup default esp # or source ~/.cargo/env & ~/.embuild/env
# Add the target for your exact chip
rustup target add xtensa-esp32-none-elf # <- WROOM/WROVER
rustup target add xtensa-esp32s3-none-elf # <- S3, etc.
Crates:
[dependencies]
esp32-hal = "0.16" # change to esp32s3-hal for S3
esp-backtrace = "0.7"
panic-halt = "0.2"
Build & flash:
cargo espflash --release --target xtensa-esp32-none-elf
2-D. Want the full ESP-IDF (Wi-Fi/BLE/Std lib) ?
If you need Wi-Fi, TLS, NVS, etc. you can link against Espressif’s ESP-IDF C SDK:
cargo install cargo-generate
cargo generate --git https://github.com/esp-rs/esp-idf-template cargo
# then: idf.py menuconfig # (sets Wi-Fi creds)
# cargo build --release
# cargo espflash ...
Internally this uses crates esp-idf-sys, esp-idf-hal, esp-idf-svc and a build.rs that pulls the C toolchain + headers.
3. Verify with a 20-line “blinky”
main.rs
#![no_std]
#![no_main]
use esp32_hal as hal; // or esp32c3_hal
use hal::{clock::ClockControl, delay::Delay, prelude::*, peripherals::Peripherals};
use xtensa_lx_rt::entry; // riscv_rt::entry for C3
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);
let mut led = io.pins.gpio2.into_push_pull_output(); // onboard LED on many boards
loop {
led.toggle().unwrap();
delay.delay_ms(500u32);
}
}
Cargo.toml (C3 example)
[package] # ...
[dependencies]
esp32c3-hal = "0.13"
riscv-rt = "0.11"
panic-halt = "0.2"
Build & run:
cargo espflash /dev/ttyUSB0 --monitor # auto-reset & serial console
You should see the LED blink and serial output like rst:0x1 ….
4. Debugging & monitoring
• For logging, add defmt (defmt-rtt or UART).
• For on-chip debugging, plug an ESP-PROG or J-Link into GPIO13/14 (TCK/TMS) and:
probe-rs debug --chip ESP32C3
# or use VS Code + embGDB extension
5. Cheatsheet
| Command | Description |
|---|
cargo espflash --monitor | Build, flash, then open serial monitor |
espflash serial-monitor | Only monitor (no flash) |
cargo size --release -- -A | View .text/.data sizes |
cargo fix --edition | Auto-apply edition fixes |
idf.py menuconfig | Configure ESP-IDF projects |
espup update | Update Xtensa toolchain |
In short
- Get rustup +
espflash.
- Add
riscv32imc-unknown-none-elf (ESP32-C3) or run espup (Xtensa).
- Grab a HAL crate, write
#![no_std] firmware, cargo espflash.
- For Wi-Fi/BLE, use the ESP-IDF Rust bindings.
That’s literally all you need—happy hacking! 🚀