From 5365031d9d636525e2cea3b81acb2586a827a7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 28 Sep 2023 09:47:44 +0200 Subject: [PATCH] Support SysTimer as timebase on ESP32-S2 --- .github/workflows/ci.yml | 12 ++++++++++++ CHANGELOG.md | 1 + esp-hal-common/Cargo.toml | 2 +- esp32-hal/Cargo.toml | 2 +- esp32c2-hal/Cargo.toml | 2 +- esp32c3-hal/Cargo.toml | 2 +- esp32c6-hal/Cargo.toml | 2 +- esp32h2-hal/Cargo.toml | 2 +- esp32s2-hal/Cargo.toml | 7 ++----- esp32s2-hal/examples/embassy_hello_world.rs | 6 ++++++ esp32s2-hal/examples/embassy_i2c.rs | 6 ++++++ esp32s2-hal/examples/embassy_i2s_read.rs | 14 +++++++++++--- esp32s2-hal/examples/embassy_i2s_sound.rs | 14 +++++++++++--- esp32s2-hal/examples/embassy_multiprio.rs | 6 ++++++ esp32s2-hal/examples/embassy_rmt_rx.rs | 6 ++++++ esp32s2-hal/examples/embassy_rmt_tx.rs | 6 ++++++ esp32s2-hal/examples/embassy_serial.rs | 6 ++++++ esp32s2-hal/examples/embassy_spi.rs | 6 ++++++ esp32s2-hal/examples/embassy_wait.rs | 6 ++++++ esp32s2-hal/src/lib.rs | 2 ++ esp32s3-hal/Cargo.toml | 2 +- 21 files changed, 94 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 856f3cd2072..ed6731e0872 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -409,6 +409,11 @@ jobs: cd esp32s2-hal/ cargo +esp check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread cargo +esp check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-interrupt + - name: check esp32s2-hal (embassy, systick) + run: | + cd esp32s2-hal/ + cargo +esp check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread + cargo +esp check --example=embassy_multiprio --features=embassy,embassy-time-systick,embassy-executor-interrupt - name: check esp32s2-hal (embassy, timg0, async) run: | cd esp32s2-hal/ @@ -420,6 +425,13 @@ jobs: cargo +esp check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread cargo +esp check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread --release cargo +esp check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread + - name: check esp32s2-hal (embassy, systick, async) + run: | + cd esp32s2-hal/ + cargo +esp check --example=embassy_wait --features=embassy,embassy-time-systick,async,embassy-executor-thread + cargo +esp check --example=embassy_spi --features=embassy,embassy-time-systick,async,embassy-executor-thread + cargo +esp check --example=embassy_serial --features=embassy,embassy-time-systick,async,embassy-executor-thread + cargo +esp check --example=embassy_i2c --features=embassy,embassy-time-systick,async,embassy-executor-thread - name: check esp32s2-hal (embassy, log/defmt) run: | cd esp32s2-hal/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 1711a307208..ee9c670363f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added `embassy-time-systick` to ESP32-S2 (#827) - Implement enabling/disabling BLE clock on ESP32-C6 (#784) - Async support for RMT (#787) - Implement `defmt::Format` for more types (#786) diff --git a/esp-hal-common/Cargo.toml b/esp-hal-common/Cargo.toml index ae22eb40f2a..f9e2b44e531 100644 --- a/esp-hal-common/Cargo.toml +++ b/esp-hal-common/Cargo.toml @@ -38,7 +38,7 @@ embedded-hal-async = { version = "=1.0.0-rc.1", optional = true } embedded-io-async = { version = "0.5.0", optional = true } embassy-executor = { version = "0.3.0", features = ["integrated-timers"], optional = true } embassy-sync = { version = "0.3.0", optional = true } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } embassy-futures = { version = "0.1.0", optional = true } # RISC-V diff --git a/esp32-hal/Cargo.toml b/esp32-hal/Cargo.toml index e7473b232a4..ccf46808da2 100644 --- a/esp32-hal/Cargo.toml +++ b/esp32-hal/Cargo.toml @@ -26,7 +26,7 @@ categories = [ [dependencies] esp-hal-common = { version = "0.12.0", features = ["esp32"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } [dev-dependencies] aes = "0.8.3" diff --git a/esp32c2-hal/Cargo.toml b/esp32c2-hal/Cargo.toml index 091af66d2b6..7f231b4e5d1 100644 --- a/esp32c2-hal/Cargo.toml +++ b/esp32c2-hal/Cargo.toml @@ -26,7 +26,7 @@ categories = [ [dependencies] esp-hal-common = { version = "0.12.0", features = ["esp32c2"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } [dev-dependencies] critical-section = "1.1.2" diff --git a/esp32c3-hal/Cargo.toml b/esp32c3-hal/Cargo.toml index 9823fa897f1..8afcc082594 100644 --- a/esp32c3-hal/Cargo.toml +++ b/esp32c3-hal/Cargo.toml @@ -27,7 +27,7 @@ categories = [ [dependencies] cfg-if = "1.0.0" esp-hal-common = { version = "0.12.0", features = ["esp32c3"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } [dev-dependencies] aes = "0.8.3" diff --git a/esp32c6-hal/Cargo.toml b/esp32c6-hal/Cargo.toml index 97b2326ba95..51a391bd94d 100644 --- a/esp32c6-hal/Cargo.toml +++ b/esp32c6-hal/Cargo.toml @@ -27,7 +27,7 @@ categories = [ [dependencies] esp-hal-common = { version = "0.12.0", features = ["esp32c6"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } [dev-dependencies] aes = "0.8.3" diff --git a/esp32h2-hal/Cargo.toml b/esp32h2-hal/Cargo.toml index 811a92ff159..42dc5ab8de9 100644 --- a/esp32h2-hal/Cargo.toml +++ b/esp32h2-hal/Cargo.toml @@ -27,7 +27,7 @@ categories = [ [dependencies] esp-hal-common = { version = "0.12.0", features = ["esp32h2"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } [dev-dependencies] aes = "0.8.3" diff --git a/esp32s2-hal/Cargo.toml b/esp32s2-hal/Cargo.toml index 56de462b057..db9172fbeee 100644 --- a/esp32s2-hal/Cargo.toml +++ b/esp32s2-hal/Cargo.toml @@ -26,7 +26,7 @@ categories = [ [dependencies] esp-hal-common = { version = "0.12.0", features = ["esp32s2"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } xtensa-atomic-emulation-trap = "0.4.0" [dev-dependencies] @@ -66,10 +66,7 @@ vectored = ["esp-hal-common/vectored"] # Embassy support embassy = ["esp-hal-common/embassy"] -# FIXME: -# - add 80_000_000 support to embassy time -# - Fix https://github.com/esp-rs/esp-hal/issues/253 -# embassy-time-systick = ["esp-hal-common/embassy-time-systick", "embassy-time/tick-hz-1_000_000"] +embassy-time-systick = ["esp-hal-common/embassy-time-systick", "embassy-time/tick-hz-80_000_000"] embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"] embassy-executor-interrupt = ["esp-hal-common/embassy-executor-interrupt"] embassy-executor-thread = ["esp-hal-common/embassy-executor-thread"] diff --git a/esp32s2-hal/examples/embassy_hello_world.rs b/esp32s2-hal/examples/embassy_hello_world.rs index ba3fad4e3fd..2b1a0a92637 100644 --- a/esp32s2-hal/examples/embassy_hello_world.rs +++ b/esp32s2-hal/examples/embassy_hello_world.rs @@ -33,6 +33,12 @@ async fn main(spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_i2c.rs b/esp32s2-hal/examples/embassy_i2c.rs index 92e0225d0ba..d4b21991125 100644 --- a/esp32s2-hal/examples/embassy_i2c.rs +++ b/esp32s2-hal/examples/embassy_i2c.rs @@ -34,6 +34,12 @@ async fn main(_spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_i2s_read.rs b/esp32s2-hal/examples/embassy_i2s_read.rs index 54041a74f64..c88aac22f37 100644 --- a/esp32s2-hal/examples/embassy_i2s_read.rs +++ b/esp32s2-hal/examples/embassy_i2s_read.rs @@ -23,7 +23,6 @@ use esp32s2_hal::{ pdma::Dma, peripherals::Peripherals, prelude::*, - timer::TimerGroup, IO, }; use esp_backtrace as _; @@ -38,8 +37,17 @@ async fn main(_spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0.timer0); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + + #[cfg(feature = "embassy-time-timg0")] + { + let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timer_group0.timer0); + } let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/esp32s2-hal/examples/embassy_i2s_sound.rs b/esp32s2-hal/examples/embassy_i2s_sound.rs index f0e1ff846b9..fd8dfdfff20 100644 --- a/esp32s2-hal/examples/embassy_i2s_sound.rs +++ b/esp32s2-hal/examples/embassy_i2s_sound.rs @@ -40,7 +40,6 @@ use esp32s2_hal::{ pdma::Dma, peripherals::Peripherals, prelude::*, - timer::TimerGroup, IO, }; use esp_backtrace as _; @@ -63,8 +62,17 @@ async fn main(_spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0.timer0); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + + #[cfg(feature = "embassy-time-timg0")] + { + let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timer_group0.timer0); + } let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/esp32s2-hal/examples/embassy_multiprio.rs b/esp32s2-hal/examples/embassy_multiprio.rs index 0e0d6e3e7b3..1e7d21f8ee8 100644 --- a/esp32s2-hal/examples/embassy_multiprio.rs +++ b/esp32s2-hal/examples/embassy_multiprio.rs @@ -87,6 +87,12 @@ fn main() -> ! { // Set GPIO2 as an output, and set its state high initially. let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_rmt_rx.rs b/esp32s2-hal/examples/embassy_rmt_rx.rs index b9687b34fc2..ab63a0f42f2 100644 --- a/esp32s2-hal/examples/embassy_rmt_rx.rs +++ b/esp32s2-hal/examples/embassy_rmt_rx.rs @@ -46,6 +46,12 @@ async fn main(spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_rmt_tx.rs b/esp32s2-hal/examples/embassy_rmt_tx.rs index 671591482cc..bf468d4addd 100644 --- a/esp32s2-hal/examples/embassy_rmt_tx.rs +++ b/esp32s2-hal/examples/embassy_rmt_tx.rs @@ -29,6 +29,12 @@ async fn main(_spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_serial.rs b/esp32s2-hal/examples/embassy_serial.rs index fbc0a7df6af..e543f6fae91 100644 --- a/esp32s2-hal/examples/embassy_serial.rs +++ b/esp32s2-hal/examples/embassy_serial.rs @@ -67,6 +67,12 @@ async fn main(spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_spi.rs b/esp32s2-hal/examples/embassy_spi.rs index 4244477cff7..8feb8a3fe29 100644 --- a/esp32s2-hal/examples/embassy_spi.rs +++ b/esp32s2-hal/examples/embassy_spi.rs @@ -39,6 +39,12 @@ async fn main(_spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/examples/embassy_wait.rs b/esp32s2-hal/examples/embassy_wait.rs index 6d5ec439e4e..3df5afe42b1 100644 --- a/esp32s2-hal/examples/embassy_wait.rs +++ b/esp32s2-hal/examples/embassy_wait.rs @@ -25,6 +25,12 @@ async fn main(_spawner: Spawner) -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + #[cfg(feature = "embassy-time-systick")] + embassy::init( + &clocks, + esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); + #[cfg(feature = "embassy-time-timg0")] { let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); diff --git a/esp32s2-hal/src/lib.rs b/esp32s2-hal/src/lib.rs index ccf49383594..dbf895b3217 100644 --- a/esp32s2-hal/src/lib.rs +++ b/esp32s2-hal/src/lib.rs @@ -18,6 +18,8 @@ //! using this feature. //! - `embassy-executor-interrupt` - Use the interrupt-mode embassy executor //! - `embassy-executor-thread` - Use the thread-mode embassy executor +//! - `embassy-time-systick` - Enable the [embassy] time driver using the +//! `SYSTIMER` peripheral //! - `embassy-time-timg0` - Enable the [embassy] time driver using the `TIMG0` //! peripheral //! - `log` - enable log output using the `log` crate diff --git a/esp32s3-hal/Cargo.toml b/esp32s3-hal/Cargo.toml index 6a25d270068..66b00b874d3 100644 --- a/esp32s3-hal/Cargo.toml +++ b/esp32s3-hal/Cargo.toml @@ -26,7 +26,7 @@ categories = [ [dependencies] esp-hal-common = { version = "0.12.0", features = ["esp32s3"], path = "../esp-hal-common" } -embassy-time = { version = "0.1.3", features = ["nightly"], optional = true } +embassy-time = { version = "0.1.4", features = ["nightly"], optional = true } r0 = { version = "1.0.0", optional = true } [dev-dependencies]