Today I will share my journey of preparing a working environment to develop Rust for Espressif boards. Discover how I made the decision to work with Rust for embedded systems, a language known for its safety, speed, and reliability. I’ll also guide you through the process of preparing your development environment, like installing necessary tools, and configuring your workspace to program Rust in VS Code using Docker Dev Containers.

Preview

vs code rust dev containers

Demo

You can find the code for this demo on my Github.

Getting started

To beggin you will need the following programs installed:

  • VS Code
  • Docker
  • Rust and Cargo
  • cargo: ldproxy, espflash, espmonitor

For this demo I will use a LilyGO T-Dongle-S3 that is based on the ESP32-s3. So if you have this dongle you can try to run this demo, otherwise you can use this esp-rs template and select the board that you have.

To clone the project and start working on it:

git clone -b demo https://github.com/ddavidmelo/rust-esp32-dongle.git

Based on the ESP32 model that you are using, run the following Docker image that provides the necessary environment to develop applications in Rust for Espressif devices.

sudo docker run -v $PWD:/project -it espressif/idf-rust:esp32s3_latest

The next step is to open the project folder in Visual Studio Code. To build and develop on this project, make sure you have the following VS Code plugins: vs code dev containers rust-analyser

With these plugins installed and the idf-rust container running, you are able to build the project. To do that, you need to enter in the container. To achieve this, in Visual Studio Code press Ctrl+Shift+P to open the Command Palette, and then select “Attach to a running container” (choose the name of the container you previously ran): vs code dev containers This will open a new window.

Compiling

In the new VS Code window, the terminal should pop up. In there, you are able to build the project:

cargo install -f ldproxy
cargo build

Flashing

After building the project, to flash the device, you will need to follow some additional steps in your local machine. First, ensure that you have Rust installed by running the following commands:

curl https://sh.rustup.rs -sSf | sh
source "$HOME/.cargo/env"

Next, make sure you have the following software package installed:

sudo apt-get install pkg-config libudev-dev

Finally, you need to install the following auxiliary tools:

cargo install -f ldproxy espflash espmonitor

These steps are necessary to prepare your environment for flashing the device. Now open a new terminal (outside of the container) and in the project folder run the following commands:

espflash /dev/ttyACM0 target/xtensa-esp32s3-espidf/debug/dongle-demo
espmonitor /dev/ttyACM0

lilygo rust demo app

Tips for LilyGO T-Dongle-S3

If the port cannot be found when uploading the program or the USB has been used for other functions, the port does not appear. Please enter the upload mode manually:

  1. Press and hold the BOOT button , While still pressing the BOOT button, Insert USB
  2. Release the BOOT button
  3. Upload sketch