commit 33a1ec6c49a65c052d05c605d7f6a3b27f85fa93
parent 4c2284e1045b4e2bafe0d1237ffd588eff7b5bd9
Author: filipton <filipton12@gmail.com>
Date: Fri, 13 Sep 2024 17:16:30 +0200
feat: multi target example (esp32s3 and esp32c3)
Diffstat:
5 files changed, 43 insertions(+), 71 deletions(-)
diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml
@@ -1,15 +1,24 @@
-[target.xtensa-esp32s3-none-elf]
-runner = "espflash flash --monitor -T ./partitions.csv --erase-parts otadata"
+[alias]
+esp32c3 = "run --no-default-features --features=esp32c3 --target=riscv32imc-unknown-none-elf"
+esp32s3 = "run --no-default-features --features=esp32s3 --target=xtensa-esp32s3-none-elf"
-[env]
-ESP_LOGLEVEL="INFO"
+[target.'cfg(target_arch = "riscv32")']
+runner = "espflash flash --monitor -T ./partitions.csv --erase-parts otadata"
+rustflags = [
+ "-C", "force-frame-pointers",
+]
-[build]
+[target.'cfg(target_arch = "xtensa")']
+runner = "espflash flash --monitor -T ./partitions.csv --erase-parts otadata"
rustflags = [
"-C", "link-arg=-nostartfiles",
]
-target = "xtensa-esp32s3-none-elf"
+[build]
+target = "xtensa-esp32s3-none-elf" #default esp32s3
+
+[env]
+ESP_LOGLEVEL="INFO"
[unstable]
build-std = ["core"]
diff --git a/examples/Cargo.lock b/examples/Cargo.lock
@@ -606,6 +606,7 @@ dependencies = [
"esp-metadata",
"esp-riscv-rt",
"esp-synopsys-usb-otg",
+ "esp32c3",
"esp32s3",
"fugit",
"log",
@@ -613,6 +614,7 @@ dependencies = [
"paste",
"portable-atomic",
"rand_core",
+ "riscv",
"serde",
"strum",
"usb-device",
@@ -790,6 +792,16 @@ dependencies = [
]
[[package]]
+name = "esp32c3"
+version = "0.25.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3922cd13da83d070892c47e66f005856c62510952198c3008bc4f3b79f3e9623"
+dependencies = [
+ "critical-section",
+ "vcell",
+]
+
+[[package]]
name = "esp32s3"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1269,11 +1281,10 @@ checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
[[package]]
name = "ruzstd"
-version = "0.7.1"
+version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1c8b8f3d26bd9f945e5cbae77f7cdfbf37af9a66956f1115eb4516e45df519f4"
+checksum = "99c3938e133aac070997ddc684d4b393777d293ba170f2988c8fd5ea2ad4ce21"
dependencies = [
- "byteorder",
"twox-hash",
]
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
@@ -6,19 +6,19 @@ edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
-esp-backtrace = { version = "0.14.1", features = [ "esp32s3", "exception-handler", "panic-handler", "println" ] }
-esp-hal = { version = "0.20.1", features = [ "esp32s3", "embedded-hal", "embedded-hal-02", "async" ] }
-esp-println = { version = "0.11.0", features = ["esp32s3", "log"] }
+esp-backtrace = { version = "0.14.1", features = [ "exception-handler", "panic-handler", "println" ] }
+esp-hal = { version = "0.20.1", features = [ "embedded-hal", "embedded-hal-02", "async" ] }
+esp-println = { version = "0.11.0", features = ["log"] }
log = { version = "0.4.22" }
-esp-wifi = { version = "0.8.0", features = [ "esp32s3", "phy-enable-usb", "utils", "wifi", "dhcpv4", "ble", "embassy-net" ] }
-esp-hal-embassy = { version = "0.3.0", features = ["integrated-timers", "esp32s3"] }
+esp-wifi = { version = "0.8.0", features = [ "phy-enable-usb", "utils", "wifi", "dhcpv4", "ble", "embassy-net" ] }
+esp-hal-embassy = { version = "0.3.0", features = ["integrated-timers"] }
embassy-executor = { version = "0.6.0", package = "embassy-executor", features = ["arch-riscv32", "task-arena-size-10240"] }
embassy-net = { version = "0.4.0", features = ["tcp", "udp", "dhcpv4", "medium-ethernet"] }
embassy-time = { version = "0.3.2" }
-esp-storage = { version = "0.3.0", features = ["esp32s3"] }
-esp-hal-ota = { path = "../", features = ["esp32s3"] }
+esp-storage = { version = "0.3.0", features = [] }
+esp-hal-ota = { path = "../", features = [] }
static_cell = { version = "2.1.0", features = ["nightly"] }
-xtensa-lx-rt = { version = "0.17.1", features = ["esp32s3", "float-save-restore"] }
+xtensa-lx-rt = { version = "0.17.1", optional = true, features = ["esp32s3", "float-save-restore"] }
[build-dependencies]
dotenvy = "0.15.7"
@@ -36,3 +36,8 @@ incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false
+
+[features]
+default = ["esp32s3"]
+esp32s3 = ["esp-backtrace/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-wifi/esp32s3", "esp-hal-embassy/esp32s3", "esp-storage/esp32s3", "esp-hal-ota/esp32s3", "dep:xtensa-lx-rt"]
+esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3", "esp-println/esp32c3", "esp-wifi/esp32c3", "esp-hal-embassy/esp32c3", "esp-storage/esp32c3", "esp-hal-ota/esp32c3"]
diff --git a/examples/build.rs b/examples/build.rs
@@ -1,30 +1,4 @@
fn main() {
- let path_env = std::env::var("PATH").expect("NO PATH ENV FOUND!");
- let rustup_home_env = std::env::var("RUSTUP_HOME").expect("NO RUSTUP_HOME ENV FOUND!");
- let esp_toolchains_path = std::path::PathBuf::from(rustup_home_env)
- .join("toolchains")
- .join("esp");
-
- if !esp_toolchains_path.exists() {
- panic!(
- ".rustup/toolchains/esp path not found! Are you sure you've installed esp toolchains?"
- );
- }
-
- let clang_path = get_newest(&esp_toolchains_path.join("xtensa-esp32-elf-clang")).expect("xtensa-esp32-elf-clang not found in esp toolchains! Are you sure you've installed esp toolchains?");
- let elf_path = get_newest(&esp_toolchains_path.join("xtensa-esp-elf")).expect(
- "xtensa-esp-elf not found in esp toolchains! Are you sure you've installed esp toolchains?",
- );
-
- println!(
- "cargo:rustc-env=LIBCLANG_PATH={}/esp-clang/lib",
- clang_path.display()
- );
- println!(
- "cargo:rustc-env=PATH={}/xtensa-esp-elf/bin:{path_env}",
- elf_path.display()
- );
-
println!("cargo:rerun-if-changed=*.env*");
if let Ok(mut iter) = dotenvy::dotenv_iter() {
while let Some(Ok((key, value))) = iter.next() {
@@ -35,30 +9,3 @@ fn main() {
println!("cargo:rustc-link-arg-bins=-Tlinkall.x");
println!("cargo:rustc-link-arg-bins=-Trom_functions.x");
}
-
-fn get_newest(path: &std::path::PathBuf) -> Option<std::path::PathBuf> {
- if !path.exists() {
- return None;
- }
-
- let mut tmp_path = (None, None);
- for entry in path.read_dir().unwrap() {
- if let Ok(entry) = entry {
- let metadata = entry.metadata().expect("Cant get dir metadata!");
- let modified = metadata.modified().expect("Cant get dir modified time!");
-
- match tmp_path.0 {
- Some(old) => {
- if modified > old {
- tmp_path = (Some(modified), Some(entry.path()));
- }
- }
- None => {
- tmp_path = (Some(modified), Some(entry.path()));
- }
- }
- }
- }
-
- tmp_path.1
-}
diff --git a/examples/src/main.rs b/examples/src/main.rs
@@ -37,7 +37,7 @@ async fn main(spawner: Spawner) {
//let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
esp_println::logger::init_logger_from_env();
- log::set_max_level(log::LevelFilter::Info);
+ //log::set_max_level(log::LevelFilter::Info); // only for esp32s3??
let rng = esp_hal::rng::Rng::new(peripherals.RNG);
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);