Dependancies
Buy the components
src/main.rs
use esp_idf_hal::{delay::FreeRtos, gpio::PinDriver, peripherals::Peripherals};
use esp_idf_sys as _;
fn main() {
esp_idf_sys::link_patches();
let peripherals = Peripherals::take().unwrap();
let mut led_pin = PinDriver::output(peripherals.pins.gpio3).unwrap();
loop {
led_pin.set_low().unwrap();
FreeRtos::delay_ms(1000);
led_pin.set_high().unwrap();
FreeRtos::delay_ms(1000);
println!("blink");
}
}
PORT?=/dev/cu.usbserial-*
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 flash target/riscv32imc-esp-espidf/debug/$(PROJECT_NAME)
log: ## Start the logs
cargo espmonitor $(PORT) --chip esp32c3
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 cargo-espmonitor
cargo install --list
cargo generate esp-rs/esp-idf-template cargo
With options:
Typical output:
$ cargo generate esp-rs/esp-idf-template cargo
⚠️ Favorite `esp-rs/esp-idf-template` not found in config, using it as a git repository: https://github.com/esp-rs/esp-idf-template.git
🤷 Project Name: blinky-rust-esp32c3
🔧 Destination: /Users/sayanee/Desktop/blinky-rust-esp32c3 ...
🔧 project-name: blinky-rust-esp32c3 ...
🔧 Generating template ...
✔ 🤷 Which MCU to target? · esp32c3
✔ 🤷 Configure advanced template options? · false
🔧 Moving generated files into: `/Users/sayanee/Desktop/blinky-rust-esp32c3`...
🔧 Initializing a fresh Git repository
✨ Done! New project created /Users/sayanee/Desktop/blinky-rust-esp32c3
$ cd blinky
src/main.rs
with the blinky code.Cargo.toml
to add dependencies[package]
name = "blinky-rust-esp32c3"
version = "0.1.0"
authors = ["Sayanee <[email protected]>"]
edition = "2021"
resolver = "2"
rust-version = "1.66"
[profile.release]
opt-level = "s"
[profile.dev]
debug = true
opt-level = "z"
[features]
pio = ["esp-idf-sys/pio"]
[dependencies]
esp-idf-sys = { version = "0.33.2", features = ["binstart"] }
esp-idf-hal = "0.42"
[build-dependencies]
embuild = "0.31.3"
$ cargo build
Check the port address
$ ls /dev/cu.*
/dev/cu.usbserial-1410
espflash flash target/riscv32imc-esp-espidf/debug/blinky
Start the serial monitor
cargo espmonitor /dev/cu.usbserial-1410 --chip esp32c3