This is a simple example of how to use Rust to program an ESP32 microcontroller.
This project is based on the esp-idf-template project.
See Prequisites
Add user to dialout group to access serial port:
sudo usermod -a -G dialout $USER
Install cargo espflash:
cargo install cargo-espflash
cargo espflash board-info
outputs:
[2024-02-04T12:12:44Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-02-04T12:12:44Z INFO ] Connecting...
[2024-02-04T12:12:45Z INFO ] Unable to connect, retrying with extra delay...
[2024-02-04T12:12:46Z INFO ] Using flash stub
Chip type: esp32 (revision v1.0)
Crystal frequency: 40MHz
Flash size: 4MB
Features: WiFi, BT, Dual Core, 240MHz, Coding Scheme None
MAC address: 24:6f:28:00:00:00
If you get an error like:
[2024-02-04T12:12:44Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-02-04T12:12:44Z INFO ] Connecting...
[2024-02-04T12:12:45Z INFO ] Unable to connect, retrying with extra delay...
Try to press the boot button on the ESP32 board and run the command again.
Copy example.env
to .env
and adjust the settings.
. $HOME/export-esp.sh
cargo build
I tested on two boards:
To configure the right pins, you can use the v2
or v3
feature:
cargo build --features v2
cargo espflash flash --release --monitor --partition-table partitions.csv