From 1185217fd090401873bc04fff3a271cb7a66dc8e Mon Sep 17 00:00:00 2001 From: Netwxx Date: Wed, 5 Aug 2026 14:35:48 -0700 Subject: [PATCH] Initial testing, have a blinking LED --- .cargo/config.toml | 19 +++++++++++++++++++ .envrc | 1 + .gitignore | 4 ++++ Cargo.toml | 27 +++++++++++++++++++++++++++ build.rs | 3 +++ rust-toolchain.toml | 2 ++ sdkconfig.defaults | 12 ++++++++++++ src/main.rs | 20 ++++++++++++++++++++ 8 files changed, 88 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 rust-toolchain.toml create mode 100644 sdkconfig.defaults create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..4b8eb47 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,19 @@ +[build] +target = "xtensa-esp32s3-espidf" + +[target.'cfg(target_os = "espidf")'] +linker = "ldproxy" +runner = "espflash flash --monitor" +rustflags = [ "--cfg", "espidf_time64"] + +[unstable] +build-std = ["std", "panic_abort"] + +[env] +MCU = "esp32s3" +ESP_IDF_VERSION = "v5.5.3" +ESP_IDF_TOOLS_INSTALL_DIR = "workspace" + +# Uncomment this if you have moved the target dir by setting CARGO_TARGET_DIR or similar. +# Required for now due to embuild limitations. +#CARGO_WORKSPACE_DIR = { value = "", relative = true } diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..f09569e --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +source /home/wyatt/Applications/esp32/export-esp.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73a638b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.vscode +/.embuild +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..dcf7a5e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "esp32_experiments" +version = "0.1.0" +authors = ["Netwxx "] +edition = "2021" +resolver = "2" +rust-version = "1.82" + +[[bin]] +name = "esp32_experiments" +harness = false # do not use the built-in cargo test harness -> resolve rust-analyzer errors + +[profile.release] +opt-level = "s" + +[profile.dev] +debug = true # Symbols are nice, and they don't increase the size on Flash +opt-level = "z" + +[dependencies] +log = "0.4" +esp-idf-svc = { version = "0.52.1", features = ["critical-section", "embassy-time-driver", "embassy-sync"] } +# Remove `generic-queue-8` if you plan to use `embassy-time` WITH `embassy-executor` +embassy-time = { version = "0.5", features = ["generic-queue-8"] } + +[build-dependencies] +embuild = "0.33" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..112ec3f --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + embuild::espidf::sysenv::output(); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..a2f5ab5 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "esp" diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..ca7a8a8 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,12 @@ +# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) +# You might have to increase this further if you allocate large stack variables in the main task +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 + +# Increase a bit these stack sizes as they are also a bit too small by default +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096 +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096 + +# You might have to increase this further if you spawn your own Rust threads +# that allocate large stack variables; or better yet - use +# `std::thread::Builder::new().stack_size(XXX)` for spawning +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=4096 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..29781a0 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,20 @@ +use esp_idf_svc::hal::delay::FreeRtos; +use esp_idf_svc::hal::gpio::PinDriver; +use esp_idf_svc::hal::peripherals::Peripherals; + +fn main() { + esp_idf_svc::sys::link_patches(); + esp_idf_svc::log::EspLogger::initialize_default(); + log::info!("Hello, world!"); + + let peripherals = Peripherals::take().unwrap(); + let mut led = PinDriver::output(peripherals.pins.gpio17).unwrap(); + + loop { + led.set_high().unwrap(); + FreeRtos::delay_ms(500); + led.set_low().unwrap(); + FreeRtos::delay_ms(500); + log::info!("Blink"); + } +} \ No newline at end of file