Dependancies
Buy the components
src/main.rs
use std::thread;
use std::time::Duration;
use esp_idf_sys as _;
use embedded_hal::digital::blocking::OutputPin;
use esp_idf_hal::peripherals::Peripherals;
fn main() {
esp_idf_sys::link_patches();
let peripherals = Peripherals::take().unwrap();
let mut led = peripherals.pins.gpio3.into_output().unwrap();
let n = 1;
while n == 1 {
led.set_high().unwrap();
thread::sleep(Duration::from_millis(1000));
led.set_low().unwrap();
thread::sleep(Duration::from_millis(1000));
println!("blink");
}
}
PORT?=/dev/cu.SLAB_USBtoUART*
PROJECT_NAME=blinky-rust-esp32c3
.PHONY: default compile upload log clean
default: clean compile upload
help: ## Show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
compile: ## Compile rust
cargo clean
cargo build
upload: ## Upload the firmware to the board
espflash $(PORT) target/riscv32imc-esp-espidf/debug/$(PROJECT_NAME)
log: ## Start the logs
espmonitor $(PORT)
clean: ## Remove all build files
cargo clean
rustup target add riscv32imc-unknown-none-elf
cargo install cargo-generate
cargo install ldproxy
cargo install espup
cargo install espflash
cargo install --list
cargo generate --vcs none --git https://github.com/esp-rs/esp-idf-template cargo
Typical output:
🤷 Project Name: blinky-rust-esp32c3
🔧 Destination: /Users/sayanee/Desktop/blinky-rust-esp32c3 ...
🔧 project-name: blinky-rust-esp32c3 ...
🔧 Generating template ...
✔ 🤷 STD support · true
✔ 🤷 MCU · esp32c3
✔ 🤷 ESP-IDF native build version (v4.3.2 = previous stable, v4.4 = stable, mainline = UNSTABLE) · v4.4
? 🤷 Configure project to use Dev Containers (VS Code, GitHub Codespaces and Gitpod)?
✔ 🤷 Configure project to use Dev Containers (VS Code, GitHub Codespaces and Gitpod)?
🔧 Moving generated files into: `/Users/sayanee/Desktop/blinky-rust-esp32c3`...
✨ Done! New project created /Users/sayanee/Desktop/blinky-rust-esp32c3
$ cd blinky-rust-esp32c3
src/main.rs
with the blinky code.Cargo.toml
to add dependencies
[dependencies]
embedded-hal = "1.0.0-alpha.8"
esp-idf-sys = { version = "0.31.11", features = ["binstart"] }
esp-idf-hal = "0.38.1"
$ cargo build
Check the port address
$ ls /dev/cu.*
/dev/cu.SLAB_USBtoUART /dev/cu.usbserial-1410
espflash /dev/cu.SLAB_USBtoUART target/riscv32imc-esp-espidf/debug/blinky-rust-esp32c3
Start the serial monitor
espmonitor /dev/cu.SLAB_USBtoUART