From 96a0658b3d872f565999ad152b0c5992b8af2ae6 Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Sat, 13 Jul 2024 16:29:53 -0700 Subject: [PATCH 1/5] some refactoring and add ESP32 support --- Cargo.toml | 2 +- README.md | 7 +- ci.sh | 6 + src/chip.rs | 48 ++-- src/chip/family.rs | 8 +- src/chip/family/esp.rs | 16 ++ src/chip/target.rs | 8 +- src/cli/init_args/panic_handler.rs | 2 +- src/error.rs | 1 + src/init.rs | 207 +++++++++++------- src/templates/build.rs.esp.template | 3 + ...s.stm32.template => build.rs.stm.template} | 0 src/templates/config.toml.esp.template | 16 ++ src/templates/main.rs.esp.template | 37 ++++ ...rs.stm32.template => main.rs.stm.template} | 0 .../rust-toolchain.toml.esp.template | 4 + 16 files changed, 259 insertions(+), 106 deletions(-) create mode 100644 src/chip/family/esp.rs create mode 100644 src/templates/build.rs.esp.template rename src/templates/{build.rs.stm32.template => build.rs.stm.template} (100%) create mode 100644 src/templates/config.toml.esp.template create mode 100644 src/templates/main.rs.esp.template rename src/templates/{main.rs.stm32.template => main.rs.stm.template} (100%) create mode 100644 src/templates/rust-toolchain.toml.esp.template diff --git a/Cargo.toml b/Cargo.toml index 917b79b..522cecc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,5 @@ Inflector = "0.11.4" clap = { version = "4.4.11", features = ["derive"] } indicatif = "0.17.7" open = "5.0.1" -probe-rs = "0.21.1" +probe-rs = "0.24.0" termimad = "0.29.1" diff --git a/README.md b/README.md index 4f3db28..94d30b1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Get up and running with Embassy in seconds. # Features -- Supports STM32* and NRF* +- Supports STM32*, NRF*, and ESP32(C3/S3) - Generates project structure - Toolchain - Probing @@ -57,3 +57,8 @@ cargo embassy init my_project --chip nrf52840 ```sh cargo embassy init my_project --chip nrf52832_xxAA --softdevice s132 ``` + +**Create a new Embassy project for the ESP32S3** +```sh +cargo embassy init my_project --chip esp32s3 +``` diff --git a/ci.sh b/ci.sh index 742c3d1..0c9b38e 100755 --- a/ci.sh +++ b/ci.sh @@ -27,11 +27,17 @@ $cwd/target/release/cargo-embassy embassy init test-stm32g4 --chip stm32g431rb - $cwd/target/release/cargo-embassy embassy init test-nrf52840 --chip nrf52840 $cwd/target/release/cargo-embassy embassy init test-nrf52832 --chip nrf52832-xxab --softdevice s132 +# esp32 +$cwd/target/release/cargo-embassy embassy init test-esp32c3 --chip esp32c3 +$cwd/target/release/cargo-embassy embassy init test-esp32s3 --chip esp32s3 + # compile cd test-stm32g0; cargo build; cargo build --no-default-features --release cd ../test-stm32g4; cargo build; cargo build --no-default-features --release cd ../test-nrf52840; cargo build; cargo build --no-default-features --release cd ../test-nrf52832; cargo build; cargo build --no-default-features --release +cd ../test-esp32c3; cargo build --release +cd ../test-esp32s3; cargo build --release # clean up cd ../.. diff --git a/src/chip.rs b/src/chip.rs index a2fc418..99a8a24 100644 --- a/src/chip.rs +++ b/src/chip.rs @@ -1,6 +1,8 @@ pub mod family; pub mod target; +use family::esp::Variant; + use crate::error::{Error, InvalidChip}; use std::str::FromStr; @@ -29,25 +31,28 @@ impl FromStr for Chip { ("nrf52840", (NRF(MemRegion::NRF52840), Thumbv7f)), // TODO: nrf53x and nrf91x // STM - ("stm32c0", (STM32, Thumbv6)), - ("stm32f0", (STM32, Thumbv6)), - ("stm32f1", (STM32, Thumbv7)), - ("stm32f2", (STM32, Thumbv7)), - ("stm32f3", (STM32, Thumbv7e)), - ("stm32f4", (STM32, Thumbv7e)), - ("stm32f7", (STM32, Thumbv7e)), - ("stm32g0", (STM32, Thumbv6)), - ("stm32g4", (STM32, Thumbv7e)), - ("stm32h5", (STM32, Thumbv8)), - ("stm32h7", (STM32, Thumbv7e)), - ("stm32l0", (STM32, Thumbv6)), - ("stm32l1", (STM32, Thumbv7)), - ("stm32l4", (STM32, Thumbv7e)), - ("stm32l5", (STM32, Thumbv8)), - ("stm32u5", (STM32, Thumbv8)), - ("stm32wb", (STM32, Thumbv7e)), - ("stm32wba", (STM32, Thumbv8)), - ("stm32wl", (STM32, Thumbv7e)), + ("stm32c0", (STM, Thumbv6)), + ("stm32f0", (STM, Thumbv6)), + ("stm32f1", (STM, Thumbv7)), + ("stm32f2", (STM, Thumbv7)), + ("stm32f3", (STM, Thumbv7e)), + ("stm32f4", (STM, Thumbv7e)), + ("stm32f7", (STM, Thumbv7e)), + ("stm32g0", (STM, Thumbv6)), + ("stm32g4", (STM, Thumbv7e)), + ("stm32h5", (STM, Thumbv8)), + ("stm32h7", (STM, Thumbv7e)), + ("stm32l0", (STM, Thumbv6)), + ("stm32l1", (STM, Thumbv7)), + ("stm32l4", (STM, Thumbv7e)), + ("stm32l5", (STM, Thumbv8)), + ("stm32u5", (STM, Thumbv8)), + ("stm32wb", (STM, Thumbv7e)), + ("stm32wba", (STM, Thumbv8)), + ("stm32wl", (STM, Thumbv7e)), + // ESP32 + ("esp32c3", (ESP(Variant::C3), Risc32Imc)), + ("esp32s3", (ESP(Variant::S3), XTensaS3)), ]; let (family, target) = chips @@ -59,10 +64,11 @@ impl FromStr for Chip { })?; Ok(Self { - name: match family { - STM32 => chip.to_string(), + name: match &family { + STM => chip.to_string(), // FRAGILE: "_" is used to coerce probe-rs chip search NRF(_) => chip.split('_').next().unwrap().to_string(), + ESP(variant) => variant.to_string(), }, family, target, diff --git a/src/chip/family.rs b/src/chip/family.rs index 5f5d390..212521d 100644 --- a/src/chip/family.rs +++ b/src/chip/family.rs @@ -1,20 +1,24 @@ +pub mod esp; pub mod mem_region; +use esp::Variant; use mem_region::MemRegion; use std::fmt::Display; #[allow(clippy::upper_case_acronyms)] #[derive(Debug, Clone)] pub enum Family { - STM32, + STM, NRF(MemRegion), + ESP(Variant), } impl Display for Family { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { - Self::STM32 => "stm32", + Self::STM => "stm32", Self::NRF(_) => "nrf", + Self::ESP(_) => "esp", }) } } diff --git a/src/chip/family/esp.rs b/src/chip/family/esp.rs new file mode 100644 index 0000000..3a3f996 --- /dev/null +++ b/src/chip/family/esp.rs @@ -0,0 +1,16 @@ +use std::fmt::Display; + +#[derive(Clone, Debug)] +pub enum Variant { + C3, + S3, +} + +impl Display for Variant { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Self::C3 => "esp32c3", + Self::S3 => "esp32s3", + }) + } +} diff --git a/src/chip/target.rs b/src/chip/target.rs index b4ade8c..1943914 100644 --- a/src/chip/target.rs +++ b/src/chip/target.rs @@ -1,14 +1,14 @@ -use clap::ValueEnum; use std::fmt::Display; -#[derive(Debug, Clone, ValueEnum)] -#[value()] +#[derive(Debug, Clone)] pub enum Target { Thumbv6, Thumbv7, Thumbv7e, Thumbv7f, Thumbv8, + XTensaS3, + Risc32Imc, } impl Display for Target { @@ -19,6 +19,8 @@ impl Display for Target { Self::Thumbv7e => "thumbv7em-none-eabi", Self::Thumbv7f => "thumbv7em-none-eabihf", Self::Thumbv8 => "thumbv8m.main-none-eabihf", + Self::XTensaS3 => "xtensa-esp32s3-none-elf", + Self::Risc32Imc => "riscv32imc-unknown-none-elf", }) } } diff --git a/src/cli/init_args/panic_handler.rs b/src/cli/init_args/panic_handler.rs index 36e9451..45be452 100644 --- a/src/cli/init_args/panic_handler.rs +++ b/src/cli/init_args/panic_handler.rs @@ -1,6 +1,6 @@ use clap::ValueEnum; -#[derive(Debug, Clone, Default, ValueEnum)] +#[derive(Debug, Clone, Default, PartialEq, ValueEnum)] #[value()] pub enum PanicHandler { #[default] diff --git a/src/error.rs b/src/error.rs index 61eb427..4e76cfd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,6 +6,7 @@ pub enum Error { CreateFile(String), CreateFolder(String), ErroneousSoftdevice, + ErroneousPanicHandler, InvalidChip(InvalidChip), } diff --git a/src/init.rs b/src/init.rs index 6567454..e66cb2e 100644 --- a/src/init.rs +++ b/src/init.rs @@ -1,7 +1,6 @@ use crate::{ chip::{ - family::{mem_region::MemRegion, Family}, - target::Target, + family::{esp::Variant, mem_region::MemRegion, Family}, Chip, }, cli::init_args::{panic_handler::PanicHandler, soft_device::Softdevice, InitArgs}, @@ -53,8 +52,8 @@ impl Init { self.create_project(&args.name)?; - self.init_config(&chip.target, &probe_target_name)?; - self.init_toolchain(&chip.target)?; + self.init_config(&chip, &probe_target_name)?; + self.init_toolchain(&chip)?; self.init_embed(&probe_target_name)?; self.init_build(&chip.family)?; self.init_manifest( @@ -63,7 +62,9 @@ impl Init { &args.panic_handler, args.softdevice.as_ref(), )?; - self.init_fmt()?; + if !matches!(&chip.family, Family::ESP(_)) { + self.init_fmt()?; + } self.init_main(&chip.family, &args.panic_handler, args.softdevice.as_ref())?; if let Family::NRF(mem_reg) = chip.family { @@ -100,26 +101,39 @@ impl Init { } } - fn init_config(&self, target: &Target, chip: &str) -> Result<(), Error> { + fn init_config(&self, chip: &Chip, name: &str) -> Result<(), Error> { fs::create_dir_all(".cargo").map_err(|_| Error::CreateFolder(".cargo".into()))?; self.create_file( ".cargo/config.toml", - &format!( - include_str!("templates/config.toml.template"), - target = target, - chip = chip - ), + &match &chip.family { + Family::ESP(variant) => format!( + include_str!("templates/config.toml.esp.template"), + target = chip.target, + rustflags = match variant { + Variant::C3 => "rustflags = [\n\"-C\", \"force-frame-pointers\",\n]", + Variant::S3 => "rustflags = [\n\"-C\", \"link-arg=-nostartfiles\",\n]", + } + ), + _ => format!( + include_str!("templates/config.toml.template"), + target = chip.target, + chip = name + ), + }, ) } - fn init_toolchain(&self, target: &Target) -> Result<(), Error> { + fn init_toolchain(&self, chip: &Chip) -> Result<(), Error> { self.create_file( "rust-toolchain.toml", - &format!( - include_str!("templates/rust-toolchain.toml.template"), - target = target - ), + &match chip.family { + Family::ESP(_) => include_str!("templates/rust-toolchain.toml.esp.template").into(), + _ => format!( + include_str!("templates/rust-toolchain.toml.template"), + target = chip.target + ), + }, ) } @@ -132,8 +146,9 @@ impl Init { fn init_build(&self, family: &Family) -> Result<(), Error> { let template = match family { - Family::STM32 => include_str!("templates/build.rs.stm32.template"), + Family::STM => include_str!("templates/build.rs.stm.template"), Family::NRF(_) => include_str!("templates/build.rs.nrf.template"), + Family::ESP(_) => include_str!("templates/build.rs.esp.template"), }; self.create_file("build.rs", template) @@ -154,31 +169,59 @@ impl Init { // NOTE: should be threaded proably self.cargo_add( "embassy-executor", - Some(&["arch-cortex-m", "executor-thread", "integrated-timers"]), + match &chip.family { + Family::ESP(_) => Some(&["executor-thread"]), + _ => Some(&["arch-cortex-m", "executor-thread", "integrated-timers"]), + }, false, )?; self.cargo_add("embassy-sync", None, false)?; self.cargo_add("embassy-futures", None, false)?; - self.cargo_add("embassy-time", Some(&["tick-hz-32_768"]), false)?; + self.cargo_add( + "embassy-time", + match &chip.family { + Family::ESP(_) => Some(&["generic-queue-8"]), + _ => Some(&["tick-hz-32_768"]), + }, + false, + )?; - match chip.family { - Family::STM32 => self.cargo_add( - "embassy-stm32", - Some(&[ - "memory-x", - chip.name.as_str(), - "time-driver-any", - "exti", - "unstable-pac", - ]), - false, - ), - Family::NRF(_) => self.cargo_add( - "embassy-nrf", - Some(&[chip.name.as_str(), "gpiote", "time-driver-rtc1"]), - false, - ), - }?; + match &chip.family { + Family::STM => { + self.cargo_add( + "embassy-stm32", + Some(&[ + "memory-x", + chip.name.as_str(), + "time-driver-any", + "exti", + "unstable-pac", + ]), + false, + )?; + } + Family::NRF(_) => { + self.cargo_add( + "embassy-nrf", + Some(&[chip.name.as_str(), "gpiote", "time-driver-rtc1"]), + false, + )?; + } + Family::ESP(variant) => { + let name = variant.to_string(); + + self.cargo_add("embassy-time-driver", None, false)?; + self.cargo_add( + "esp-backtrace", + Some(&[&name, "exception-handler", "panic-handler", "println"]), + false, + )?; + self.cargo_add("esp-hal", Some(&[&name]), false)?; + self.cargo_add("esp-hal-embassy", Some(&[&name, "time-timg0"]), false)?; + self.cargo_add("esp-println", Some(&[&name, "log"]), false)?; + self.cargo_add("log", None, false)?; + } + }; if let Some(softdevice) = softdevice { self.cargo_add( @@ -195,48 +238,57 @@ impl Init { self.cargo_add(&format!("nrf-softdevice-{}", softdevice.str()), None, false)?; } - self.cargo_add( - "cortex-m", - Some(if softdevice.is_some() { - &["inline-asm"] - } else { - &["inline-asm", "critical-section-single-core"] - }), - false, - )?; - self.cargo_add("cortex-m-rt", None, false)?; - self.cargo_add("defmt", None, true)?; - self.cargo_add("defmt-rtt", None, true)?; - self.cargo_add("panic-probe", Some(&["print-defmt"]), true)?; - self.cargo_add(panic_handler.str(), None, false)?; - - let mut file = fs::OpenOptions::new() - .read(true) - .append(true) - .open("Cargo.toml") - .map_err(|_| Error::CreateFile("Cargo.toml".into()))?; - - // really gross patch for cargo version discontinuity - // somewhere between cargo 1.72 and 1.76 the behavior of "cargo add" changed - let mut buf = String::new(); - file.read_to_string(&mut buf).unwrap(); - if !buf.contains("[features]") { - file.write_all(include_str!("templates/Cargo.toml.feature-patch.template").as_bytes()) + if let Family::ESP(_) = &chip.family { + println!("[NOTICE] ESP32s have their own panic handler system."); + if panic_handler.ne(&PanicHandler::default()) { + Err(Error::ErroneousPanicHandler)? + } + } else { + self.cargo_add( + "cortex-m", + Some(if softdevice.is_some() { + &["inline-asm"] + } else { + &["inline-asm", "critical-section-single-core"] + }), + false, + )?; + self.cargo_add("cortex-m-rt", None, false)?; + self.cargo_add("defmt", None, true)?; + self.cargo_add("defmt-rtt", None, true)?; + self.cargo_add("panic-probe", Some(&["print-defmt"]), true)?; + self.cargo_add(panic_handler.str(), None, false)?; + + let mut file = fs::OpenOptions::new() + .read(true) + .append(true) + .open("Cargo.toml") .map_err(|_| Error::CreateFile("Cargo.toml".into()))?; - } - file.write_all( - if softdevice.is_some() { - include_str!("templates/Cargo.toml.sd.append").into() - } else { - format!( - include_str!("templates/Cargo.toml.append"), - family = chip.family + // really gross patch for cargo version discontinuity + // somewhere between cargo 1.72 and 1.76 the behavior of "cargo add" changed + let mut buf = String::new(); + file.read_to_string(&mut buf).unwrap(); + if !buf.contains("[features]") { + file.write_all( + include_str!("templates/Cargo.toml.feature-patch.template").as_bytes(), ) + .map_err(|_| Error::CreateFile("Cargo.toml".into()))?; } - .as_bytes(), - ) - .map_err(|_| Error::CreateFile("Cargo.toml".into()))?; + + file.write_all( + if softdevice.is_some() { + include_str!("templates/Cargo.toml.sd.append").into() + } else { + format!( + include_str!("templates/Cargo.toml.append"), + family = chip.family + ) + } + .as_bytes(), + ) + .map_err(|_| Error::CreateFile("Cargo.toml".into()))?; + } Ok(()) } @@ -256,8 +308,8 @@ impl Init { self.create_file( "src/main.rs", &match (family, softdevice) { - (Family::STM32, _) => format!( - include_str!("templates/main.rs.stm32.template"), + (Family::STM, _) => format!( + include_str!("templates/main.rs.stm.template"), panic_handler = panic_handler ), (Family::NRF(_), Some(_)) => { @@ -272,6 +324,7 @@ impl Init { panic_handler = panic_handler ) } + (Family::ESP(_), _) => include_str!("templates/main.rs.esp.template").into(), }, ) } diff --git a/src/templates/build.rs.esp.template b/src/templates/build.rs.esp.template new file mode 100644 index 0000000..5efe9c9 --- /dev/null +++ b/src/templates/build.rs.esp.template @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-link-arg-bins=-Tlinkall.x"); +} diff --git a/src/templates/build.rs.stm32.template b/src/templates/build.rs.stm.template similarity index 100% rename from src/templates/build.rs.stm32.template rename to src/templates/build.rs.stm.template diff --git a/src/templates/config.toml.esp.template b/src/templates/config.toml.esp.template new file mode 100644 index 0000000..f0fbd45 --- /dev/null +++ b/src/templates/config.toml.esp.template @@ -0,0 +1,16 @@ +# This file was automatically generated. + +[target.{target}] +runner = "espflash flash --monitor" + + +[env] +ESP_LOGLEVEL="INFO" + +[build] +{rustflags} + +target = "{target}" + +[unstable] +build-std = ["core"] diff --git a/src/templates/main.rs.esp.template b/src/templates/main.rs.esp.template new file mode 100644 index 0000000..d3cef71 --- /dev/null +++ b/src/templates/main.rs.esp.template @@ -0,0 +1,37 @@ +#![no_std] +#![no_main] + +use embassy_executor::Spawner; +use embassy_time::Timer; +use esp_backtrace as _; +use esp_hal::{ + clock::ClockControl, + gpio::{Io, Level, Output}, + peripherals::Peripherals, + prelude::*, + system::SystemControl, + timer::timg::TimerGroup, +}; +use esp_println::println; + +#[main] +async fn main(_spawner: Spawner) { + let peripherals = Peripherals::take(); + let system = SystemControl::new(peripherals.SYSTEM); + + let clocks = ClockControl::max(system.clock_control).freeze(); + + esp_println::logger::init_logger_from_env(); + + let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); + esp_hal_embassy::init(&clocks, timg0); + let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); + + let mut led = Output::new(io.pins.gpio21, Level::Low); + + loop { + println!("Hello, World!"); + led.toggle(); + Timer::after_millis(1_000).await; + } +} diff --git a/src/templates/main.rs.stm32.template b/src/templates/main.rs.stm.template similarity index 100% rename from src/templates/main.rs.stm32.template rename to src/templates/main.rs.stm.template diff --git a/src/templates/rust-toolchain.toml.esp.template b/src/templates/rust-toolchain.toml.esp.template new file mode 100644 index 0000000..2158949 --- /dev/null +++ b/src/templates/rust-toolchain.toml.esp.template @@ -0,0 +1,4 @@ +# This file was automatically generated. + +[toolchain] +channel = "esp" From 799232faac989f710da6e89332b817bd50f07f2a Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Sat, 13 Jul 2024 16:40:25 -0700 Subject: [PATCH 2/5] update ci to install esp toolchain --- ci.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci.sh b/ci.sh index 0c9b38e..9b3eb2b 100755 --- a/ci.sh +++ b/ci.sh @@ -31,6 +31,11 @@ $cwd/target/release/cargo-embassy embassy init test-nrf52832 --chip nrf52832-xxa $cwd/target/release/cargo-embassy embassy init test-esp32c3 --chip esp32c3 $cwd/target/release/cargo-embassy embassy init test-esp32s3 --chip esp32s3 +# esp toolchain +cargo install espup +espup install +. $HOME/export-esp.sh + # compile cd test-stm32g0; cargo build; cargo build --no-default-features --release cd ../test-stm32g4; cargo build; cargo build --no-default-features --release From dd9b9fe23a0b7a7906c394b526b143a867bc13bd Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Tue, 30 Jul 2024 13:07:15 -0700 Subject: [PATCH 3/5] update for esp's breaking changes --- .github/workflows/rust.yml | 2 +- ci.sh | 9 +++++++-- src/init.rs | 13 +++++++++--- src/templates/fmt.rs.template | 23 +++++----------------- src/templates/main.rs.esp.template | 16 +++++++++++---- src/templates/rust-toolchain.toml.template | 8 +++----- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bd8f9a0..eb44885 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,4 +18,4 @@ jobs: - name: Install Deps run: sudo apt -y install libudev-dev - name: ci - run: ./ci.sh + run: ./ci.sh --install-esp diff --git a/ci.sh b/ci.sh index 9b3eb2b..797514e 100755 --- a/ci.sh +++ b/ci.sh @@ -32,8 +32,13 @@ $cwd/target/release/cargo-embassy embassy init test-esp32c3 --chip esp32c3 $cwd/target/release/cargo-embassy embassy init test-esp32s3 --chip esp32s3 # esp toolchain -cargo install espup -espup install +if [ "${1-""}" = "--install-esp" ]; then + cargo install espup + espup install +else + echo "Skipping ESP toolchain installation." +fi + . $HOME/export-esp.sh # compile diff --git a/src/init.rs b/src/init.rs index e66cb2e..2dc463e 100644 --- a/src/init.rs +++ b/src/init.rs @@ -54,7 +54,9 @@ impl Init { self.init_config(&chip, &probe_target_name)?; self.init_toolchain(&chip)?; - self.init_embed(&probe_target_name)?; + if !matches!(&chip.family, Family::ESP(_)) { + self.init_embed(&probe_target_name)?; + } self.init_build(&chip.family)?; self.init_manifest( &args.name, @@ -180,7 +182,7 @@ impl Init { self.cargo_add( "embassy-time", match &chip.family { - Family::ESP(_) => Some(&["generic-queue-8"]), + Family::ESP(_) => None, _ => Some(&["tick-hz-32_768"]), }, false, @@ -217,9 +219,14 @@ impl Init { false, )?; self.cargo_add("esp-hal", Some(&[&name]), false)?; - self.cargo_add("esp-hal-embassy", Some(&[&name, "time-timg0"]), false)?; + self.cargo_add( + "esp-hal-embassy", + Some(&[&name, "integrated-timers"]), + false, + )?; self.cargo_add("esp-println", Some(&[&name, "log"]), false)?; self.cargo_add("log", None, false)?; + self.cargo_add("static_cell", None, false)?; } }; diff --git a/src/templates/fmt.rs.template b/src/templates/fmt.rs.template index 55994c1..5000f59 100644 --- a/src/templates/fmt.rs.template +++ b/src/templates/fmt.rs.template @@ -1,8 +1,5 @@ #![allow(unused)] -#[cfg(all(feature = "defmt", feature = "log"))] -compile_error!("You may not enable both `defmt` and `log` features."); - macro_rules! assert { ($($x:tt)*) => { { @@ -108,11 +105,9 @@ macro_rules! panic { macro_rules! trace { ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(feature = "log")] - ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] ::defmt::trace!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] + #[cfg(feature="defmt")] let _ = ($( & $x ),*); } }; @@ -121,11 +116,9 @@ macro_rules! trace { macro_rules! debug { ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(feature = "log")] - ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] ::defmt::debug!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] + #[cfg(not(eature="defmt"))] let _ = ($( & $x ),*); } }; @@ -134,11 +127,9 @@ macro_rules! debug { macro_rules! info { ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(feature = "log")] - ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] ::defmt::info!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] + #[cfg(not(feature="defmt"))] let _ = ($( & $x ),*); } }; @@ -147,11 +138,9 @@ macro_rules! info { macro_rules! _warn { ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(feature = "log")] - ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] ::defmt::warn!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] + #[cfg(not(feature="defmt"))] let _ = ($( & $x ),*); } }; @@ -160,11 +149,9 @@ macro_rules! _warn { macro_rules! error { ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(feature = "log")] - ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] ::defmt::error!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] + #[cfg(not(feature="defmt"))] let _ = ($( & $x ),*); } }; diff --git a/src/templates/main.rs.esp.template b/src/templates/main.rs.esp.template index d3cef71..4114f53 100644 --- a/src/templates/main.rs.esp.template +++ b/src/templates/main.rs.esp.template @@ -10,9 +10,10 @@ use esp_hal::{ peripherals::Peripherals, prelude::*, system::SystemControl, - timer::timg::TimerGroup, + timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, }; use esp_println::println; +use static_cell::StaticCell; #[main] async fn main(_spawner: Spawner) { @@ -23,11 +24,18 @@ async fn main(_spawner: Spawner) { esp_println::logger::init_logger_from_env(); - let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks, None); + + let timer = { + static TIMER: StaticCell<[OneShotTimer; 1]> = StaticCell::new(); + + TIMER.init([OneShotTimer::new(timg0.timer0.into())]) + }; + + esp_hal_embassy::init(&clocks, timer); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = Output::new(io.pins.gpio21, Level::Low); + let mut led = Output::new(io.pins.gpio17, Level::Low); loop { println!("Hello, World!"); diff --git a/src/templates/rust-toolchain.toml.template b/src/templates/rust-toolchain.toml.template index 297852b..c338292 100644 --- a/src/templates/rust-toolchain.toml.template +++ b/src/templates/rust-toolchain.toml.template @@ -1,8 +1,6 @@ # This file was automatically generated. [toolchain] -channel = "1.77" -components = [ "rust-src", "rustfmt" ] -targets = [ - "{target}" -] +channel = "1.80" +components = ["rust-src", "rustfmt"] +targets = ["{target}"] From 0b5fa6471cbd1a7d5a3ca52b7fd88c6bf25043fc Mon Sep 17 00:00:00 2001 From: AdinAck Date: Tue, 30 Jul 2024 13:52:09 -0700 Subject: [PATCH 4/5] try older ubuntu version --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index eb44885..1bb2b36 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 From 79a5a5a47ba13f5e5a7bf023e1c33f81936cc421 Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Tue, 30 Jul 2024 14:10:46 -0700 Subject: [PATCH 5/5] remote ci for esp is impossible --- .github/workflows/rust.yml | 4 ++-- ci-esp.sh | 40 ++++++++++++++++++++++++++++++++++++++ ci.sh | 16 --------------- 3 files changed, 42 insertions(+), 18 deletions(-) create mode 100755 ci-esp.sh diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1bb2b36..bd8f9a0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,11 +11,11 @@ env: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install Deps run: sudo apt -y install libudev-dev - name: ci - run: ./ci.sh --install-esp + run: ./ci.sh diff --git a/ci-esp.sh b/ci-esp.sh new file mode 100755 index 0000000..4b62fd9 --- /dev/null +++ b/ci-esp.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -euxo pipefail + +# build cargo-embassy +cargo build --release + +test_dir="/tmp/ci" + +# create test directory +if [ -d $test_dir ]; then + rm -r $test_dir +fi + +cwd=`pwd` + +mkdir $test_dir +cd $test_dir + +# generation +$cwd/target/release/cargo-embassy embassy init test-esp32c3 --chip esp32c3 +$cwd/target/release/cargo-embassy embassy init test-esp32s3 --chip esp32s3 + +# esp toolchain +if [ "${1-""}" = "--install-esp" ]; then + cargo install espup + espup install +else + echo "Skipping ESP toolchain installation." +fi + +. $HOME/export-esp.sh + +# compile +cd ../test-esp32c3; cargo build --release +cd ../test-esp32s3; cargo build --release + +# clean up +cd ../.. +# rm -r ci diff --git a/ci.sh b/ci.sh index 797514e..742c3d1 100755 --- a/ci.sh +++ b/ci.sh @@ -27,27 +27,11 @@ $cwd/target/release/cargo-embassy embassy init test-stm32g4 --chip stm32g431rb - $cwd/target/release/cargo-embassy embassy init test-nrf52840 --chip nrf52840 $cwd/target/release/cargo-embassy embassy init test-nrf52832 --chip nrf52832-xxab --softdevice s132 -# esp32 -$cwd/target/release/cargo-embassy embassy init test-esp32c3 --chip esp32c3 -$cwd/target/release/cargo-embassy embassy init test-esp32s3 --chip esp32s3 - -# esp toolchain -if [ "${1-""}" = "--install-esp" ]; then - cargo install espup - espup install -else - echo "Skipping ESP toolchain installation." -fi - -. $HOME/export-esp.sh - # compile cd test-stm32g0; cargo build; cargo build --no-default-features --release cd ../test-stm32g4; cargo build; cargo build --no-default-features --release cd ../test-nrf52840; cargo build; cargo build --no-default-features --release cd ../test-nrf52832; cargo build; cargo build --no-default-features --release -cd ../test-esp32c3; cargo build --release -cd ../test-esp32s3; cargo build --release # clean up cd ../..