This project is set up to build and flash Rust firmware to an ESP32‑S3 using:
- Nix + direnv for a reproducible dev shell
- rustup + espup for the Xtensa Rust toolchain (
esp) - espflash for flashing and serial monitor
- Just for simplifying common commands
You already have this, but for reference:
- NixOS / Nix configuration installs:
pkgs.rustup(sorustupexists globally),- Optional Nix Rust (
pkgs.rust-bin…) for non‑ESP projects, - Tools like
rust-analyzer,pkg-config,openssl,cargo-llvm-cov.
Minimal global requirements (already configured):
-
Nix with flakes
-
direnv integrated with your shell
-
rustupinstalled globally via Nix -
A stable Rust toolchain via rustup:
rustup install stable rustup default stable
From the project root, run:
just setupThis command will:
- Create a
.envrcfile and allow direnv. - Install the ESP Xtensa toolchain using
espup. - Set the
esptoolchain as the default for this project usingrustup.
You can verify the setup:
which rustc
rustc -V
rustup show active-toolchainYou should see output indicating the esp toolchain is active.
A .cargo/config.toml file is provided in the project root to configure Cargo for the ESP32-S3 target and set espflash as the runner.
[build]
target = "xtensa-esp32s3-none-elf"
[target.xtensa-esp32s3-none-elf]
runner = "espflash flash --monitor"
[unstable]
build-std = ["core"]Notes:
- Do not add manual
rustflagslike-C target-cpu=esp32s3. - Let the ESP
esptoolchain + target spec handle CPU settings.
The flake.nix dev shell:
- Installs tools:
espup,espflash,ldproxy,esp-generate,rust-analyzer. - Sets:
CARGO_BUILD_TARGET=xtensa-esp32s3-none-elfRUST_BACKTRACE=1
- In
shellHook:- Sources
~/export-esp.sh(espup environment). - Puts
esptoolchainbinfirst inPATHso Xtensarustcis used.
- Sources
After completing the one-time setup, you can use the following just commands for your daily workflow:
-
Build:
just build-release
This builds the project in release mode for the
xtensa-esp32s3-none-elftarget. -
Flash and Monitor:
just flash
or
just flash-monitor
This command builds the project, flashes it to your ESP32-S3, and opens the serial monitor. Important: Ensure the
PORTenvironment variable is set correctly, or update thejustfilewith your specific serial port (e.g.,/dev/tty.usbmodem2101). You can list available ports withjust list-ports. -
List available serial ports:
just list-ports
-
Clean build artifacts:
just clean
- Nix + direnv: Provide a consistent and reproducible development environment, ensuring all necessary tools and dependencies are available.
- espup + rustup: Install and manage the specific Xtensa Rust toolchain required for ESP32-S3 development.
.cargo/config.toml: Configurescargoto use the correct target and runner for the ESP32-S3.- Justfile: Simplifies common development tasks into easy-to-remember commands, reducing the cognitive load and potential for errors.
One-time setup:
cd /Users/utopiaeh/Developer/mcu/guage-board
just setupDay-to-day commands:
cd /Users/utopiaeh/Developer/mcu/guage-board
# Build
just build-release
# Flash and monitor (ensure port is correct in Justfile or set as env var)
just flash