From cc163589fc7768f077f878f047e624d1ed46cd02 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 9 Jun 2025 18:06:58 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9F=20pmme-device:=20Rust=20version=20?= =?UTF-8?q?with=20the=20esp-idf-template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmme-device/rust-version/.cargo/config.toml | 16 +++++++++++ pmme-device/rust-version/.gitignore | 4 +++ pmme-device/rust-version/Cargo.toml | 30 ++++++++++++++++++++ pmme-device/rust-version/build.rs | 3 ++ pmme-device/rust-version/rust-toolchain.toml | 2 ++ pmme-device/rust-version/sdkconfig.defaults | 10 +++++++ pmme-device/rust-version/src/main.rs | 13 +++++++++ 7 files changed, 78 insertions(+) create mode 100644 pmme-device/rust-version/.cargo/config.toml create mode 100644 pmme-device/rust-version/.gitignore create mode 100644 pmme-device/rust-version/Cargo.toml create mode 100644 pmme-device/rust-version/build.rs create mode 100644 pmme-device/rust-version/rust-toolchain.toml create mode 100644 pmme-device/rust-version/sdkconfig.defaults create mode 100644 pmme-device/rust-version/src/main.rs diff --git a/pmme-device/rust-version/.cargo/config.toml b/pmme-device/rust-version/.cargo/config.toml new file mode 100644 index 0000000..f632639 --- /dev/null +++ b/pmme-device/rust-version/.cargo/config.toml @@ -0,0 +1,16 @@ +[build] +target = "xtensa-esp32-espidf" + +[target.xtensa-esp32-espidf] +linker = "ldproxy" +runner = "espflash flash --monitor" +rustflags = [ "--cfg", "espidf_time64"] + +[unstable] +build-std = ["std", "panic_abort"] + +[env] +MCU="esp32" +# Note: this variable is not used by the pio builder (`cargo build --features pio`) +ESP_IDF_VERSION = "v5.2.3" + diff --git a/pmme-device/rust-version/.gitignore b/pmme-device/rust-version/.gitignore new file mode 100644 index 0000000..73a638b --- /dev/null +++ b/pmme-device/rust-version/.gitignore @@ -0,0 +1,4 @@ +/.vscode +/.embuild +/target +/Cargo.lock diff --git a/pmme-device/rust-version/Cargo.toml b/pmme-device/rust-version/Cargo.toml new file mode 100644 index 0000000..39efb1c --- /dev/null +++ b/pmme-device/rust-version/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "rust-version" +version = "0.1.0" +authors = ["Joseph Ferano "] +edition = "2021" +resolver = "2" +rust-version = "1.77" + +[[bin]] +name = "rust-version" +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" + +[features] +default = [] + +experimental = ["esp-idf-svc/experimental"] + +[dependencies] +log = "0.4" +esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] } + +[build-dependencies] +embuild = "0.33" diff --git a/pmme-device/rust-version/build.rs b/pmme-device/rust-version/build.rs new file mode 100644 index 0000000..112ec3f --- /dev/null +++ b/pmme-device/rust-version/build.rs @@ -0,0 +1,3 @@ +fn main() { + embuild::espidf::sysenv::output(); +} diff --git a/pmme-device/rust-version/rust-toolchain.toml b/pmme-device/rust-version/rust-toolchain.toml new file mode 100644 index 0000000..a2f5ab5 --- /dev/null +++ b/pmme-device/rust-version/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "esp" diff --git a/pmme-device/rust-version/sdkconfig.defaults b/pmme-device/rust-version/sdkconfig.defaults new file mode 100644 index 0000000..c25b89d --- /dev/null +++ b/pmme-device/rust-version/sdkconfig.defaults @@ -0,0 +1,10 @@ +# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000 + +# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). +# This allows to use 1 ms granularity for thread sleeps (10 ms by default). +#CONFIG_FREERTOS_HZ=1000 + +# Workaround for https://github.com/espressif/esp-idf/issues/7631 +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n diff --git a/pmme-device/rust-version/src/main.rs b/pmme-device/rust-version/src/main.rs new file mode 100644 index 0000000..43b4fbd --- /dev/null +++ b/pmme-device/rust-version/src/main.rs @@ -0,0 +1,13 @@ +fn main() { + // It is necessary to call this function once. Otherwise some patches to the runtime + // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 + esp_idf_svc::sys::link_patches(); + + // Bind the log crate to the ESP Logging facilities + esp_idf_svc::log::EspLogger::initialize_default(); + + loop { + log::info!("Hello, world!"); + std::thread::sleep(std::time::Duration::from_secs(1)); + } +}