diff --git a/.vscode/settings.json b/.vscode/settings.json index 1ac3fc51..d6ce75c9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,7 @@ { "editor.formatOnSave": true, - "rust-analyzer.checkOnSave.allFeatures": false, "rust-analyzer.checkOnSave.allTargets": false, "rust-analyzer.checkOnSave.noDefaultFeatures": true, - "rust-analyzer.cargo.allFeatures": false, "rust-analyzer.cargo.noDefaultFeatures": true, "rust-analyzer.procMacro.enable": true, "rust-analyzer.cargo.target": "thumbv7em-none-eabi", diff --git a/README.md b/README.md index 42374067..4dbbb5f5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Rust's async/await allows - embassy-nrf, for the Nordic Semiconductor nRF52, nRF53, nRF91 series. - **Time that Just Works** - -No more messing with hardware timers. embassy_executor::time provides Instant, Duration and Timer types that are globally available and never overflow. +No more messing with hardware timers. embassy_time provides Instant, Duration and Timer types that are globally available and never overflow. - **Real-time ready** - Tasks on the same async executor run cooperatively, but you can create multiple executors with different priorities, so that higher priority tasks preempt lower priority ones. See the example. @@ -44,8 +44,8 @@ The nrf-softdevice cr ```rust,ignore use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull}; use embassy_nrf::Peripherals; @@ -65,7 +65,9 @@ async fn blink(pin: AnyPin) { // Main is itself an async task as well. #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + // Spawned tasks run in the background, concurrently. spawner.spawn(blink(p.P0_13.degrade())).unwrap(); diff --git a/ci.sh b/ci.sh index 6ec2410f..77a8a7e2 100755 --- a/ci.sh +++ b/ci.sh @@ -54,25 +54,25 @@ cargo batch \ --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits,log \ --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits \ --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wb15cc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l072cz,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l041f6,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32l151cb-a,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f398ve,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32g0c1ve,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5ub,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wb15cc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l072cz,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l041f6,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32l151cb-a,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f398ve,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32g0c1ve,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5ub,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ --- build --release --manifest-path embassy-boot/nrf/Cargo.toml --target thumbv7em-none-eabi --features embassy-nrf/nrf52840 \ --- build --release --manifest-path embassy-boot/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \ --- build --release --manifest-path docs/modules/ROOT/examples/basic/Cargo.toml --target thumbv7em-none-eabi \ diff --git a/ci_stable.sh b/ci_stable.sh index 7521827d..d388cfee 100755 --- a/ci_stable.sh +++ b/ci_stable.sh @@ -30,38 +30,38 @@ cargo batch \ --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features unstable-traits,defmt \ --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features unstable-traits,log \ --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55uc-cm4,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz \ - --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-executor/time-tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55uc-cm4,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz \ + --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,embassy-time?/tick-32768hz,unstable-traits \ --- build --release --manifest-path examples/nrf/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf --bin raw_spawn \ --- build --release --manifest-path examples/stm32l0/Cargo.toml --target thumbv6m-none-eabi --no-default-features --out-dir out/examples/stm32l0 --bin raw_spawn \ diff --git a/docs/antora.yml b/docs/antora.yml index 807c97c3..9a00fa82 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -1,4 +1,4 @@ -name: embassy +name: ROOT title: Embassy version: dev nav: diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml index 59e1a437..ae124a87 100644 --- a/docs/modules/ROOT/examples/basic/Cargo.toml +++ b/docs/modules/ROOT/examples/basic/Cargo.toml @@ -6,6 +6,7 @@ version = "0.1.0" [dependencies] embassy-executor = { version = "0.1.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly"] } +embassy-time = { version = "0.1.0", path = "../../../../../embassy-time", features = ["defmt", "nightly"] } embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] } defmt = "0.3" diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs index cec39fd9..04170db5 100644 --- a/docs/modules/ROOT/examples/basic/src/main.rs +++ b/docs/modules/ROOT/examples/basic/src/main.rs @@ -3,11 +3,10 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; use embassy_nrf::peripherals::P0_13; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; // global logger #[embassy_executor::task] @@ -21,7 +20,9 @@ async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) { } #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); + let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300)))); } diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index b944a799..8df63224 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs @@ -2,14 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_s: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); let mut button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13); diff --git a/docs/modules/ROOT/images/bootloader_flash.png b/docs/modules/ROOT/images/bootloader_flash.png new file mode 100644 index 00000000..635783b0 Binary files /dev/null and b/docs/modules/ROOT/images/bootloader_flash.png differ diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index a45da195..86f2996f 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -1,10 +1,10 @@ -* xref:runtime.adoc[Runtime] -* xref:traits.adoc[APIs] -* xref:hal.adoc[Hardware Abstraction Layer] -** xref:nrf.adoc[nRF] -** xref:stm32.adoc[STM32] -* xref:bootloader.adoc[Bootloader] * xref:getting_started.adoc[Getting started] ** xref:basic_application.adoc[Basic application] ** xref:layer_by_layer.adoc[Layer by Layer] +* xref:runtime.adoc[Executor] +* xref:hal.adoc[HAL] +** xref:nrf.adoc[nRF] +** xref:stm32.adoc[STM32] +* xref:bootloader.adoc[Bootloader] + * xref:examples.adoc[Examples] diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/modules/ROOT/pages/basic_application.adoc index a8875aa9..4dc4a635 100644 --- a/docs/modules/ROOT/pages/basic_application.adoc +++ b/docs/modules/ROOT/pages/basic_application.adoc @@ -21,7 +21,7 @@ Then, what follows are some declarations on how to deal with panics and faults. [source,rust] ---- -include::example$basic/src/main.rs[lines="5..6"] +include::example$basic/src/main.rs[lines="11..12"] ---- === Task declaration @@ -30,7 +30,7 @@ After a bit of import declaration, the tasks run by the application should be de [source,rust] ---- -include::example$basic/src/main.rs[lines="18..27"] +include::example$basic/src/main.rs[lines="13..22"] ---- An embassy task must be declared `async`, and may NOT take generic arguments. In this case, we are handed the LED that should be blinked and the interval of the blinking. @@ -39,32 +39,32 @@ NOTE: Notice that there is no busy waiting going on in this task. It is using th === Main -The main entry point of an Embassy application is defined using the `#[embassy::main]` macro. The entry point is also required to take a `Spawner` and a `Peripherals` argument. +The main entry point of an Embassy application is defined using the `#[embassy_executor::main]` macro. The entry point is also required to take a `Spawner` and a `Peripherals` argument. -The `Spawner` is the way the main application spawns other tasks. The `Peripherals` type holds all peripherals that the application may use. In this case, we want to configure one of the pins as a GPIO output driving the LED: +The `Spawner` is the way the main application spawns other tasks. The `Peripherals` type comes from the HAL and holds all peripherals that the application may use. In this case, we want to configure one of the pins as a GPIO output driving the LED: [source,rust] ---- -include::example$basic/src/main.rs[lines="28..-1"] +include::example$basic/src/main.rs[lines="23..-1"] ---- -`#[embassy::main]` takes an optional `config` paramter specifying a function that returns an instance of HAL's `Config` struct. For example: +`#[embassy_executor::main]` takes an optional `config` parameter specifying a function that returns an instance of HAL's `Config` struct. For example: ```rust fn embassy_config() -> embassy_nrf::config::Config { embassy_nrf::config::Config::default() } -#[embassy::main(config = "embassy_config()")] -async fn main(_spawner: embassy::executor::Spawner, p: embassy_nrf::Peripherals) { +#[embassy_executor::main(config = "embassy_config()")] +async fn main(_spawner: Spawner, p: embassy_nrf::Peripherals) { // ... } ``` What happens when the `blinker` task have been spawned and main returns? Well, the main entry point is actually just like any other task, except that you can only have one and it takes some specific type arguments. The magic lies within the `#[embassy::main]` macro. The macro does the following: -. Creates an Embassy Executor instance -. Initializes the microcontroller to get the `Peripherals` +. Creates an Embassy Executor +. Initializes the microcontroller HAL to get the `Peripherals` . Defines a main task for the entry point . Runs the executor spawning the main task diff --git a/docs/modules/ROOT/pages/bootloader.adoc b/docs/modules/ROOT/pages/bootloader.adoc index 3df2daf5..ae92e9d5 100644 --- a/docs/modules/ROOT/pages/bootloader.adoc +++ b/docs/modules/ROOT/pages/bootloader.adoc @@ -20,7 +20,10 @@ In general, the bootloader works on any platform that implements the `embedded-s == Design -The bootloader divides the storage into 4 main partitions, configured by a linker script: +image::bootloader_flash.png[Bootloader flash layout] + +The bootloader divides the storage into 4 main partitions, configurable when creating the bootloader +instance or via linker scripts: * BOOTLOADER - Where the bootloader is placed. The bootloader itself consumes about 8kB of flash. * ACTIVE - Where the main application is placed. The bootloader will attempt to load the application at the start of this partition. This partition is only written to by the bootloader. diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc index 23102b3b..f3492a3d 100644 --- a/docs/modules/ROOT/pages/getting_started.adoc +++ b/docs/modules/ROOT/pages/getting_started.adoc @@ -46,15 +46,13 @@ You can run an example by opening a terminal and entering the following commands [source, bash] ---- cd examples/nrf -DEFMT_LOG=info cargo run --bin blinky --release +cargo run --bin blinky --release ---- -IMPORTANT: The DEFMT_LOG environment variable controls the example log verbosity. If you do not specify it, you will not see anything logged to the console. - == Whats next? Congratulations, you have your first Embassy application running! Here are some alternatives on where to go from here: -* Read more about the xref:runtime.adoc[runtime]. +* Read more about the xref:runtime.adoc[executor]. * Read more about the xref:hal.adoc[HAL]. * Start xref:basic_application.adoc[writing your application]. diff --git a/docs/modules/ROOT/pages/hal.adoc b/docs/modules/ROOT/pages/hal.adoc index 0b15e2fc..de4ab33b 100644 --- a/docs/modules/ROOT/pages/hal.adoc +++ b/docs/modules/ROOT/pages/hal.adoc @@ -1,9 +1,10 @@ = Hardware Abstraction Layer (HAL) -Embassy provides HAL's for several microcontroller families: +Embassy provides HALs for several microcontroller families: * `embassy-nrf` for the nRF microcontrollers from Nordic Semiconductor * `embassy-stm32` for STM32 microcontrollers from ST Microelectronics * `embassy-rp` for the Raspberry Pi RP2040 microcontrollers -These HALs implement async/await functionality for most peripherals while also implementing the async traits in Embassy. +These HALs implement async/await functionality for most peripherals while also implementing the +async traits in `embedded-hal-async`. You can also use these HALs with another executor. diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 9a14e465..0a17c673 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -15,6 +15,20 @@ In Rust, non-blocking operations can be implemented using async-await. Async-awa == What is Embassy? -Embassy is an executor and a Hardware Access Layer (HAL). The executor is a scheduler that generally executes a fixed number of tasks, allocated at startup, though more can be added later. The HAL is an API that you can use to access peripherals, such as USART, UART, I2C, SPI, CAN, and USB. Embassy provides implementations of both async and blocking APIs where it makes sense. DMA (Direct Memory Access) is an example where async is a good fit, whereas GPIO states are a better fit for a blocking API. +The Embassy project consists of several crates that you can use together or independently: -Embassy may also provide a system timer that you can use for both async and blocking delays. For less than one microsecond, blocking delays should be used because the cost of context-switching is too high and the executor will be unable to provide accurate timing. +* **Executor** - The link:https://docs.embassy.dev/embassy-executor/[embassy-executor] is an async/await executor that generally executes a fixed number of tasks, allocated at startup, though more can be added later. The HAL is an API that you can use to access peripherals, such as USART, UART, I2C, SPI, CAN, and USB. Embassy provides implementations of both async and blocking APIs where it makes sense. DMA (Direct Memory Access) is an example where async is a good fit, whereas GPIO states are a better fit for a blocking API. The executor may also provide a system timer that you can use for both async and blocking delays. For less than one microsecond, blocking delays should be used because the cost of context-switching is too high and the executor will be unable to provide accurate timing. + +* **Hardware Abstraction Layers** - HALs implement safe, idiomatic Rust APIs to use the hardware capabilities, so raw register manipulation is not needed. The Embassy project maintains HALs for select hardware, but you can still use HALs from other projects with Embassy. +** link:https://docs.embassy.dev/embassy-stm32/[embassy-stm32], for all STM32 microcontroller families. +** link:https://docs.embassy.dev/embassy-nrf/[embassy-nrf], for the Nordic Semiconductor nRF52, nRF53, nRF91 series. + +* **Networking** - The link:https://docs.embassy.dev/embassy-net/[embassy-net] network stack implements extensive networking functionality, including Ethernet, IP, TCP, UDP, ICMP and DHCP. Async drastically simplifies managing timeouts and serving multiple connections concurrently. + +* **Bluetooth** - The link:https://github.com/embassy-rs/nrf-softdevice[nrf-softdevice] crate provides Bluetooth Low Energy 4.x and 5.x support for nRF52 microcontrollers. + +* **LoRa** - link:https://docs.embassy.dev/embassy-lora/[embassy-lora] supports LoRa networking on STM32WL wireless microcontrollers and Semtech SX127x transceivers. + +* **USB** - link:https://docs.embassy.dev/embassy-usb/[embassy-usb] implements a device-side USB stack. Implementations for common classes such as USB serial (CDC ACM) and USB HID are available, and a rich builder API allows building your own. + +* **Bootloader and DFU** - link:https://github.com/embassy-rs/embassy/tree/master/embassy-boot[embassy-boot] is a lightweight bootloader supporting firmware application upgrades in a power-fail-safe way, with trial boots and rollbacks. diff --git a/docs/modules/ROOT/pages/runtime.adoc b/docs/modules/ROOT/pages/runtime.adoc index 0adaa21a..a7d6a8d0 100644 --- a/docs/modules/ROOT/pages/runtime.adoc +++ b/docs/modules/ROOT/pages/runtime.adoc @@ -1,6 +1,6 @@ -= Embassy runtime += Embassy executor -The Embassy runtime is an async/await executor designed for embedded usage along with support functionality for interrupts and timers. +The Embassy executor is an async/await executor designed for embedded usage along with support functionality for interrupts and timers. == Features diff --git a/docs/modules/ROOT/pages/traits.adoc b/docs/modules/ROOT/pages/traits.adoc deleted file mode 100644 index 38b8f286..00000000 --- a/docs/modules/ROOT/pages/traits.adoc +++ /dev/null @@ -1,8 +0,0 @@ -= Embassy Traits - -Embassy provides a set of traits and types specifically designed for `async` usage. Many of these futures will be upstreamed to the `embedded-hal` crate at some point in the future, probably when the required GAT (Generic Associated Types) feature is stabilized in Rust. - -* `embassy::io`: `AsyncBufRead`, `AsyncWrite`. Traits for byte-stream IO, essentially `no_std` compatible versions of `futures::io`. The primary reason for re-defining these traits is that the `futures::io` variant requires `std::io::Error`, which does not work in the `no_std` environment. -* `embassy::time`: Time `Driver` trait that is implemented for different platforms. Time in Embassy is represented using the `Duration` and `Instant` types. - -These traits are implemented by the platform-specific crates, such as `embassy-nrf` or `embassy-stm32`. diff --git a/embassy-boot/boot/Cargo.toml b/embassy-boot/boot/Cargo.toml index abb7bb5c..9c2e72be 100644 --- a/embassy-boot/boot/Cargo.toml +++ b/embassy-boot/boot/Cargo.toml @@ -4,6 +4,11 @@ name = "embassy-boot" version = "0.1.0" description = "Bootloader using Embassy" +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-v$VERSION/embassy-boot/boot/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-boot/boot/src/" +target = "thumbv7em-none-eabi" + [lib] [dependencies] diff --git a/embassy-boot/nrf/Cargo.toml b/embassy-boot/nrf/Cargo.toml index 5dc3ce52..b06e8102 100644 --- a/embassy-boot/nrf/Cargo.toml +++ b/embassy-boot/nrf/Cargo.toml @@ -4,6 +4,12 @@ name = "embassy-boot-nrf" version = "0.1.0" description = "Bootloader lib for nRF chips" +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/nrf/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-boot/nrf/src/" +features = ["embassy-nrf/nrf52840"] +target = "thumbv7em-none-eabi" + [lib] [dependencies] @@ -12,7 +18,7 @@ defmt = { version = "0.3", optional = true } embassy-util = { path = "../../embassy-util" } embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] } embassy-boot = { path = "../boot", default-features = false } -cortex-m = { version = "0.7" } +cortex-m = { version = "0.7.6" } cortex-m-rt = { version = "0.7" } embedded-storage = "0.3.0" embedded-storage-async = "0.3.0" diff --git a/embassy-boot/stm32/Cargo.toml b/embassy-boot/stm32/Cargo.toml index eab8d160..d8f49253 100644 --- a/embassy-boot/stm32/Cargo.toml +++ b/embassy-boot/stm32/Cargo.toml @@ -4,6 +4,12 @@ name = "embassy-boot-stm32" version = "0.1.0" description = "Bootloader lib for STM32 chips" +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-boot-nrf-v$VERSION/embassy-boot/stm32/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-boot/stm32/src/" +features = ["embassy-stm32/stm32f429zi"] +target = "thumbv7em-none-eabi" + [lib] [dependencies] @@ -14,7 +20,7 @@ log = { version = "0.4", optional = true } embassy-util = { path = "../../embassy-util" } embassy-stm32 = { path = "../../embassy-stm32", default-features = false, features = ["nightly"] } embassy-boot = { path = "../boot", default-features = false } -cortex-m = { version = "0.7" } +cortex-m = { version = "0.7.6" } cortex-m-rt = { version = "0.7" } embedded-storage = "0.3.0" embedded-storage-async = "0.3.0" diff --git a/embassy-cortex-m/Cargo.toml b/embassy-cortex-m/Cargo.toml index 454f34e0..1f16da31 100644 --- a/embassy-cortex-m/Cargo.toml +++ b/embassy-cortex-m/Cargo.toml @@ -39,8 +39,8 @@ embassy-util = { version = "0.1.0", path = "../embassy-util" } embassy-executor = { version = "0.1.0", path = "../embassy-executor"} embassy-macros = { version = "0.1.0", path = "../embassy-macros"} embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"} -atomic-polyfill = "0.1.5" -critical-section = "0.2.5" +atomic-polyfill = "1.0.1" +critical-section = "1.1" cfg-if = "1.0.0" -cortex-m = "0.7.3" +cortex-m = "0.7.6" diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs index 4a3fa990..80c452f8 100644 --- a/embassy-cortex-m/src/executor.rs +++ b/embassy-cortex-m/src/executor.rs @@ -1,7 +1,7 @@ //! Executor specific to cortex-m devices. use core::marker::PhantomData; -pub use embassy_executor::executor::*; +pub use embassy_executor::*; use crate::interrupt::{Interrupt, InterruptExt}; @@ -60,11 +60,11 @@ impl InterruptExecutor { /// The executor keeps running in the background through the interrupt. /// /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`] - /// is returned instead of a [`Spawner`](embassy_executor::executor::Spawner) because the executor effectively runs in a + /// is returned instead of a [`Spawner`](embassy_executor::Spawner) because the executor effectively runs in a /// different "thread" (the interrupt), so spawning tasks on it is effectively /// sending them. /// - /// To obtain a [`Spawner`](embassy_executor::executor::Spawner) for this executor, use [`Spawner::for_current_executor()`](embassy_executor::executor::Spawner::for_current_executor()) from + /// To obtain a [`Spawner`](embassy_executor::Spawner) for this executor, use [`Spawner::for_current_executor()`](embassy_executor::Spawner::for_current_executor()) from /// a task running in it. /// /// This function requires `&'static mut self`. This means you have to store the diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index 7358caa4..1df8671b 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs @@ -6,6 +6,13 @@ use cortex_m::peripheral::NVIC; use embassy_hal_common::Peripheral; pub use embassy_macros::cortex_m_interrupt_take as take; +/// Do not use. Used for macros and HALs only. Not covered by semver guarantees. +#[doc(hidden)] +pub mod _export { + pub use atomic_polyfill as atomic; + pub use embassy_macros::{cortex_m_interrupt as interrupt, cortex_m_interrupt_declare as declare}; +} + /// Implementation detail, do not use outside embassy crates. #[doc(hidden)] pub struct Handler { diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index f245783c..86666687 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -3,6 +3,13 @@ name = "embassy-embedded-hal" version = "0.1.0" edition = "2021" + +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-embedded-hal-v$VERSION/embassy-embedded-hal/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-embedded-hal/src/" +features = ["nightly", "std"] +target = "thumbv7em-none-eabi" + [features] std = [] # Enable nightly-only features diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index ca00f2e7..7d5c4a04 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-executor-v$VERSION/embassy-executor/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-executor/src/" -features = ["nightly", "defmt", "unstable-traits", "time", "time-tick-1mhz"] +features = ["nightly", "defmt", "unstable-traits"] flavors = [ { name = "std", target = "x86_64-unknown-linux-gnu", features = ["std"] }, { name = "wasm", target = "wasm32-unknown-unknown", features = ["wasm"] }, @@ -22,33 +22,13 @@ flavors = [ [features] default = [] -std = ["time", "time-tick-1mhz", "embassy-macros/std"] -wasm = ["wasm-bindgen", "js-sys", "embassy-macros/wasm", "wasm-timer", "time", "time-tick-1mhz"] +std = ["embassy-macros/std"] +wasm = ["dep:wasm-bindgen", "dep:js-sys", "embassy-macros/wasm"] # Enable nightly-only features -nightly = ["embedded-hal-async"] +nightly = [] -# Implement embedded-hal 1.0 alpha and embedded-hal-async traits. -# Implement embedded-hal-async traits if `nightly` is set as well. -unstable-traits = ["embedded-hal-1"] - -# Display a timestamp of the number of seconds since startup next to defmt log messages -# To use this you must have a time driver provided. -defmt-timestamp-uptime = ["defmt"] - -# Enable `embassy_executor::time` module. -# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. -# Enabling it directly without supplying a time driver will fail to link. -time = [] - -# Set the `embassy_executor::time` tick rate. -# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. -# If you're not writing your own driver, check the driver documentation to customize the tick rate. -# If you're writing a driver and your tick rate is not listed here, please add it and send a PR! -time-tick-32768hz = ["time"] -time-tick-1000hz = ["time"] -time-tick-1mhz = ["time"] -time-tick-16mhz = ["time"] +integrated-timers = ["dep:embassy-time"] # Trace interrupt invocations with rtos-trace. rtos-trace-interrupt = ["rtos-trace"] @@ -58,17 +38,13 @@ defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } rtos-trace = { version = "0.1.2", optional = true } -embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } -embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true} -embedded-hal-async = { version = "0.1.0-alpha.1", optional = true} - futures-util = { version = "0.3.17", default-features = false } embassy-macros = { version = "0.1.0", path = "../embassy-macros"} -atomic-polyfill = "0.1.5" -critical-section = "0.2.5" +embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true} +atomic-polyfill = "1.0.1" +critical-section = "1.1" cfg-if = "1.0.0" # WASM dependencies wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } -js-sys = { version = "0.3", optional = true } -wasm-timer = { version = "0.2.5", optional = true } \ No newline at end of file +js-sys = { version = "0.3", optional = true } \ No newline at end of file diff --git a/embassy-executor/README.md b/embassy-executor/README.md new file mode 100644 index 00000000..47d0cb8a --- /dev/null +++ b/embassy-executor/README.md @@ -0,0 +1,11 @@ +# embassy-executor + +An async/await executor designed for embedded usage. + +- No `alloc`, no heap needed. Task futures are statically allocated. +- No "fixed capacity" data structures, executor works with 1 or 1000 tasks without needing config/tuning. +- Integrated timer queue: sleeping is easy, just do `Timer::after(Duration::from_secs(1)).await;`. +- No busy-loop polling: CPU sleeps when there's no work to do, using interrupts or `WFE/SEV`. +- Efficient polling: a wake will only poll the woken task, not all of them. +- Fair: a task can't monopolize CPU time even if it's constantly being woken. All other tasks get a chance to run before a given task gets polled for the second time. +- Creating multiple executor instances is supported, to run tasks with multiple priority levels. This allows higher-priority tasks to preempt lower-priority tasks. diff --git a/embassy-executor/src/executor/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs similarity index 100% rename from embassy-executor/src/executor/arch/cortex_m.rs rename to embassy-executor/src/arch/cortex_m.rs diff --git a/embassy-executor/src/executor/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs similarity index 100% rename from embassy-executor/src/executor/arch/riscv32.rs rename to embassy-executor/src/arch/riscv32.rs diff --git a/embassy-executor/src/executor/arch/std.rs b/embassy-executor/src/arch/std.rs similarity index 100% rename from embassy-executor/src/executor/arch/std.rs rename to embassy-executor/src/arch/std.rs diff --git a/embassy-executor/src/executor/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs similarity index 100% rename from embassy-executor/src/executor/arch/wasm.rs rename to embassy-executor/src/arch/wasm.rs diff --git a/embassy-executor/src/executor/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs similarity index 100% rename from embassy-executor/src/executor/arch/xtensa.rs rename to embassy-executor/src/arch/xtensa.rs diff --git a/embassy-executor/src/executor/mod.rs b/embassy-executor/src/executor/mod.rs deleted file mode 100644 index 45d00c56..00000000 --- a/embassy-executor/src/executor/mod.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Async task executor. -//! -//! This module provides an async/await executor designed for embedded usage. -//! -//! - No `alloc`, no heap needed. Task futures are statically allocated. -//! - No "fixed capacity" data structures, executor works with 1 or 1000 tasks without needing config/tuning. -//! - Integrated timer queue: sleeping is easy, just do `Timer::after(Duration::from_secs(1)).await;`. -//! - No busy-loop polling: CPU sleeps when there's no work to do, using interrupts or `WFE/SEV`. -//! - Efficient polling: a wake will only poll the woken task, not all of them. -//! - Fair: a task can't monopolize CPU time even if it's constantly being woken. All other tasks get a chance to run before a given task gets polled for the second time. -//! - Creating multiple executor instances is supported, to run tasks with multiple priority levels. This allows higher-priority tasks to preempt lower-priority tasks. - -cfg_if::cfg_if! { - if #[cfg(cortex_m)] { - #[path="arch/cortex_m.rs"] - mod arch; - pub use arch::*; - } - else if #[cfg(target_arch="riscv32")] { - #[path="arch/riscv32.rs"] - mod arch; - pub use arch::*; - } - else if #[cfg(all(target_arch="xtensa", feature = "nightly"))] { - #[path="arch/xtensa.rs"] - mod arch; - pub use arch::*; - } - else if #[cfg(feature="wasm")] { - #[path="arch/wasm.rs"] - mod arch; - pub use arch::*; - } - else if #[cfg(feature="std")] { - #[path="arch/std.rs"] - mod arch; - pub use arch::*; - } -} - -pub mod raw; - -mod spawner; -pub use spawner::*; diff --git a/embassy-executor/src/fmt.rs b/embassy-executor/src/fmt.rs index f8bb0a03..06697081 100644 --- a/embassy-executor/src/fmt.rs +++ b/embassy-executor/src/fmt.rs @@ -195,9 +195,6 @@ macro_rules! unwrap { } } -#[cfg(feature = "defmt-timestamp-uptime")] -defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() } - #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct NoneError; diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 47c0c1d6..93f2eaa6 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -1,24 +1,46 @@ #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] -#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] #![cfg_attr(all(feature = "nightly", target_arch = "xtensa"), feature(asm_experimental_arch))] #![allow(clippy::new_without_default)] -#![doc = include_str!("../../README.md")] +#![doc = include_str!("../README.md")] #![warn(missing_docs)] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; -pub mod executor; -#[cfg(feature = "time")] -pub mod time; - #[cfg(feature = "nightly")] pub use embassy_macros::{main, task}; +cfg_if::cfg_if! { + if #[cfg(cortex_m)] { + #[path="arch/cortex_m.rs"] + mod arch; + pub use arch::*; + } + else if #[cfg(target_arch="riscv32")] { + #[path="arch/riscv32.rs"] + mod arch; + pub use arch::*; + } + else if #[cfg(all(target_arch="xtensa", feature = "nightly"))] { + #[path="arch/xtensa.rs"] + mod arch; + pub use arch::*; + } + else if #[cfg(feature="wasm")] { + #[path="arch/wasm.rs"] + mod arch; + pub use arch::*; + } + else if #[cfg(feature="std")] { + #[path="arch/std.rs"] + mod arch; + pub use arch::*; + } +} + #[doc(hidden)] /// Implementation details for embassy macros. DO NOT USE. pub mod export { - pub use atomic_polyfill as atomic; #[cfg(feature = "rtos-trace")] pub use rtos_trace::trace; @@ -40,3 +62,8 @@ pub mod export { ($($tt:tt)*) => {}; } } + +pub mod raw; + +mod spawner; +pub use spawner::*; diff --git a/embassy-executor/src/executor/raw/mod.rs b/embassy-executor/src/raw/mod.rs similarity index 93% rename from embassy-executor/src/executor/raw/mod.rs rename to embassy-executor/src/raw/mod.rs index 56220d10..c55d1069 100644 --- a/embassy-executor/src/executor/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs @@ -8,7 +8,7 @@ //! executor wrappers in [`executor`](crate::executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. mod run_queue; -#[cfg(feature = "time")] +#[cfg(feature = "integrated-timers")] mod timer_queue; pub(crate) mod util; mod waker; @@ -22,6 +22,10 @@ use core::{mem, ptr}; use atomic_polyfill::{AtomicU32, Ordering}; use critical_section::CriticalSection; +#[cfg(feature = "integrated-timers")] +use embassy_time::driver::{self, AlarmHandle}; +#[cfg(feature = "integrated-timers")] +use embassy_time::Instant; #[cfg(feature = "rtos-trace")] use rtos_trace::trace; @@ -29,17 +33,13 @@ use self::run_queue::{RunQueue, RunQueueItem}; use self::util::UninitCell; pub use self::waker::task_from_waker; use super::SpawnToken; -#[cfg(feature = "time")] -use crate::time::driver::{self, AlarmHandle}; -#[cfg(feature = "time")] -use crate::time::Instant; /// Task is spawned (has a future) pub(crate) const STATE_SPAWNED: u32 = 1 << 0; /// Task is in the executor run queue pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1; /// Task is in the executor timer queue -#[cfg(feature = "time")] +#[cfg(feature = "integrated-timers")] pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2; /// Raw task header for use in task pointers. @@ -52,9 +52,9 @@ pub struct TaskHeader { pub(crate) executor: Cell<*const Executor>, // Valid if state != 0 pub(crate) poll_fn: UninitCell)>, // Valid if STATE_SPAWNED - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] pub(crate) expires_at: Cell, - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] pub(crate) timer_queue_item: timer_queue::TimerQueueItem, } @@ -66,9 +66,9 @@ impl TaskHeader { executor: Cell::new(ptr::null()), poll_fn: UninitCell::uninit(), - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] expires_at: Cell::new(Instant::from_ticks(0)), - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] timer_queue_item: timer_queue::TimerQueueItem::new(), } } @@ -269,9 +269,9 @@ pub struct Executor { signal_fn: fn(*mut ()), signal_ctx: *mut (), - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] pub(crate) timer_queue: timer_queue::TimerQueue, - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] alarm: AlarmHandle, } @@ -283,9 +283,9 @@ impl Executor { /// /// See [`Executor`] docs for details on `signal_fn`. pub fn new(signal_fn: fn(*mut ()), signal_ctx: *mut ()) -> Self { - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] let alarm = unsafe { unwrap!(driver::allocate_alarm()) }; - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] driver::set_alarm_callback(alarm, signal_fn, signal_ctx); Self { @@ -293,9 +293,9 @@ impl Executor { signal_fn, signal_ctx, - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] timer_queue: timer_queue::TimerQueue::new(), - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] alarm, } } @@ -354,13 +354,13 @@ impl Executor { /// somehow schedule for `poll()` to be called later, at a time you know for sure there's /// no `poll()` already running. pub unsafe fn poll(&'static self) { - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] self.timer_queue.dequeue_expired(Instant::now(), |task| wake_task(task)); self.run_queue.dequeue_all(|p| { let task = p.as_ref(); - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] task.expires_at.set(Instant::MAX); let state = task.state.fetch_and(!STATE_RUN_QUEUED, Ordering::AcqRel); @@ -383,11 +383,11 @@ impl Executor { trace::task_exec_end(); // Enqueue or update into timer_queue - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] self.timer_queue.update(p); }); - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] { // If this is already in the past, set_alarm will immediately trigger the alarm. // This will cause `signal_fn` to be called, which will cause `poll()` to be called again, @@ -435,8 +435,9 @@ pub unsafe fn wake_task(task: NonNull) { }) } -#[cfg(feature = "time")] -pub(crate) unsafe fn register_timer(at: Instant, waker: &core::task::Waker) { +#[cfg(feature = "integrated-timers")] +#[no_mangle] +unsafe fn _embassy_time_schedule_wake(at: Instant, waker: &core::task::Waker) { let task = waker::task_from_waker(waker); let task = task.as_ref(); let expires_at = task.expires_at.get(); @@ -448,11 +449,11 @@ impl rtos_trace::RtosTraceOSCallbacks for Executor { fn task_list() { // We don't know what tasks exist, so we can't send them. } - #[cfg(feature = "time")] + #[cfg(feature = "integrated-timers")] fn time() -> u64 { Instant::now().as_micros() } - #[cfg(not(feature = "time"))] + #[cfg(not(feature = "integrated-timers"))] fn time() -> u64 { 0 } diff --git a/embassy-executor/src/executor/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs similarity index 100% rename from embassy-executor/src/executor/raw/run_queue.rs rename to embassy-executor/src/raw/run_queue.rs diff --git a/embassy-executor/src/executor/raw/timer_queue.rs b/embassy-executor/src/raw/timer_queue.rs similarity index 98% rename from embassy-executor/src/executor/raw/timer_queue.rs rename to embassy-executor/src/raw/timer_queue.rs index 62fcfc53..24c31892 100644 --- a/embassy-executor/src/executor/raw/timer_queue.rs +++ b/embassy-executor/src/raw/timer_queue.rs @@ -4,9 +4,9 @@ use core::ptr; use core::ptr::NonNull; use atomic_polyfill::Ordering; +use embassy_time::Instant; use super::{TaskHeader, STATE_TIMER_QUEUED}; -use crate::time::Instant; pub(crate) struct TimerQueueItem { next: Cell<*mut TaskHeader>, diff --git a/embassy-executor/src/executor/raw/util.rs b/embassy-executor/src/raw/util.rs similarity index 100% rename from embassy-executor/src/executor/raw/util.rs rename to embassy-executor/src/raw/util.rs diff --git a/embassy-executor/src/executor/raw/waker.rs b/embassy-executor/src/raw/waker.rs similarity index 95% rename from embassy-executor/src/executor/raw/waker.rs rename to embassy-executor/src/raw/waker.rs index 6b9c03a6..5765259f 100644 --- a/embassy-executor/src/executor/raw/waker.rs +++ b/embassy-executor/src/raw/waker.rs @@ -40,7 +40,7 @@ pub fn task_from_waker(waker: &Waker) -> NonNull { // TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992 let hack: &WakerHack = unsafe { mem::transmute(waker) }; if hack.vtable != &VTABLE { - panic!("Found waker not created by the Embassy executor. `embassy_executor::time::Timer` only works with the Embassy executor.") + panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.") } // safety: we never create a waker with a null data pointer. diff --git a/embassy-executor/src/executor/spawner.rs b/embassy-executor/src/spawner.rs similarity index 100% rename from embassy-executor/src/executor/spawner.rs rename to embassy-executor/src/spawner.rs diff --git a/embassy-hal-common/Cargo.toml b/embassy-hal-common/Cargo.toml index 4a6a6100..58f0af6a 100644 --- a/embassy-hal-common/Cargo.toml +++ b/embassy-hal-common/Cargo.toml @@ -9,5 +9,4 @@ edition = "2021" defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -embassy-util = { version = "0.1.0", path = "../embassy-util" } num-traits = { version = "0.2.14", default-features = false } diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml index 6c1b01e6..c7435ab3 100644 --- a/embassy-lora/Cargo.toml +++ b/embassy-lora/Cargo.toml @@ -8,8 +8,8 @@ src_base = "https://github.com/embassy-rs/embassy/blob/embassy-lora-v$VERSION/em src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-lora/src/" features = ["time", "defmt"] flavors = [ - { name = "sx127x", target = "thumbv7em-none-eabihf", features = ["sx127x", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-executor/time-tick-32768hz"] }, - { name = "stm32wl", target = "thumbv7em-none-eabihf", features = ["stm32wl", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-executor/time-tick-32768hz"] }, + { name = "sx127x", target = "thumbv7em-none-eabihf", features = ["sx127x", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-time/tick-32768hz"] }, + { name = "stm32wl", target = "thumbv7em-none-eabihf", features = ["stm32wl", "embassy-stm32/stm32wl55jc-cm4", "embassy-stm32/time-driver-any", "embassy-time/tick-32768hz"] }, ] [lib] @@ -24,7 +24,7 @@ time = [] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -embassy-executor = { version = "0.1.0", path = "../embassy-executor" } +embassy-time = { version = "0.1.0", path = "../embassy-time" } embassy-util = { version = "0.1.0", path = "../embassy-util" } embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } diff --git a/embassy-lora/src/lib.rs b/embassy-lora/src/lib.rs index 29ea4586..1b2dd45c 100644 --- a/embassy-lora/src/lib.rs +++ b/embassy-lora/src/lib.rs @@ -18,6 +18,6 @@ pub struct LoraTimer; impl lorawan_device::async_device::radio::Timer for LoraTimer { type DelayFuture<'m> = impl core::future::Future + 'm; fn delay_ms<'m>(&'m mut self, millis: u64) -> Self::DelayFuture<'m> { - embassy_executor::time::Timer::after(embassy_executor::time::Duration::from_millis(millis)) + embassy_time::Timer::after(embassy_time::Duration::from_millis(millis)) } } diff --git a/embassy-lora/src/sx127x/sx127x_lora/mod.rs b/embassy-lora/src/sx127x/sx127x_lora/mod.rs index b3636d09..aacc9da2 100644 --- a/embassy-lora/src/sx127x/sx127x_lora/mod.rs +++ b/embassy-lora/src/sx127x/sx127x_lora/mod.rs @@ -6,7 +6,7 @@ #![allow(dead_code)] use bit_field::BitField; -use embassy_executor::time::{Duration, Timer}; +use embassy_time::{Duration, Timer}; use embedded_hal::digital::v2::OutputPin; use embedded_hal_async::spi::SpiBus; diff --git a/embassy-macros/Cargo.toml b/embassy-macros/Cargo.toml index 6abafa58..19a3e9de 100644 --- a/embassy-macros/Cargo.toml +++ b/embassy-macros/Cargo.toml @@ -13,8 +13,5 @@ proc-macro2 = "1.0.29" proc-macro = true [features] -nrf = [] -stm32 = [] -rp = [] std = [] wasm = [] diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs index 62249807..f6e41bcb 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs @@ -16,8 +16,8 @@ pub fn run(name: syn::Ident) -> Result { static HANDLER: interrupt::Handler; } - let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed); - let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed); + let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed); + let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed); let func: fn(*mut ()) = ::core::mem::transmute(func); ::embassy_executor::rtos_trace_interrupt! { ::embassy_executor::export::trace::isr_enter(); @@ -28,9 +28,9 @@ pub fn run(name: syn::Ident) -> Result { } } - static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false); + static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false); - if TAKEN.compare_exchange(false, true, ::embassy_executor::export::atomic::Ordering::AcqRel, ::embassy_executor::export::atomic::Ordering::Acquire).is_err() { + if TAKEN.compare_exchange(false, true, interrupt::_export::atomic::Ordering::AcqRel, interrupt::_export::atomic::Ordering::Acquire).is_err() { core::panic!("IRQ Already taken"); } diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs index a8c8bb0d..52987d7d 100644 --- a/embassy-macros/src/macros/main.rs +++ b/embassy-macros/src/macros/main.rs @@ -3,28 +3,12 @@ use proc_macro2::TokenStream; use quote::quote; use crate::util::ctxt::Ctxt; -use crate::util::path::ModulePrefix; - -#[cfg(feature = "stm32")] -const HAL: Option<&str> = Some("embassy_stm32"); -#[cfg(feature = "nrf")] -const HAL: Option<&str> = Some("embassy_nrf"); -#[cfg(feature = "rp")] -const HAL: Option<&str> = Some("embassy_rp"); -#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))] -const HAL: Option<&str> = None; #[derive(Debug, FromMeta)] -struct Args { - #[darling(default)] - embassy_prefix: ModulePrefix, - - #[allow(unused)] - #[darling(default)] - config: Option, -} +struct Args {} pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { + #[allow(unused_variables)] let args = Args::from_list(&args).map_err(|e| e.write_errors())?; let fargs = f.sig.inputs.clone(); @@ -32,32 +16,26 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result Result<(), wasm_bindgen::JsValue> { - static EXECUTOR: ::embassy_util::Forever<#embassy_path::executor::Executor> = ::embassy_util::Forever::new(); - let executor = EXECUTOR.put(#embassy_path::executor::Executor::new()); + static EXECUTOR: ::embassy_util::Forever<::embassy_executor::Executor> = ::embassy_util::Forever::new(); + let executor = EXECUTOR.put(::embassy_executor::Executor::new()); executor.start(|spawner| { spawner.spawn(__embassy_main(spawner)).unwrap(); @@ -70,7 +48,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result ! { - let mut executor = #embassy_path::executor::Executor::new(); + let mut executor = ::embassy_executor::Executor::new(); let executor = unsafe { __make_static(&mut executor) }; executor.run(|spawner| { @@ -80,43 +58,20 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result().unwrap()).unwrap_or_else(|| { - syn::Expr::Verbatim(quote! { - Default::default() + let main = quote! { + #[cortex_m_rt::entry] + fn main() -> ! { + let mut executor = ::embassy_executor::Executor::new(); + let executor = unsafe { __make_static(&mut executor) }; + + executor.run(|spawner| { + spawner.must_spawn(__embassy_main(spawner)); }) - }); - - let (hal_setup, peris_arg) = match HAL { - Some(hal) => { - let embassy_hal_path = embassy_prefix.append(hal).path(); - ( - quote!( - let p = #embassy_hal_path::init(#config); - ), - quote!(p), - ) - } - None => (quote!(), quote!()), - }; - - quote! { - #[cortex_m_rt::entry] - fn main() -> ! { - #hal_setup - - let mut executor = #embassy_path::executor::Executor::new(); - let executor = unsafe { __make_static(&mut executor) }; - - executor.run(|spawner| { - spawner.must_spawn(__embassy_main(spawner, #peris_arg)); - }) - } } }; let result = quote! { - #[#embassy_path::task(embassy_prefix = #embassy_prefix_lit)] + #[::embassy_executor::task()] async fn __embassy_main(#fargs) { #f_body } diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index 57087c81..573776f8 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs @@ -3,22 +3,16 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use crate::util::ctxt::Ctxt; -use crate::util::path::ModulePrefix; #[derive(Debug, FromMeta)] struct Args { #[darling(default)] pool_size: Option, - #[darling(default)] - embassy_prefix: ModulePrefix, } pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { let args = Args::from_list(&args).map_err(|e| e.write_errors())?; - let embassy_prefix = args.embassy_prefix.append("embassy_executor"); - let embassy_path = embassy_prefix.path(); - let pool_size: usize = args.pool_size.unwrap_or(1); let ctxt = Ctxt::new(); @@ -70,9 +64,9 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result #embassy_path::executor::SpawnToken { + #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken { type Fut = impl ::core::future::Future + 'static; - static POOL: #embassy_path::executor::raw::TaskPool = #embassy_path::executor::raw::TaskPool::new(); + static POOL: ::embassy_executor::raw::TaskPool = ::embassy_executor::raw::TaskPool::new(); unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } } }; diff --git a/embassy-macros/src/util/mod.rs b/embassy-macros/src/util/mod.rs index c2f2dfd6..28702809 100644 --- a/embassy-macros/src/util/mod.rs +++ b/embassy-macros/src/util/mod.rs @@ -1,2 +1 @@ pub mod ctxt; -pub mod path; diff --git a/embassy-macros/src/util/path.rs b/embassy-macros/src/util/path.rs deleted file mode 100644 index 00fca7bd..00000000 --- a/embassy-macros/src/util/path.rs +++ /dev/null @@ -1,41 +0,0 @@ -use darling::{FromMeta, Result}; -use proc_macro2::Span; -use syn::{LitStr, Path}; - -#[derive(Debug)] -pub struct ModulePrefix { - literal: LitStr, -} - -impl ModulePrefix { - pub fn new(path: &str) -> Self { - let literal = LitStr::new(path, Span::call_site()); - Self { literal } - } - - pub fn append(&self, component: &str) -> ModulePrefix { - let mut lit = self.literal().value(); - lit.push_str(component); - Self::new(lit.as_str()) - } - - pub fn path(&self) -> Path { - self.literal.parse().unwrap() - } - - pub fn literal(&self) -> &LitStr { - &self.literal - } -} - -impl FromMeta for ModulePrefix { - fn from_string(value: &str) -> Result { - Ok(ModulePrefix::new(value)) - } -} - -impl Default for ModulePrefix { - fn default() -> ModulePrefix { - ModulePrefix::new("::") - } -} diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 64cb5bd8..9f9bb226 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -7,10 +7,8 @@ edition = "2021" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/" -features = [ "pool-4", "defmt", "tcp", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "embassy-executor/time", "embassy-executor/time-tick-1mhz"] -flavors = [ - { name = "default", target = "thumbv7em-none-eabihf" }, -] +features = [ "pool-4", "defmt", "tcp", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "embassy-time/tick-1mhz"] +target = "thumbv7em-none-eabi" [features] default = [] @@ -18,6 +16,7 @@ std = [] defmt = ["dep:defmt", "smoltcp/defmt"] +udp = ["smoltcp/socket-udp"] tcp = ["smoltcp/socket-tcp"] dns = ["smoltcp/socket-dns"] dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] @@ -31,23 +30,26 @@ pool-16 = [] pool-32 = [] pool-64 = [] pool-128 = [] +unstable-traits = [] [dependencies] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -embassy-executor = { version = "0.1.0", path = "../embassy-executor" } -embassy-util = { version = "0.1.0", path = "../embassy-util" } -embedded-io = { version = "0.3.0", features = [ "async" ] } +embassy-time = { version = "0.1.0", path = "../embassy-time" } +embassy-util = { version = "0.1.0", path = "../embassy-util" } +embedded-io = { version = "0.3.0", features = [ "async" ] } -managed = { version = "0.8.0", default-features = false, features = [ "map" ] } -heapless = { version = "0.7.5", default-features = false } -as-slice = "0.2.1" -generic-array = { version = "0.14.4", default-features = false } -stable_deref_trait = { version = "1.2.0", default-features = false } -futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } -atomic-pool = "0.2.1" +managed = { version = "0.8.0", default-features = false, features = [ "map" ] } +heapless = { version = "0.7.5", default-features = false } +as-slice = "0.2.1" +generic-array = { version = "0.14.4", default-features = false } +stable_deref_trait = { version = "1.2.0", default-features = false } +futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } +atomic-pool = "1.0" +atomic-polyfill = "1.0.1" +embedded-nal-async = "0.2.0" [dependencies.smoltcp] version = "0.8.0" diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 1c5ba103..83d36471 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -16,6 +16,9 @@ pub use stack::{Config, ConfigStrategy, Stack, StackResources}; #[cfg(feature = "tcp")] pub mod tcp; +#[cfg(feature = "udp")] +pub mod udp; + // smoltcp reexports pub use smoltcp::phy::{DeviceCapabilities, Medium}; pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant}; @@ -24,3 +27,5 @@ pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; #[cfg(feature = "proto-ipv6")] pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; +#[cfg(feature = "udp")] +pub use smoltcp::{socket::udp::PacketMetadata, wire::IpListenEndpoint}; diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 06bb732f..4b6a7ae2 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -2,7 +2,7 @@ use core::cell::UnsafeCell; use core::future::Future; use core::task::{Context, Poll}; -use embassy_executor::time::{Instant, Timer}; +use embassy_time::{Instant, Timer}; use embassy_util::waitqueue::WakerRegistration; use futures::future::poll_fn; use futures::pin_mut; diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index c18391ac..910772c7 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -181,7 +181,7 @@ impl<'a> Drop for TcpSocket<'a> { // ======================= #[derive(Copy, Clone)] -pub struct TcpIo<'a> { +struct TcpIo<'a> { stack: &'a UnsafeCell, handle: SocketHandle, } @@ -328,3 +328,172 @@ impl<'d> embedded_io::asynch::Write for TcpWriter<'d> { self.io.flush() } } + +#[cfg(feature = "unstable-traits")] +pub mod client { + use core::mem::MaybeUninit; + use core::ptr::NonNull; + + use atomic_polyfill::{AtomicBool, Ordering}; + use embedded_nal_async::IpAddr; + + use super::*; + + /// TCP client capable of creating up to N multiple connections with tx and rx buffers according to TX_SZ and RX_SZ. + pub struct TcpClient<'d, D: Device, const N: usize, const TX_SZ: usize = 1024, const RX_SZ: usize = 1024> { + stack: &'d Stack, + state: &'d TcpClientState, + } + + impl<'d, D: Device, const N: usize, const TX_SZ: usize, const RX_SZ: usize> TcpClient<'d, D, N, TX_SZ, RX_SZ> { + /// Create a new TcpClient + pub fn new(stack: &'d Stack, state: &'d TcpClientState) -> Self { + Self { stack, state } + } + } + + impl<'d, D: Device, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_nal_async::TcpConnect + for TcpClient<'d, D, N, TX_SZ, RX_SZ> + { + type Error = Error; + type Connection<'m> = TcpConnection<'m, N, TX_SZ, RX_SZ> where Self: 'm; + type ConnectFuture<'m> = impl Future, Self::Error>> + 'm + where + Self: 'm; + + fn connect<'m>(&'m self, remote: embedded_nal_async::SocketAddr) -> Self::ConnectFuture<'m> { + async move { + let addr: crate::IpAddress = match remote.ip() { + IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())), + #[cfg(feature = "proto-ipv6")] + IpAddr::V6(addr) => crate::IpAddress::Ipv6(crate::Ipv6Address::from_bytes(&addr.octets())), + #[cfg(not(feature = "proto-ipv6"))] + IpAddr::V6(_) => panic!("ipv6 support not enabled"), + }; + let remote_endpoint = (addr, remote.port()); + let mut socket = TcpConnection::new(&self.stack, self.state)?; + socket + .socket + .connect(remote_endpoint) + .await + .map_err(|_| Error::ConnectionReset)?; + Ok(socket) + } + } + } + + pub struct TcpConnection<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> { + socket: TcpSocket<'d>, + state: &'d TcpClientState, + bufs: NonNull<([u8; TX_SZ], [u8; RX_SZ])>, + } + + impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> TcpConnection<'d, N, TX_SZ, RX_SZ> { + fn new(stack: &'d Stack, state: &'d TcpClientState) -> Result { + let mut bufs = state.pool.alloc().ok_or(Error::ConnectionReset)?; + Ok(Self { + socket: unsafe { TcpSocket::new(stack, &mut bufs.as_mut().0, &mut bufs.as_mut().1) }, + state, + bufs, + }) + } + } + + impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> Drop for TcpConnection<'d, N, TX_SZ, RX_SZ> { + fn drop(&mut self) { + unsafe { + self.socket.close(); + self.state.pool.free(self.bufs); + } + } + } + + impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::Io + for TcpConnection<'d, N, TX_SZ, RX_SZ> + { + type Error = Error; + } + + impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Read + for TcpConnection<'d, N, TX_SZ, RX_SZ> + { + type ReadFuture<'a> = impl Future> + where + Self: 'a; + + fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { + self.socket.read(buf) + } + } + + impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Write + for TcpConnection<'d, N, TX_SZ, RX_SZ> + { + type WriteFuture<'a> = impl Future> + where + Self: 'a; + + fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { + self.socket.write(buf) + } + + type FlushFuture<'a> = impl Future> + where + Self: 'a; + + fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { + self.socket.flush() + } + } + + /// State for TcpClient + pub struct TcpClientState { + pool: Pool<([u8; TX_SZ], [u8; RX_SZ]), N>, + } + + impl TcpClientState { + pub const fn new() -> Self { + Self { pool: Pool::new() } + } + } + + unsafe impl Sync for TcpClientState {} + + struct Pool { + used: [AtomicBool; N], + data: [UnsafeCell>; N], + } + + impl Pool { + const VALUE: AtomicBool = AtomicBool::new(false); + const UNINIT: UnsafeCell> = UnsafeCell::new(MaybeUninit::uninit()); + + const fn new() -> Self { + Self { + used: [Self::VALUE; N], + data: [Self::UNINIT; N], + } + } + } + + impl Pool { + fn alloc(&self) -> Option> { + for n in 0..N { + if self.used[n].swap(true, Ordering::SeqCst) == false { + let p = self.data[n].get() as *mut T; + return Some(unsafe { NonNull::new_unchecked(p) }); + } + } + None + } + + /// safety: p must be a pointer obtained from self.alloc that hasn't been freed yet. + unsafe fn free(&self, p: NonNull) { + let origin = self.data.as_ptr() as *mut T; + let n = p.as_ptr().offset_from(origin); + assert!(n >= 0); + assert!((n as usize) < N); + self.used[n as usize].store(false, Ordering::SeqCst); + } + } +} diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs new file mode 100644 index 00000000..78b09a49 --- /dev/null +++ b/embassy-net/src/udp.rs @@ -0,0 +1,157 @@ +use core::cell::UnsafeCell; +use core::mem; +use core::task::Poll; + +use futures::future::poll_fn; +use smoltcp::iface::{Interface, SocketHandle}; +use smoltcp::socket::udp::{self, PacketMetadata}; +use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; + +use super::stack::SocketStack; +use crate::{Device, Stack}; + +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum BindError { + /// The socket was already open. + InvalidState, + /// No route to host. + NoRoute, +} + +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum Error { + /// No route to host. + NoRoute, +} + +pub struct UdpSocket<'a> { + stack: &'a UnsafeCell, + handle: SocketHandle, +} + +impl<'a> UdpSocket<'a> { + pub fn new( + stack: &'a Stack, + rx_meta: &'a mut [PacketMetadata], + rx_buffer: &'a mut [u8], + tx_meta: &'a mut [PacketMetadata], + tx_buffer: &'a mut [u8], + ) -> Self { + // safety: not accessed reentrantly. + let s = unsafe { &mut *stack.socket.get() }; + + let rx_meta: &'static mut [PacketMetadata] = unsafe { mem::transmute(rx_meta) }; + let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) }; + let tx_meta: &'static mut [PacketMetadata] = unsafe { mem::transmute(tx_meta) }; + let tx_buffer: &'static mut [u8] = unsafe { mem::transmute(tx_buffer) }; + let handle = s.sockets.add(udp::Socket::new( + udp::PacketBuffer::new(rx_meta, rx_buffer), + udp::PacketBuffer::new(tx_meta, tx_buffer), + )); + + Self { + stack: &stack.socket, + handle, + } + } + + pub fn bind(&mut self, endpoint: T) -> Result<(), BindError> + where + T: Into, + { + let mut endpoint = endpoint.into(); + + // safety: not accessed reentrantly. + if endpoint.port == 0 { + // If user didn't specify port allocate a dynamic port. + endpoint.port = unsafe { &mut *self.stack.get() }.get_local_port(); + } + + // safety: not accessed reentrantly. + match unsafe { self.with_mut(|s, _| s.bind(endpoint)) } { + Ok(()) => Ok(()), + Err(udp::BindError::InvalidState) => Err(BindError::InvalidState), + Err(udp::BindError::Unaddressable) => Err(BindError::NoRoute), + } + } + + /// SAFETY: must not call reentrantly. + unsafe fn with(&self, f: impl FnOnce(&udp::Socket, &Interface) -> R) -> R { + let s = &*self.stack.get(); + let socket = s.sockets.get::(self.handle); + f(socket, &s.iface) + } + + /// SAFETY: must not call reentrantly. + unsafe fn with_mut(&self, f: impl FnOnce(&mut udp::Socket, &mut Interface) -> R) -> R { + let s = &mut *self.stack.get(); + let socket = s.sockets.get_mut::(self.handle); + let res = f(socket, &mut s.iface); + s.waker.wake(); + res + } + + pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), Error> { + poll_fn(move |cx| unsafe { + self.with_mut(|s, _| match s.recv_slice(buf) { + Ok(x) => Poll::Ready(Ok(x)), + // No data ready + Err(udp::RecvError::Exhausted) => { + //s.register_recv_waker(cx.waker()); + cx.waker().wake_by_ref(); + Poll::Pending + } + }) + }) + .await + } + + pub async fn send_to(&self, buf: &[u8], remote_endpoint: T) -> Result<(), Error> + where + T: Into, + { + let remote_endpoint = remote_endpoint.into(); + poll_fn(move |cx| unsafe { + self.with_mut(|s, _| match s.send_slice(buf, remote_endpoint) { + // Entire datagram has been sent + Ok(()) => Poll::Ready(Ok(())), + Err(udp::SendError::BufferFull) => { + s.register_send_waker(cx.waker()); + Poll::Pending + } + Err(udp::SendError::Unaddressable) => Poll::Ready(Err(Error::NoRoute)), + }) + }) + .await + } + + pub fn endpoint(&self) -> IpListenEndpoint { + unsafe { self.with(|s, _| s.endpoint()) } + } + + pub fn is_open(&self) -> bool { + unsafe { self.with(|s, _| s.is_open()) } + } + + pub fn close(&mut self) { + unsafe { self.with_mut(|s, _| s.close()) } + } + + pub fn may_send(&self) -> bool { + unsafe { self.with(|s, _| s.can_send()) } + } + + pub fn may_recv(&self) -> bool { + unsafe { self.with(|s, _| s.can_recv()) } + } +} + +impl Drop for UdpSocket<'_> { + fn drop(&mut self) { + // safety: not accessed reentrantly. + let s = unsafe { &mut *self.stack.get() }; + s.sockets.remove(self.handle); + } +} diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 75780d41..0ef7f5bb 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -16,7 +16,7 @@ flavors = [ [features] -time = ["embassy-executor/time"] +time = ["dep:embassy-time"] defmt = ["dep:defmt", "embassy-executor/defmt", "embassy-util/defmt", "embassy-usb?/defmt", "embedded-io?/defmt", "embassy-embedded-hal/defmt"] @@ -57,7 +57,7 @@ _nrf5340-net = ["_nrf5340", "nrf5340-net-pac"] _nrf5340 = ["_gpio-p1", "_dppi"] _nrf9160 = ["nrf9160-pac", "_dppi"] -_time-driver = ["embassy-executor/time-tick-32768hz", "time"] +_time-driver = ["dep:embassy-time", "embassy-time?/tick-32768hz"] _ppi = [] _dppi = [] @@ -65,9 +65,9 @@ _gpio-p1 = [] [dependencies] embassy-executor = { version = "0.1.0", path = "../embassy-executor", optional = true } +embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true } embassy-util = { version = "0.1.0", path = "../embassy-util" } embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} -embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true } @@ -80,9 +80,9 @@ embedded-io = { version = "0.3.0", features = ["async"], optional = true } defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } cortex-m-rt = ">=0.6.15,<0.8" -cortex-m = "0.7.3" +cortex-m = "0.7.6" futures = { version = "0.3.17", default-features = false } -critical-section = "0.2.5" +critical-section = "1.1" rand_core = "0.6.3" fixed = "1.10.0" embedded-storage = "0.3.0" diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index 8fca4da1..d078fa0a 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs @@ -197,7 +197,7 @@ impl_saadc_input!(P0_04, ANALOGINPUT2); impl_saadc_input!(P0_05, ANALOGINPUT3); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index 538a617d..faa52d8f 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs @@ -218,7 +218,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index 808adf51..bbdf1cbe 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs @@ -219,7 +219,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index 6be5bd36..dba033b0 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs @@ -211,7 +211,7 @@ impl_ppi_channel!(PPI_CH30, 30 => static); impl_ppi_channel!(PPI_CH31, 31 => static); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index cdc644d6..18b8eda6 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs @@ -235,7 +235,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index 4c3c5574..39a0f93f 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs @@ -278,7 +278,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index bdaeadb9..e3d8f34a 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs @@ -283,7 +283,7 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs index 26dc56bd..edf800ef 100644 --- a/embassy-nrf/src/chips/nrf5340_app.rs +++ b/embassy-nrf/src/chips/nrf5340_app.rs @@ -468,7 +468,7 @@ impl_saadc_input!(P0_19, ANALOGINPUT6); impl_saadc_input!(P0_20, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs index e28cfe01..ae136e09 100644 --- a/embassy-nrf/src/chips/nrf5340_net.rs +++ b/embassy-nrf/src/chips/nrf5340_net.rs @@ -328,7 +328,7 @@ impl_ppi_channel!(PPI_CH30, 30 => configurable); impl_ppi_channel!(PPI_CH31, 31 => configurable); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs index 1a0bd10f..a4be8564 100644 --- a/embassy-nrf/src/chips/nrf9160.rs +++ b/embassy-nrf/src/chips/nrf9160.rs @@ -346,7 +346,7 @@ impl_saadc_input!(P0_19, ANALOGINPUT6); impl_saadc_input!(P0_20, ANALOGINPUT7); pub mod irqs { - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; use crate::pac::Interrupt as InterruptEnum; diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index ad6c16c1..f3b3ca0c 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -135,8 +135,8 @@ pub use chip::pac; pub(crate) use chip::pac; pub use chip::{peripherals, Peripherals}; pub use embassy_cortex_m::executor; +pub use embassy_cortex_m::interrupt::_export::interrupt; pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; -pub use embassy_macros::cortex_m_interrupt as interrupt; pub mod config { //! Configuration options used when initializing the HAL. diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index 05fa0aea..b961d65a 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs @@ -3,7 +3,7 @@ use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; use core::{mem, ptr}; use critical_section::CriticalSection; -use embassy_executor::time::driver::{AlarmHandle, Driver}; +use embassy_time::driver::{AlarmHandle, Driver}; use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_util::blocking_mutex::CriticalSectionMutex as Mutex; @@ -119,7 +119,7 @@ struct RtcDriver { } const ALARM_STATE_NEW: AlarmState = AlarmState::new(); -embassy_executor::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { +embassy_time::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { period: AtomicU32::new(0), alarm_count: AtomicU8::new(0), alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 494abe0c..9587d1f4 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -12,9 +12,9 @@ use core::sync::atomic::Ordering::SeqCst; use core::task::Poll; use embassy_embedded_hal::SetConfig; -#[cfg(feature = "time")] -use embassy_executor::time::{Duration, Instant}; use embassy_hal_common::{into_ref, PeripheralRef}; +#[cfg(feature = "time")] +use embassy_time::{Duration, Instant}; use embassy_util::waitqueue::AtomicWaker; use futures::future::poll_fn; diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index 303617ff..af7c8ee6 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -28,17 +28,19 @@ unstable-traits = ["embedded-hal-1"] [dependencies] embassy-util = { version = "0.1.0", path = "../embassy-util" } -embassy-executor = { version = "0.1.0", path = "../embassy-executor", features = [ "time-tick-1mhz" ] } +embassy-executor = { version = "0.1.0", path = "../embassy-executor" } +embassy-time = { version = "0.1.0", path = "../embassy-time", features = [ "tick-1mhz" ] } embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } -embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} -atomic-polyfill = "0.1.5" +atomic-polyfill = "1.0.1" defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } +nb = "1.0.0" +cfg-if = "1.0.0" cortex-m-rt = ">=0.6.15,<0.8" -cortex-m = "0.7.3" -critical-section = "0.2.5" +cortex-m = "0.7.6" +critical-section = "1.1" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="9ad7223a48a065e612bc7dc7be5bf5bd0b41cfc4", features = ["rt"] } diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 235e92d7..42c4fd13 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs @@ -1,5 +1,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; +use embassy_hal_common::impl_peripheral; + use crate::pac::dma::vals; use crate::{pac, peripherals}; @@ -35,6 +37,10 @@ impl Dma { } } +pub struct NoDma; + +impl_peripheral!(NoDma); + mod sealed { use super::*; diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index d652a8c7..f21a5433 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs @@ -4,8 +4,8 @@ //! nrf_softdevice::interrupt. Intended for switching between the two at compile-time. // Re-exports +use embassy_cortex_m::interrupt::_export::declare; pub use embassy_cortex_m::interrupt::*; -use embassy_macros::cortex_m_interrupt_declare as declare; use crate::pac::Interrupt as InterruptEnum; declare!(TIMER_IRQ_0); diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 44150be0..8c053a4f 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -17,8 +17,8 @@ mod reset; // Reexports pub use embassy_cortex_m::executor; +pub use embassy_cortex_m::interrupt::_export::interrupt; pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; -pub use embassy_macros::cortex_m_interrupt as interrupt; #[cfg(feature = "unstable-pac")] pub use rp2040_pac2 as pac; #[cfg(not(feature = "unstable-pac"))] diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index 142fd410..5bc1f66c 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs @@ -2,7 +2,7 @@ use core::cell::Cell; use atomic_polyfill::{AtomicU8, Ordering}; use critical_section::CriticalSection; -use embassy_executor::time::driver::{AlarmHandle, Driver}; +use embassy_time::driver::{AlarmHandle, Driver}; use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_util::blocking_mutex::Mutex; @@ -26,7 +26,7 @@ struct TimerDriver { next_alarm: AtomicU8, } -embassy_executor::time_driver_impl!(static DRIVER: TimerDriver = TimerDriver{ +embassy_time::time_driver_impl!(static DRIVER: TimerDriver = TimerDriver{ alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [DUMMY_ALARM; ALARM_COUNT]), next_alarm: AtomicU8::new(0), }); diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index b19f043f..6c5ab351 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs @@ -1,42 +1,199 @@ -use embassy_hal_common::{into_ref, PeripheralRef}; -use gpio::Pin; +use core::marker::PhantomData; -use crate::{gpio, pac, peripherals, Peripheral}; +use embassy_hal_common::{into_ref, PeripheralRef}; + +use crate::gpio::sealed::Pin; +use crate::gpio::AnyPin; +use crate::{pac, peripherals, Peripheral}; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum DataBits { + DataBits5, + DataBits6, + DataBits7, + DataBits8, +} + +impl DataBits { + fn bits(&self) -> u8 { + match self { + Self::DataBits5 => 0b00, + Self::DataBits6 => 0b01, + Self::DataBits7 => 0b10, + Self::DataBits8 => 0b11, + } + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Parity { + ParityNone, + ParityEven, + ParityOdd, +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum StopBits { + #[doc = "1 stop bit"] + STOP1, + #[doc = "2 stop bits"] + STOP2, +} #[non_exhaustive] +#[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct Config { pub baudrate: u32, - pub data_bits: u8, - pub stop_bits: u8, + pub data_bits: DataBits, + pub stop_bits: StopBits, + pub parity: Parity, } impl Default for Config { fn default() -> Self { Self { baudrate: 115200, - data_bits: 8, - stop_bits: 1, + data_bits: DataBits::DataBits8, + stop_bits: StopBits::STOP1, + parity: Parity::ParityNone, } } } +/// Serial error +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[non_exhaustive] +pub enum Error { + /// Triggered when the FIFO (or shift-register) is overflowed. + Overrun, + /// Triggered when a break is received + Break, + /// Triggered when there is a parity mismatch between what's received and + /// our settings. + Parity, + /// Triggered when the received character didn't have a valid stop bit. + Framing, +} + pub struct Uart<'d, T: Instance> { - inner: PeripheralRef<'d, T>, + tx: UartTx<'d, T>, + rx: UartRx<'d, T>, +} + +pub struct UartTx<'d, T: Instance> { + phantom: PhantomData<&'d mut T>, +} + +pub struct UartRx<'d, T: Instance> { + phantom: PhantomData<&'d mut T>, +} + +impl<'d, T: Instance> UartTx<'d, T> { + fn new() -> Self { + Self { phantom: PhantomData } + } + + pub async fn write(&mut self, _buffer: &[u8]) -> Result<(), Error> { + todo!() + } + + pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> { + let r = T::regs(); + unsafe { + for &b in buffer { + while r.uartfr().read().txff() {} + r.uartdr().write(|w| w.set_data(b)); + } + } + Ok(()) + } + + pub fn blocking_flush(&mut self) -> Result<(), Error> { + let r = T::regs(); + unsafe { while r.uartfr().read().txff() {} } + Ok(()) + } +} + +impl<'d, T: Instance> UartRx<'d, T> { + fn new() -> Self { + Self { phantom: PhantomData } + } + + pub async fn read(&mut self, _buffer: &mut [u8]) -> Result<(), Error> { + todo!(); + } + + pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { + let r = T::regs(); + unsafe { + for b in buffer { + *b = loop { + let dr = r.uartdr().read(); + + if dr.oe() { + return Err(Error::Overrun); + } else if dr.be() { + return Err(Error::Break); + } else if dr.pe() { + return Err(Error::Parity); + } else if dr.fe() { + return Err(Error::Framing); + } else if dr.fe() { + break dr.data(); + } + }; + } + } + Ok(()) + } } impl<'d, T: Instance> Uart<'d, T> { + /// Create a new UART without hardware flow control pub fn new( - inner: impl Peripheral

+ 'd, + uart: impl Peripheral

+ 'd, + tx: impl Peripheral

> + 'd, + rx: impl Peripheral

> + 'd, + config: Config, + ) -> Self { + into_ref!(tx, rx); + Self::new_inner(uart, rx.map_into(), tx.map_into(), None, None, config) + } + + /// Create a new UART with hardware flow control (RTS/CTS) + pub fn new_with_rtscts( + uart: impl Peripheral

+ 'd, tx: impl Peripheral

> + 'd, rx: impl Peripheral

> + 'd, cts: impl Peripheral

> + 'd, rts: impl Peripheral

> + 'd, config: Config, ) -> Self { - into_ref!(inner, tx, rx, cts, rts); + into_ref!(tx, rx, cts, rts); + Self::new_inner( + uart, + rx.map_into(), + tx.map_into(), + Some(cts.map_into()), + Some(rts.map_into()), + config, + ) + } + + fn new_inner( + _uart: impl Peripheral

+ 'd, + tx: PeripheralRef<'d, AnyPin>, + rx: PeripheralRef<'d, AnyPin>, + cts: Option>, + rts: Option>, + config: Config, + ) -> Self { + into_ref!(_uart); unsafe { - let p = inner.regs(); + let r = T::regs(); let clk_base = crate::clocks::clk_peri_freq(); @@ -53,49 +210,217 @@ impl<'d, T: Instance> Uart<'d, T> { } // Load PL011's baud divisor registers - p.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd)); - p.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); + r.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd)); + r.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); - p.uartlcr_h().write(|w| { - w.set_wlen(config.data_bits - 5); - w.set_stp2(config.stop_bits == 2); - w.set_pen(false); - w.set_eps(false); + let (pen, eps) = match config.parity { + Parity::ParityNone => (false, false), + Parity::ParityEven => (true, true), + Parity::ParityOdd => (true, false), + }; + + r.uartlcr_h().write(|w| { + w.set_wlen(config.data_bits.bits()); + w.set_stp2(config.stop_bits == StopBits::STOP2); + w.set_pen(pen); + w.set_eps(eps); w.set_fen(true); }); - p.uartcr().write(|w| { + r.uartcr().write(|w| { w.set_uarten(true); w.set_rxe(true); w.set_txe(true); + w.set_ctsen(cts.is_some()); + w.set_rtsen(rts.is_some()); }); tx.io().ctrl().write(|w| w.set_funcsel(2)); rx.io().ctrl().write(|w| w.set_funcsel(2)); - cts.io().ctrl().write(|w| w.set_funcsel(2)); - rts.io().ctrl().write(|w| w.set_funcsel(2)); + if let Some(pin) = &cts { + pin.io().ctrl().write(|w| w.set_funcsel(2)); + } + if let Some(pin) = &rts { + pin.io().ctrl().write(|w| w.set_funcsel(2)); + } + } + + Self { + tx: UartTx::new(), + rx: UartRx::new(), } - Self { inner } } - pub fn send(&mut self, data: &[u8]) { - unsafe { - let p = self.inner.regs(); + pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { + self.tx.write(buffer).await + } - for &byte in data { - if !p.uartfr().read().txff() { - p.uartdr().write(|w| w.set_data(byte)); + pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> { + self.tx.blocking_write(buffer) + } + + pub fn blocking_flush(&mut self) -> Result<(), Error> { + self.tx.blocking_flush() + } + + pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { + self.rx.read(buffer).await + } + + pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { + self.rx.blocking_read(buffer) + } + + /// Split the Uart into a transmitter and receiver, which is + /// particuarly useful when having two tasks correlating to + /// transmitting and receiving. + pub fn split(self) -> (UartTx<'d, T>, UartRx<'d, T>) { + (self.tx, self.rx) + } +} + +mod eh02 { + use super::*; + + impl<'d, T: Instance> embedded_hal_02::serial::Read for UartRx<'d, T> { + type Error = Error; + fn read(&mut self) -> Result> { + let r = T::regs(); + unsafe { + let dr = r.uartdr().read(); + + if dr.oe() { + Err(nb::Error::Other(Error::Overrun)) + } else if dr.be() { + Err(nb::Error::Other(Error::Break)) + } else if dr.pe() { + Err(nb::Error::Other(Error::Parity)) + } else if dr.fe() { + Err(nb::Error::Other(Error::Framing)) + } else if dr.fe() { + Ok(dr.data()) + } else { + Err(nb::Error::WouldBlock) } } } } + + impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write for UartTx<'d, T> { + type Error = Error; + fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { + self.blocking_write(buffer) + } + fn bflush(&mut self) -> Result<(), Self::Error> { + self.blocking_flush() + } + } + + impl<'d, T: Instance> embedded_hal_02::serial::Read for Uart<'d, T> { + type Error = Error; + fn read(&mut self) -> Result> { + embedded_hal_02::serial::Read::read(&mut self.rx) + } + } + + impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write for Uart<'d, T> { + type Error = Error; + fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { + self.blocking_write(buffer) + } + fn bflush(&mut self) -> Result<(), Self::Error> { + self.blocking_flush() + } + } +} + +#[cfg(feature = "unstable-traits")] +mod eh1 { + use super::*; + + impl embedded_hal_1::serial::Error for Error { + fn kind(&self) -> embedded_hal_1::serial::ErrorKind { + match *self { + Self::Framing => embedded_hal_1::serial::ErrorKind::FrameFormat, + Self::Break => embedded_hal_1::serial::ErrorKind::Other, + Self::Overrun => embedded_hal_1::serial::ErrorKind::Overrun, + Self::Parity => embedded_hal_1::serial::ErrorKind::Parity, + } + } + } + + impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for Uart<'d, T> { + type Error = Error; + } + + impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UartTx<'d, T> { + type Error = Error; + } + + impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UartRx<'d, T> { + type Error = Error; + } +} + +cfg_if::cfg_if! { + if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] { + use core::future::Future; + + impl<'d, T: Instance> embedded_hal_async::serial::Write for UartTx<'d, T> + { + type WriteFuture<'a> = impl Future> + 'a where Self: 'a; + + fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { + self.write(buf) + } + + type FlushFuture<'a> = impl Future> + 'a where Self: 'a; + + fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { + async move { Ok(()) } + } + } + + impl<'d, T: Instance> embedded_hal_async::serial::Read for UartRx<'d, T> + { + type ReadFuture<'a> = impl Future> + 'a where Self: 'a; + + fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { + self.read(buf) + } + } + + impl<'d, T: Instance> embedded_hal_async::serial::Write for Uart<'d, T> + { + type WriteFuture<'a> = impl Future> + 'a where Self: 'a; + + fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { + self.write(buf) + } + + type FlushFuture<'a> = impl Future> + 'a where Self: 'a; + + fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { + async move { Ok(()) } + } + } + + impl<'d, T: Instance> embedded_hal_async::serial::Read for Uart<'d, T> + { + type ReadFuture<'a> = impl Future> + 'a where Self: 'a; + + fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { + self.read(buf) + } + } + } } mod sealed { use super::*; pub trait Instance { - fn regs(&self) -> pac::uart::Uart; + fn regs() -> pac::uart::Uart; } pub trait TxPin {} pub trait RxPin {} @@ -106,23 +431,23 @@ mod sealed { pub trait Instance: sealed::Instance {} macro_rules! impl_instance { - ($type:ident, $irq:ident) => { - impl sealed::Instance for peripherals::$type { - fn regs(&self) -> pac::uart::Uart { - pac::$type + ($inst:ident, $irq:ident) => { + impl sealed::Instance for peripherals::$inst { + fn regs() -> pac::uart::Uart { + pac::$inst } } - impl Instance for peripherals::$type {} + impl Instance for peripherals::$inst {} }; } impl_instance!(UART0, UART0); impl_instance!(UART1, UART1); -pub trait TxPin: sealed::TxPin + Pin {} -pub trait RxPin: sealed::RxPin + Pin {} -pub trait CtsPin: sealed::CtsPin + Pin {} -pub trait RtsPin: sealed::RtsPin + Pin {} +pub trait TxPin: sealed::TxPin + crate::gpio::Pin {} +pub trait RxPin: sealed::RxPin + crate::gpio::Pin {} +pub trait CtsPin: sealed::CtsPin + crate::gpio::Pin {} +pub trait RtsPin: sealed::RtsPin + crate::gpio::Pin {} macro_rules! impl_pin { ($pin:ident, $instance:ident, $function:ident) => { diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index ff228cc8..c47ea0bc 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -10,7 +10,7 @@ src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-stm32 # TODO: sdmmc # TODO: net # TODO: subghz -features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "exti", "time-driver-any", "embassy-executor/time-tick-32768hz"] +features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "exti", "time-driver-any", "embassy-time/tick-32768hz"] flavors = [ { regex_feature = "stm32f0.*", target = "thumbv6m-none-eabi" }, { regex_feature = "stm32f1.*", target = "thumbv7m-none-eabi" }, @@ -33,8 +33,8 @@ flavors = [ [dependencies] embassy-util = { version = "0.1.0", path = "../embassy-util" } embassy-executor = { version = "0.1.0", path = "../embassy-executor" } +embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true } embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]} -embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } embassy-net = { version = "0.1.0", path = "../embassy-net", optional = true } @@ -50,14 +50,13 @@ embedded-storage-async = { version = "0.3.0", optional = true } defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } cortex-m-rt = ">=0.6.15,<0.8" -cortex-m = "0.7.3" +cortex-m = "0.7.6" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } rand_core = "0.6.3" sdio-host = "0.5.0" embedded-sdmmc = { git = "https://github.com/thalesfragoso/embedded-sdmmc-rs", branch = "async", optional = true } -critical-section = "0.2.5" -bare-metal = "1.0.0" -atomic-polyfill = "0.1.5" +critical-section = "1.1" +atomic-polyfill = "1.0.1" stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] } vcell = "0.1.3" bxcan = "0.7.0" @@ -82,7 +81,7 @@ exti = [] # Features starting with `_` are for internal use only. They're not intended # to be enabled by other crates, and are not covered by semver guarantees. -_time-driver = ["embassy-executor/time"] +_time-driver = ["dep:embassy-time"] time-driver-any = ["_time-driver"] time-driver-tim2 = ["_time-driver"] time-driver-tim3 = ["_time-driver"] diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 3b4aa5df..c892007a 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -96,7 +96,7 @@ fn main() { g.extend(quote! { pub mod interrupt { use crate::pac::Interrupt as InterruptEnum; - use embassy_macros::cortex_m_interrupt_declare as declare; + use embassy_cortex_m::interrupt::_export::declare; #( declare!(#irqs); )* diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 3c4cdb88..d794e398 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -213,7 +213,7 @@ impl<'d, T: Pin> Drop for Flex<'d, T> { } /// Pull setting for an input. -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Pull { None, @@ -235,7 +235,7 @@ impl From for vals::Pupdr { } /// Speed settings -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Speed { Low, @@ -303,7 +303,7 @@ impl<'d, T: Pin> Input<'d, T> { } /// Digital input or output level. -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Level { Low, @@ -470,7 +470,7 @@ pub(crate) mod sealed { use super::*; /// Alternate function type settings - #[derive(Debug)] + #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum AFType { Input, diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 613815a9..9dc75789 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -4,11 +4,28 @@ use embassy_embedded_hal::SetConfig; use embassy_hal_common::into_ref; use crate::gpio::sealed::AFType; +use crate::gpio::Pull; use crate::i2c::{Error, Instance, SclPin, SdaPin}; use crate::pac::i2c; use crate::time::Hertz; use crate::Peripheral; +#[non_exhaustive] +#[derive(Copy, Clone)] +pub struct Config { + pub sda_pullup: bool, + pub scl_pullup: bool, +} + +impl Default for Config { + fn default() -> Self { + Self { + sda_pullup: false, + scl_pullup: false, + } + } +} + pub struct State {} impl State { @@ -27,6 +44,7 @@ impl<'d, T: Instance> I2c<'d, T> { scl: impl Peripheral

> + 'd, sda: impl Peripheral

> + 'd, freq: Hertz, + config: Config, ) -> Self { into_ref!(scl, sda); @@ -34,8 +52,22 @@ impl<'d, T: Instance> I2c<'d, T> { T::reset(); unsafe { - scl.set_as_af(scl.af_num(), AFType::OutputOpenDrain); - sda.set_as_af(sda.af_num(), AFType::OutputOpenDrain); + scl.set_as_af_pull( + scl.af_num(), + AFType::OutputOpenDrain, + match config.scl_pullup { + true => Pull::Up, + false => Pull::None, + }, + ); + sda.set_as_af_pull( + sda.af_num(), + AFType::OutputOpenDrain, + match config.sda_pullup { + true => Pull::Up, + false => Pull::None, + }, + ); } unsafe { diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index f8067e8b..b4303d3d 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -10,12 +10,29 @@ use futures::future::poll_fn; use crate::dma::NoDma; use crate::gpio::sealed::AFType; +use crate::gpio::Pull; use crate::i2c::{Error, Instance, SclPin, SdaPin}; use crate::interrupt::InterruptExt; use crate::pac::i2c; use crate::time::Hertz; use crate::Peripheral; +#[non_exhaustive] +#[derive(Copy, Clone)] +pub struct Config { + pub sda_pullup: bool, + pub scl_pullup: bool, +} + +impl Default for Config { + fn default() -> Self { + Self { + sda_pullup: false, + scl_pullup: false, + } + } +} + pub struct State { waker: AtomicWaker, chunks_transferred: AtomicUsize, @@ -46,6 +63,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { tx_dma: impl Peripheral

+ 'd, rx_dma: impl Peripheral

+ 'd, freq: Hertz, + config: Config, ) -> Self { into_ref!(peri, irq, scl, sda, tx_dma, rx_dma); @@ -53,8 +71,22 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { T::reset(); unsafe { - scl.set_as_af(scl.af_num(), AFType::OutputOpenDrain); - sda.set_as_af(sda.af_num(), AFType::OutputOpenDrain); + scl.set_as_af_pull( + scl.af_num(), + AFType::OutputOpenDrain, + match config.scl_pullup { + true => Pull::Up, + false => Pull::None, + }, + ); + sda.set_as_af_pull( + sda.af_num(), + AFType::OutputOpenDrain, + match config.sda_pullup { + true => Pull::Up, + false => Pull::None, + }, + ); } unsafe { diff --git a/embassy-stm32/src/interrupt.rs b/embassy-stm32/src/interrupt.rs index 9dc1f204..b66e4c7e 100644 --- a/embassy-stm32/src/interrupt.rs +++ b/embassy-stm32/src/interrupt.rs @@ -1,5 +1,4 @@ -pub use bare_metal::Mutex; -pub use critical_section::CriticalSection; +pub use critical_section::{CriticalSection, Mutex}; pub use embassy_cortex_m::interrupt::*; pub use crate::_generated::interrupt::*; diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 78025f3d..30ff02d5 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -75,8 +75,8 @@ pub(crate) mod _generated { // Reexports pub use _generated::{peripherals, Peripherals}; pub use embassy_cortex_m::executor; +pub use embassy_cortex_m::interrupt::_export::interrupt; pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; -pub use embassy_macros::cortex_m_interrupt as interrupt; #[cfg(feature = "unstable-pac")] pub use stm32_metapac as pac; #[cfg(not(feature = "unstable-pac"))] diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 1f7e3907..960c4532 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs @@ -63,7 +63,7 @@ seq_macro::seq!(N in 2..=128 { match self { PllClkDiv::NotDivided => 1, #( - PllClkDiv::Div~N => (N + 1), + PllClkDiv::Div~N => N + 1, )* } } @@ -81,7 +81,7 @@ seq_macro::seq!(N in 4..=512 { pub enum PllN { NotMultiplied, #( - Mul~N = (N-1), + Mul~N = N-1, )* } @@ -90,7 +90,7 @@ seq_macro::seq!(N in 4..=512 { match self { PllN::NotMultiplied => 1, #( - PllN::Mul~N => (N + 1), + PllN::Mul~N => N + 1, )* } } diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 1de4b2aa..3ad31ec8 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -999,10 +999,17 @@ impl SdmmcInner { fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> { let regs = self.0; + let width_u32 = match width { + BusWidth::One => 1u32, + BusWidth::Four => 4u32, + BusWidth::Eight => 8u32, + _ => panic!("Invalid Bus Width"), + }; + let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7 // Section 55.5.8 - let sdmmc_bus_bandwidth = new_clock.0 * (width as u32); + let sdmmc_bus_bandwidth = new_clock.0 * width_u32; assert!(ker_ck.0 > 3 * sdmmc_bus_bandwidth / 32); *clock = new_clock; diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index 4e53efed..a74f9a6d 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs @@ -504,7 +504,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { /// /// sg.set_standby(StandbyClk::Rc)?; /// unsafe { sg.set_sleep(SleepCfg::default())? }; - /// embassy_executor::time::Timer::after(embassy_executor::time::Duration::from_micros(500)).await; + /// embassy_time::Timer::after(embassy_time::Duration::from_micros(500)).await; /// unsafe { wakeup() }; /// # Ok::<(), embassy_stm32::subghz::Error>(()) /// ``` diff --git a/embassy-stm32/src/subghz/timeout.rs b/embassy-stm32/src/subghz/timeout.rs index b8d6ad8f..28b3b0c2 100644 --- a/embassy-stm32/src/subghz/timeout.rs +++ b/embassy-stm32/src/subghz/timeout.rs @@ -439,9 +439,9 @@ impl From for [u8; 3] { } } -impl From for embassy_executor::time::Duration { +impl From for embassy_time::Duration { fn from(to: Timeout) -> Self { - embassy_executor::time::Duration::from_micros(to.as_micros().into()) + embassy_time::Duration::from_micros(to.as_micros().into()) } } diff --git a/embassy-stm32/src/subghz/tx_params.rs b/embassy-stm32/src/subghz/tx_params.rs index a72c060f..cede6f2c 100644 --- a/embassy-stm32/src/subghz/tx_params.rs +++ b/embassy-stm32/src/subghz/tx_params.rs @@ -44,17 +44,17 @@ impl From for core::time::Duration { } } -impl From for embassy_executor::time::Duration { +impl From for embassy_time::Duration { fn from(rt: RampTime) -> Self { match rt { - RampTime::Micros10 => embassy_executor::time::Duration::from_micros(10), - RampTime::Micros20 => embassy_executor::time::Duration::from_micros(20), - RampTime::Micros40 => embassy_executor::time::Duration::from_micros(40), - RampTime::Micros80 => embassy_executor::time::Duration::from_micros(80), - RampTime::Micros200 => embassy_executor::time::Duration::from_micros(200), - RampTime::Micros800 => embassy_executor::time::Duration::from_micros(800), - RampTime::Micros1700 => embassy_executor::time::Duration::from_micros(1700), - RampTime::Micros3400 => embassy_executor::time::Duration::from_micros(3400), + RampTime::Micros10 => embassy_time::Duration::from_micros(10), + RampTime::Micros20 => embassy_time::Duration::from_micros(20), + RampTime::Micros40 => embassy_time::Duration::from_micros(40), + RampTime::Micros80 => embassy_time::Duration::from_micros(80), + RampTime::Micros200 => embassy_time::Duration::from_micros(200), + RampTime::Micros800 => embassy_time::Duration::from_micros(800), + RampTime::Micros1700 => embassy_time::Duration::from_micros(1700), + RampTime::Micros3400 => embassy_time::Duration::from_micros(3400), } } } diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 6cea43f1..7f472316 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -4,8 +4,8 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::{mem, ptr}; use atomic_polyfill::{AtomicU32, AtomicU8}; -use embassy_executor::time::driver::{AlarmHandle, Driver}; -use embassy_executor::time::TICKS_PER_SECOND; +use embassy_time::driver::{AlarmHandle, Driver}; +use embassy_time::TICKS_PER_SECOND; use embassy_util::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_util::blocking_mutex::Mutex; use stm32_metapac::timer::regs; @@ -133,7 +133,7 @@ struct RtcDriver { const ALARM_STATE_NEW: AlarmState = AlarmState::new(); -embassy_executor::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { +embassy_time::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { period: AtomicU32::new(0), alarm_count: AtomicU8::new(0), alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 764b2146..3861e42d 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -5,8 +5,8 @@ use core::sync::atomic::Ordering; use core::task::Poll; use atomic_polyfill::{AtomicBool, AtomicU8}; -use embassy_executor::time::{block_for, Duration}; use embassy_hal_common::into_ref; +use embassy_time::{block_for, Duration}; use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; use embassy_util::waitqueue::AtomicWaker; diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml new file mode 100644 index 00000000..161c101f --- /dev/null +++ b/embassy-time/Cargo.toml @@ -0,0 +1,54 @@ +[package] +name = "embassy-time" +version = "0.1.0" +edition = "2021" + + +[package.metadata.embassy_docs] +src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/" +src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/" +features = ["nightly", "defmt", "unstable-traits", "std"] +target = "x86_64-unknown-linux-gnu" + +[features] +std = ["tick-1mhz"] +wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-1mhz"] + +# Enable nightly-only features +nightly = ["embedded-hal-async"] + +# Implement embedded-hal 1.0 alpha and embedded-hal-async traits. +# Implement embedded-hal-async traits if `nightly` is set as well. +unstable-traits = ["embedded-hal-1"] + +# Display a timestamp of the number of seconds since startup next to defmt log messages +# To use this you must have a time driver provided. +defmt-timestamp-uptime = ["defmt"] + +# Set the `embassy_time` tick rate. +# NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. +# If you're not writing your own driver, check the driver documentation to customize the tick rate. +# If you're writing a driver and your tick rate is not listed here, please add it and send a PR! +tick-32768hz = [] +tick-1000hz = [] +tick-1mhz = [] +tick-16mhz = [] + +[dependencies] +defmt = { version = "0.3", optional = true } +log = { version = "0.4.14", optional = true } + +embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } +embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true} +embedded-hal-async = { version = "0.1.0-alpha.1", optional = true} + +futures-util = { version = "0.3.17", default-features = false } +embassy-macros = { version = "0.1.0", path = "../embassy-macros"} +atomic-polyfill = "1.0.1" +critical-section = "1.1" +cfg-if = "1.0.0" + +# WASM dependencies +wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } +js-sys = { version = "0.3", optional = true } +wasm-timer = { version = "0.2.5", optional = true } \ No newline at end of file diff --git a/embassy-executor/src/time/delay.rs b/embassy-time/src/delay.rs similarity index 98% rename from embassy-executor/src/time/delay.rs rename to embassy-time/src/delay.rs index d76ed32e..d010fff9 100644 --- a/embassy-executor/src/time/delay.rs +++ b/embassy-time/src/delay.rs @@ -33,7 +33,7 @@ mod eh1 { cfg_if::cfg_if! { if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { - use crate::time::Timer; + use crate::Timer; use core::future::Future; use futures_util::FutureExt; diff --git a/embassy-executor/src/time/driver.rs b/embassy-time/src/driver.rs similarity index 83% rename from embassy-executor/src/time/driver.rs rename to embassy-time/src/driver.rs index 48e2f1c7..216b2740 100644 --- a/embassy-executor/src/time/driver.rs +++ b/embassy-time/src/driver.rs @@ -1,17 +1,17 @@ //! Time driver interface //! -//! This module defines the interface a driver needs to implement to power the `embassy_executor::time` module. +//! This module defines the interface a driver needs to implement to power the `embassy_time` module. //! //! # Implementing a driver //! //! - Define a struct `MyDriver` //! - Implement [`Driver`] for it //! - Register it as the global driver with [`time_driver_impl`]. -//! - Enable the Cargo features `embassy-executor/time` and one of `embassy-executor/time-tick-*` corresponding to the +//! - Enable the Cargo features `embassy-executor/time` and one of `embassy-time/tick-*` corresponding to the //! tick rate of your driver. //! //! If you wish to make the tick rate configurable by the end user, you should do so by exposing your own -//! Cargo features and having each enable the corresponding `embassy-executor/time-tick-*`. +//! Cargo features and having each enable the corresponding `embassy-time/tick-*`. //! //! # Linkage details //! @@ -34,10 +34,10 @@ //! # Example //! //! ``` -//! use embassy_executor::time::driver::{Driver, AlarmHandle}; +//! use embassy_time::driver::{Driver, AlarmHandle}; //! //! struct MyDriver{}; // not public! -//! embassy_executor::time_driver_impl!(static DRIVER: MyDriver = MyDriver{}); +//! embassy_time::time_driver_impl!(static DRIVER: MyDriver = MyDriver{}); //! //! impl Driver for MyDriver { //! fn now(&self) -> u64 { @@ -121,17 +121,25 @@ extern "Rust" { fn _embassy_time_set_alarm(alarm: AlarmHandle, timestamp: u64); } -pub(crate) fn now() -> u64 { +/// See [`Driver::now`] +pub fn now() -> u64 { unsafe { _embassy_time_now() } } + +/// See [`Driver::allocate_alarm`] +/// /// Safety: it is UB to make the alarm fire before setting a callback. -pub(crate) unsafe fn allocate_alarm() -> Option { +pub unsafe fn allocate_alarm() -> Option { _embassy_time_allocate_alarm() } -pub(crate) fn set_alarm_callback(alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { + +/// See [`Driver::set_alarm_callback`] +pub fn set_alarm_callback(alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { unsafe { _embassy_time_set_alarm_callback(alarm, callback, ctx) } } -pub(crate) fn set_alarm(alarm: AlarmHandle, timestamp: u64) { + +/// See [`Driver::set_alarm`] +pub fn set_alarm(alarm: AlarmHandle, timestamp: u64) { unsafe { _embassy_time_set_alarm(alarm, timestamp) } } @@ -145,26 +153,22 @@ macro_rules! time_driver_impl { #[no_mangle] fn _embassy_time_now() -> u64 { - <$t as $crate::time::driver::Driver>::now(&$name) + <$t as $crate::driver::Driver>::now(&$name) } #[no_mangle] - unsafe fn _embassy_time_allocate_alarm() -> Option<$crate::time::driver::AlarmHandle> { - <$t as $crate::time::driver::Driver>::allocate_alarm(&$name) + unsafe fn _embassy_time_allocate_alarm() -> Option<$crate::driver::AlarmHandle> { + <$t as $crate::driver::Driver>::allocate_alarm(&$name) } #[no_mangle] - fn _embassy_time_set_alarm_callback( - alarm: $crate::time::driver::AlarmHandle, - callback: fn(*mut ()), - ctx: *mut (), - ) { - <$t as $crate::time::driver::Driver>::set_alarm_callback(&$name, alarm, callback, ctx) + fn _embassy_time_set_alarm_callback(alarm: $crate::driver::AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { + <$t as $crate::driver::Driver>::set_alarm_callback(&$name, alarm, callback, ctx) } #[no_mangle] - fn _embassy_time_set_alarm(alarm: $crate::time::driver::AlarmHandle, timestamp: u64) { - <$t as $crate::time::driver::Driver>::set_alarm(&$name, alarm, timestamp) + fn _embassy_time_set_alarm(alarm: $crate::driver::AlarmHandle, timestamp: u64) { + <$t as $crate::driver::Driver>::set_alarm(&$name, alarm, timestamp) } }; } diff --git a/embassy-executor/src/time/driver_std.rs b/embassy-time/src/driver_std.rs similarity index 99% rename from embassy-executor/src/time/driver_std.rs rename to embassy-time/src/driver_std.rs index cb66f7c1..2ddb2e60 100644 --- a/embassy-executor/src/time/driver_std.rs +++ b/embassy-time/src/driver_std.rs @@ -6,7 +6,7 @@ use std::{mem, ptr, thread}; use atomic_polyfill::{AtomicU8, Ordering}; -use crate::time::driver::{AlarmHandle, Driver}; +use crate::driver::{AlarmHandle, Driver}; const ALARM_COUNT: usize = 4; diff --git a/embassy-executor/src/time/driver_wasm.rs b/embassy-time/src/driver_wasm.rs similarity index 98% rename from embassy-executor/src/time/driver_wasm.rs rename to embassy-time/src/driver_wasm.rs index 5f585a19..e4497e6a 100644 --- a/embassy-executor/src/time/driver_wasm.rs +++ b/embassy-time/src/driver_wasm.rs @@ -7,7 +7,7 @@ use atomic_polyfill::{AtomicU8, Ordering}; use wasm_bindgen::prelude::*; use wasm_timer::Instant as StdInstant; -use crate::time::driver::{AlarmHandle, Driver}; +use crate::driver::{AlarmHandle, Driver}; const ALARM_COUNT: usize = 4; diff --git a/embassy-executor/src/time/duration.rs b/embassy-time/src/duration.rs similarity index 100% rename from embassy-executor/src/time/duration.rs rename to embassy-time/src/duration.rs diff --git a/embassy-time/src/fmt.rs b/embassy-time/src/fmt.rs new file mode 100644 index 00000000..06697081 --- /dev/null +++ b/embassy-time/src/fmt.rs @@ -0,0 +1,225 @@ +#![macro_use] +#![allow(unused_macros)] + +#[cfg(all(feature = "defmt", feature = "log"))] +compile_error!("You may not enable both `defmt` and `log` features."); + +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::todo!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::panic!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::panic!($($x)*); + } + }; +} + +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")))] + let _ = ($( & $x ),*); + } + }; +} + +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")))] + let _ = ($( & $x ),*); + } + }; +} + +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")))] + let _ = ($( & $x ),*); + } + }; +} + +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")))] + let _ = ($( & $x ),*); + } + }; +} + +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")))] + let _ = ($( & $x ),*); + } + }; +} + +#[cfg(feature = "defmt")] +macro_rules! unwrap { + ($($x:tt)*) => { + ::defmt::unwrap!($($x)*) + }; +} + +#[cfg(not(feature = "defmt"))] +macro_rules! unwrap { + ($arg:expr) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); + } + } + }; + ($arg:expr, $($msg:expr),+ $(,)? ) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); + } + } + } +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct NoneError; + +pub trait Try { + type Ok; + type Error; + fn into_result(self) -> Result; +} + +impl Try for Option { + type Ok = T; + type Error = NoneError; + + #[inline] + fn into_result(self) -> Result { + self.ok_or(NoneError) + } +} + +impl Try for Result { + type Ok = T; + type Error = E; + + #[inline] + fn into_result(self) -> Self { + self + } +} diff --git a/embassy-executor/src/time/instant.rs b/embassy-time/src/instant.rs similarity index 100% rename from embassy-executor/src/time/instant.rs rename to embassy-time/src/instant.rs diff --git a/embassy-executor/src/time/mod.rs b/embassy-time/src/lib.rs similarity index 75% rename from embassy-executor/src/time/mod.rs rename to embassy-time/src/lib.rs index b787a5cf..a6454d55 100644 --- a/embassy-executor/src/time/mod.rs +++ b/embassy-time/src/lib.rs @@ -1,3 +1,8 @@ +#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] +#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] +#![allow(clippy::new_without_default)] +#![warn(missing_docs)] + //! Timekeeping, delays and timeouts. //! //! Timekeeping is done with elapsed time since system boot. Time is represented in @@ -26,7 +31,7 @@ //! like `2021-08-24 13:33:21`). //! //! If persistence across reboots is not needed, support can be built on top of -//! `embassy_executor::time` by storing the offset between "seconds elapsed since boot" +//! `embassy_time` by storing the offset between "seconds elapsed since boot" //! and "seconds since unix epoch". //! //! # Time driver @@ -35,12 +40,13 @@ //! Only one driver can be active in a program. //! //! All methods and structs transparently call into the active driver. This makes it -//! possible for libraries to use `embassy_executor::time` in a driver-agnostic way without +//! possible for libraries to use `embassy_time` in a driver-agnostic way without //! requiring generic parameters. //! //! For more details, check the [`driver`] module. -#![deny(missing_docs)] +// This mod MUST go first, so that the others see its macros. +pub(crate) mod fmt; mod delay; pub mod driver; @@ -50,7 +56,6 @@ mod timer; #[cfg(feature = "std")] mod driver_std; - #[cfg(feature = "wasm")] mod driver_wasm; @@ -59,24 +64,24 @@ pub use duration::Duration; pub use instant::Instant; pub use timer::{with_timeout, Ticker, TimeoutError, Timer}; -#[cfg(feature = "time-tick-1000hz")] +#[cfg(feature = "tick-1000hz")] const TPS: u64 = 1_000; -#[cfg(feature = "time-tick-32768hz")] +#[cfg(feature = "tick-32768hz")] const TPS: u64 = 32_768; -#[cfg(feature = "time-tick-1mhz")] +#[cfg(feature = "tick-1mhz")] const TPS: u64 = 1_000_000; -#[cfg(feature = "time-tick-16mhz")] +#[cfg(feature = "tick-16mhz")] const TPS: u64 = 16_000_000; /// Ticks per second of the global timebase. /// -/// This value is specified by the `time-tick-*` Cargo features, which +/// This value is specified by the `tick-*` Cargo features, which /// should be set by the time driver. Some drivers support a fixed tick rate, others /// allow you to choose a tick rate with Cargo features of their own. You should not -/// set the `time-tick-*` features for embassy yourself as an end user. +/// set the `tick-*` features for embassy yourself as an end user. pub const TICKS_PER_SECOND: u64 = TPS; const fn gcd(a: u64, b: u64) -> u64 { @@ -89,3 +94,6 @@ const fn gcd(a: u64, b: u64) -> u64 { pub(crate) const GCD_1K: u64 = gcd(TICKS_PER_SECOND, 1_000); pub(crate) const GCD_1M: u64 = gcd(TICKS_PER_SECOND, 1_000_000); + +#[cfg(feature = "defmt-timestamp-uptime")] +defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } diff --git a/embassy-executor/src/time/timer.rs b/embassy-time/src/timer.rs similarity index 88% rename from embassy-executor/src/time/timer.rs rename to embassy-time/src/timer.rs index b9cdb1be..bd791b81 100644 --- a/embassy-executor/src/time/timer.rs +++ b/embassy-time/src/timer.rs @@ -1,12 +1,11 @@ use core::future::Future; use core::pin::Pin; -use core::task::{Context, Poll}; +use core::task::{Context, Poll, Waker}; use futures_util::future::{select, Either}; use futures_util::{pin_mut, Stream}; -use crate::executor::raw; -use crate::time::{Duration, Instant}; +use crate::{Duration, Instant}; /// Error returned by [`with_timeout`] on timeout. #[derive(Debug, Clone, PartialEq, Eq)] @@ -49,7 +48,7 @@ impl Timer { /// # #![feature(type_alias_impl_trait)] /// # /// # fn foo() {} - /// use embassy_executor::time::{Duration, Timer}; + /// use embassy_time::{Duration, Timer}; /// /// #[embassy_executor::task] /// async fn demo_sleep_seconds() { @@ -73,7 +72,7 @@ impl Future for Timer { if self.yielded_once && self.expires_at <= Instant::now() { Poll::Ready(()) } else { - unsafe { raw::register_timer(self.expires_at, cx.waker()) }; + schedule_wake(self.expires_at, cx.waker()); self.yielded_once = true; Poll::Pending } @@ -88,7 +87,7 @@ impl Future for Timer { /// ``` no_run /// # #![feature(type_alias_impl_trait)] /// # -/// use embassy_executor::time::{Duration, Timer}; +/// use embassy_time::{Duration, Timer}; /// # fn foo() {} /// /// #[embassy_executor::task] @@ -108,7 +107,7 @@ impl Future for Timer { /// ``` no_run /// # #![feature(type_alias_impl_trait)] /// # -/// use embassy_executor::time::{Duration, Ticker}; +/// use embassy_time::{Duration, Ticker}; /// use futures::StreamExt; /// # fn foo(){} /// @@ -144,8 +143,16 @@ impl Stream for Ticker { self.expires_at += dur; Poll::Ready(Some(())) } else { - unsafe { raw::register_timer(self.expires_at, cx.waker()) }; + schedule_wake(self.expires_at, cx.waker()); Poll::Pending } } } + +extern "Rust" { + fn _embassy_time_schedule_wake(at: Instant, waker: &Waker); +} + +fn schedule_wake(at: Instant, waker: &Waker) { + unsafe { _embassy_time_schedule_wake(at, waker) } +} diff --git a/embassy-usb-hid/Cargo.toml b/embassy-usb-hid/Cargo.toml index 53b6db3d..5e9cfebf 100644 --- a/embassy-usb-hid/Cargo.toml +++ b/embassy-usb-hid/Cargo.toml @@ -6,10 +6,8 @@ edition = "2021" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-hid-v$VERSION/embassy-usb-hid/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-hid/src/" -features = ["defmt", "embassy-executor/time-tick-1mhz"] -flavors = [ - { name = "default", target = "thumbv7em-none-eabihf" }, -] +features = ["defmt"] +target = "thumbv7em-none-eabi" [features] default = ["usbd-hid"] diff --git a/embassy-usb-ncm/Cargo.toml b/embassy-usb-ncm/Cargo.toml index fa6fa017..47c1f36b 100644 --- a/embassy-usb-ncm/Cargo.toml +++ b/embassy-usb-ncm/Cargo.toml @@ -7,9 +7,7 @@ edition = "2021" src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-ncm-v$VERSION/embassy-usb-ncm/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-ncm/src/" features = ["defmt"] -flavors = [ - { name = "default", target = "thumbv7em-none-eabihf" }, -] +target = "thumbv7em-none-eabi" [dependencies] embassy-util = { version = "0.1.0", path = "../embassy-util" } diff --git a/embassy-usb-serial/Cargo.toml b/embassy-usb-serial/Cargo.toml index 495dd9fe..63361047 100644 --- a/embassy-usb-serial/Cargo.toml +++ b/embassy-usb-serial/Cargo.toml @@ -7,9 +7,7 @@ edition = "2021" src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-serial-v$VERSION/embassy-usb-serial/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb-serial/src/" features = ["defmt"] -flavors = [ - { name = "default", target = "thumbv7em-none-eabihf" }, -] +target = "thumbv7em-none-eabi" [dependencies] embassy-util = { version = "0.1.0", path = "../embassy-util" } diff --git a/embassy-usb/Cargo.toml b/embassy-usb/Cargo.toml index 98734e98..6adbd399 100644 --- a/embassy-usb/Cargo.toml +++ b/embassy-usb/Cargo.toml @@ -7,9 +7,7 @@ edition = "2021" src_base = "https://github.com/embassy-rs/embassy/blob/embassy-usb-v$VERSION/embassy-usb/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-usb/src/" features = ["defmt"] -flavors = [ - { name = "default", target = "thumbv7em-none-eabihf" }, -] +target = "thumbv7em-none-eabi" [dependencies] embassy-util = { version = "0.1.0", path = "../embassy-util" } diff --git a/embassy-util/Cargo.toml b/embassy-util/Cargo.toml index ef5acc0f..d4708d73 100644 --- a/embassy-util/Cargo.toml +++ b/embassy-util/Cargo.toml @@ -7,9 +7,7 @@ edition = "2021" src_base = "https://github.com/embassy-rs/embassy/blob/embassy-util-v$VERSION/embassy-util/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-util/src/" features = ["nightly"] -flavors = [ - { name = "default", target = "x86_64-unknown-linux-gnu" }, -] +target = "thumbv7em-none-eabi" [features] nightly = ["embedded-io/async"] @@ -19,8 +17,8 @@ defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } futures-util = { version = "0.3.17", default-features = false } -atomic-polyfill = "0.1.5" -critical-section = "0.2.5" +atomic-polyfill = "1.0.1" +critical-section = "1.1" heapless = "0.7.5" cfg-if = "1.0.0" embedded-io = "0.3.0" @@ -30,3 +28,6 @@ futures-executor = { version = "0.3.17", features = [ "thread-pool" ] } futures-test = "0.3.17" futures-timer = "3.0.2" futures-util = { version = "0.3.17", features = [ "channel" ] } + +# Enable critical-section implementation for std, for tests +critical-section = { version = "1.1", features = ["std"] } diff --git a/embassy-util/src/channel/signal.rs b/embassy-util/src/channel/signal.rs index a58469c4..05889f5a 100644 --- a/embassy-util/src/channel/signal.rs +++ b/embassy-util/src/channel/signal.rs @@ -69,7 +69,8 @@ impl Signal { }) } - fn poll_wait(&self, cx: &mut Context<'_>) -> Poll { + /// Manually poll the Signal future. + pub fn poll_wait(&self, cx: &mut Context<'_>) -> Poll { critical_section::with(|_| unsafe { let state = &mut *self.state.get(); match state { diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index dd9bcc09..ef934663 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util" } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] } embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,5 +16,5 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 3044645a..bd8fa324 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs @@ -6,15 +6,16 @@ use embassy_boot_nrf::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; use embassy_nrf::nvmc::Nvmc; -use embassy_nrf::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut button = Input::new(p.P0_11, Pull::Up); let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs index 2f76d20c..5394bf0c 100644 --- a/examples/boot/application/nrf/src/bin/b.rs +++ b/examples/boot/application/nrf/src/bin/b.rs @@ -4,13 +4,14 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index 313808a0..27eafa65 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index fd18e937..11eecc5e 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs @@ -6,16 +6,17 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32f3/src/bin/b.rs b/examples/boot/application/stm32f3/src/bin/b.rs index 934f862d..a5862b1b 100644 --- a/examples/boot/application/stm32f3/src/bin/b.rs +++ b/examples/boot/application/stm32f3/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PA5, Level::High, Speed::Low); loop { diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index 2a4741dc..7de0b82d 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index 10d709cf..a3b66e7c 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs @@ -6,16 +6,17 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32f7/src/bin/b.rs b/examples/boot/application/stm32f7/src/bin/b.rs index c89e8a31..16c94d84 100644 --- a/examples/boot/application/stm32f7/src/bin/b.rs +++ b/examples/boot/application/stm32f7/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); Timer::after(Duration::from_millis(300)).await; let mut led = Output::new(p.PB7, Level::High, Speed::Low); led.set_high(); diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index c6420e8a..65d34c70 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index cc363bb3..0ecf6034 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs @@ -6,16 +6,17 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32h7/src/bin/b.rs b/examples/boot/application/stm32h7/src/bin/b.rs index 3fa63bdc..34799279 100644 --- a/examples/boot/application/stm32h7/src/bin/b.rs +++ b/examples/boot/application/stm32h7/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); Timer::after(Duration::from_millis(300)).await; let mut led = Output::new(p.PB14, Level::High, Speed::Low); led.set_high(); diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index a6936419..8f37869e 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs index fcf3f2ef..f4f1d711 100644 --- a/examples/boot/application/stm32l0/src/bin/a.rs +++ b/examples/boot/application/stm32l0/src/bin/a.rs @@ -6,17 +6,18 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32l0/src/bin/b.rs b/examples/boot/application/stm32l0/src/bin/b.rs index 46e394c4..ee40274f 100644 --- a/examples/boot/application/stm32l0/src/bin/b.rs +++ b/examples/boot/application/stm32l0/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB6, Level::High, Speed::Low); loop { diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index 5e53cd5f..6abf1986 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index fcf3f2ef..f4f1d711 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs @@ -6,17 +6,18 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32l1/src/bin/b.rs b/examples/boot/application/stm32l1/src/bin/b.rs index 46e394c4..ee40274f 100644 --- a/examples/boot/application/stm32l1/src/bin/b.rs +++ b/examples/boot/application/stm32l1/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB6, Level::High, Speed::Low); loop { diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index bbb5e7e1..6f2d12ff 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index f092f023..178b2e04 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs @@ -6,16 +6,17 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32l4/src/bin/b.rs b/examples/boot/application/stm32l4/src/bin/b.rs index 934f862d..a5862b1b 100644 --- a/examples/boot/application/stm32l4/src/bin/b.rs +++ b/examples/boot/application/stm32l4/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PA5, Level::High, Speed::Low); loop { diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index 62123a87..be97d4eb 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } @@ -15,7 +16,7 @@ defmt-rtt = { version = "0.3", optional = true } panic-reset = { version = "0.1.1" } embedded-hal = { version = "0.2.6" } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" [features] diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index 14408a90..c71a4265 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs @@ -6,16 +6,17 @@ use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::flash::Flash; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy_executor::main] -async fn main(_s: embassy_executor::executor::Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let flash = Flash::unlock(p.FLASH); let mut flash = BlockingAsync::new(flash); diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs index e565fd7c..f9f0ffc6 100644 --- a/examples/boot/application/stm32wl/src/bin/b.rs +++ b/examples/boot/application/stm32wl/src/bin/b.rs @@ -4,14 +4,14 @@ #[cfg(feature = "defmt-rtt")] use defmt_rtt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use panic_reset as _; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB15, Level::High, Speed::Low); loop { diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index 9683bff1..aa2a13ec 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml @@ -10,7 +10,7 @@ defmt-rtt = { version = "0.3", optional = true } embassy-nrf = { path = "../../../../embassy-nrf", default-features = false, features = ["nightly"] } embassy-boot-nrf = { path = "../../../../embassy-boot/nrf", default-features = false } -cortex-m = { version = "0.7" } +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = { version = "0.7" } cfg-if = "1.0.0" diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index 4a331952..49177710 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml @@ -10,7 +10,7 @@ defmt-rtt = { version = "0.3", optional = true } embassy-stm32 = { path = "../../../../embassy-stm32", default-features = false, features = ["nightly"] } embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32", default-features = false } -cortex-m = { version = "0.7" } +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = { version = "0.7" } embedded-storage = "0.3.0" embedded-storage-async = "0.3.0" diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml index 9c749a38..dad74235 100644 --- a/examples/nrf-rtos-trace/Cargo.toml +++ b/examples/nrf-rtos-trace/Cargo.toml @@ -5,38 +5,26 @@ version = "0.1.0" [features] default = ["log", "nightly"] -nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] +nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits"] log = [ "dep:log", "embassy-util/log", "embassy-executor/log", + "embassy-time/log", "embassy-nrf/log", - "embassy-net/log", - "embassy-usb-ncm/log", - # Currently broken: - # "embassy-usb/log", - # "embassy-usb-serial/log", - # "embassy-usb-hid/log", ] [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util" } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time" } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } -embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } -embassy-usb = { version = "0.1.0", path = "../../embassy-usb", optional = true } -embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", optional = true } -embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", optional = true } -embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", optional = true } -embedded-io = "0.3.0" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" panic-probe = { version = "0.3" } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } rand = { version = "0.8.4", default-features = false } -embedded-storage = "0.3.0" -usbd-hid = "0.5.2" serde = { version = "1.0.136", default-features = false } rtos-trace = "0.1.3" systemview-target = { version = "0.1.1", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } diff --git a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs index 5699fe8e..7d1ad87c 100644 --- a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs +++ b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs @@ -4,9 +4,8 @@ use core::task::Poll; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Instant, Timer}; -use embassy_nrf::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Instant, Timer}; #[cfg(feature = "log")] use log::*; use panic_probe as _; @@ -55,7 +54,8 @@ async fn run3() { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); LOGGER.init(); #[cfg(feature = "log")] { diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 91edbd36..2fcc3122 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -9,7 +9,8 @@ nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unsta [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } @@ -21,7 +22,7 @@ embedded-io = "0.3.0" defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf/src/bin/awaitable_timer.rs index f2c1d9fa..b32af236 100644 --- a/examples/nrf/src/bin/awaitable_timer.rs +++ b/examples/nrf/src/bin/awaitable_timer.rs @@ -3,13 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::timer::Timer; -use embassy_nrf::{interrupt, Peripherals}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0)); // default frequency is 1MHz, so this triggers every second t.cc(0).write(1_000_000); diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs index 98db6546..513f6cd8 100644 --- a/examples/nrf/src/bin/blinky.rs +++ b/examples/nrf/src/bin/blinky.rs @@ -2,14 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); loop { diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index f02b7d84..ea566f4b 100644 --- a/examples/nrf/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs @@ -3,15 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::buffered_uarte::{BufferedUarte, State}; -use embassy_nrf::{interrupt, uarte, Peripherals}; +use embassy_nrf::{interrupt, uarte}; use embedded_io::asynch::{BufRead, Write}; use futures::pin_mut; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut config = uarte::Config::default(); config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs index e97c6c5e..19520098 100644 --- a/examples/nrf/src/bin/channel.rs +++ b/examples/nrf/src/bin/channel.rs @@ -3,10 +3,9 @@ #![feature(type_alias_impl_trait)] use defmt::unwrap; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::mpmc::Channel; use {defmt_rtt as _, panic_probe as _}; @@ -29,7 +28,8 @@ async fn my_task() { } #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); unwrap!(spawner.spawn(my_task())); diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs index bca7bb24..c9c458ae 100644 --- a/examples/nrf/src/bin/channel_sender_receiver.rs +++ b/examples/nrf/src/bin/channel_sender_receiver.rs @@ -3,10 +3,9 @@ #![feature(type_alias_impl_trait)] use defmt::unwrap; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use embassy_util::blocking_mutex::raw::NoopRawMutex; use embassy_util::channel::mpmc::{Channel, Receiver, Sender}; use embassy_util::Forever; @@ -42,7 +41,8 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta } #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let channel = CHANNEL.put(Channel::new()); unwrap!(spawner.spawn(send_task(channel.sender()))); diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs index b9845493..9ae030d0 100644 --- a/examples/nrf/src/bin/executor_fairness_test.rs +++ b/examples/nrf/src/bin/executor_fairness_test.rs @@ -5,9 +5,8 @@ use core::task::Poll; use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Instant, Timer}; -use embassy_nrf::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Instant, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -35,7 +34,8 @@ async fn run3() { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); unwrap!(spawner.spawn(run1())); unwrap!(spawner.spawn(run2())); unwrap!(spawner.spawn(run3())); diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs index 65c7b4df..5bfd0246 100644 --- a/examples/nrf/src/bin/gpiote_channel.rs +++ b/examples/nrf/src/bin/gpiote_channel.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; -use embassy_nrf::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("Starting!"); let ch1 = InputChannel::new( diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs index 7746a7f9..0155d539 100644 --- a/examples/nrf/src/bin/gpiote_port.rs +++ b/examples/nrf/src/bin/gpiote_port.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; -use embassy_nrf::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task(pool_size = 4)] @@ -19,7 +18,8 @@ async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { } #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("Starting!"); let btn1 = Input::new(p.P0_11.degrade(), Pull::Up); diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index 7050da37..b653689a 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs @@ -59,10 +59,10 @@ use cortex_m_rt::entry; use defmt::{info, unwrap}; -use embassy_executor::time::{Duration, Instant, Timer}; use embassy_nrf::executor::{Executor, InterruptExecutor}; use embassy_nrf::interrupt; use embassy_nrf::interrupt::InterruptExt; +use embassy_time::{Duration, Instant, Timer}; use embassy_util::Forever; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs index 5fe7eadb..87629788 100644 --- a/examples/nrf/src/bin/mutex.rs +++ b/examples/nrf/src/bin/mutex.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_nrf::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::mutex::Mutex; use {defmt_rtt as _, panic_probe as _}; @@ -30,7 +29,8 @@ async fn my_task() { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); unwrap!(spawner.spawn(my_task())); loop { diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf/src/bin/nvmc.rs index 1d4387de..75d090fb 100644 --- a/examples/nrf/src/bin/nvmc.rs +++ b/examples/nrf/src/bin/nvmc.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::nvmc::Nvmc; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("Hello NVMC!"); // probe-run breaks without this, I'm not sure why. diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs index 9a60cc0a..d74ce406 100644 --- a/examples/nrf/src/bin/ppi.rs +++ b/examples/nrf/src/bin/ppi.rs @@ -5,16 +5,16 @@ use core::future::pending; use defmt::info; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; use embassy_nrf::ppi::Ppi; -use embassy_nrf::Peripherals; use gpiote::{OutputChannel, OutputChannelPolarity}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("Starting!"); let button1 = InputChannel::new( diff --git a/examples/nrf/src/bin/pubsub.rs b/examples/nrf/src/bin/pubsub.rs index 5f33f3e0..1d90217f 100644 --- a/examples/nrf/src/bin/pubsub.rs +++ b/examples/nrf/src/bin/pubsub.rs @@ -3,8 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::unwrap; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::pubsub::{DynSubscriber, PubSubChannel, Subscriber}; use {defmt_rtt as _, panic_probe as _}; @@ -20,7 +20,8 @@ enum Message { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: embassy_nrf::Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); defmt::info!("Hello World!"); // It's good to set up the subscribers before publishing anything. diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs index c8a08329..1698c0bc 100644 --- a/examples/nrf/src/bin/pwm.rs +++ b/examples/nrf/src/bin/pwm.rs @@ -3,10 +3,9 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::pwm::{Prescaler, SimplePwm}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; // for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') @@ -71,7 +70,8 @@ static DUTY: [u16; 1024] = [ ]; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut pwm = SimplePwm::new_4ch(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15); pwm.set_prescaler(Prescaler::Div1); pwm.set_max_duty(32767); diff --git a/examples/nrf/src/bin/pwm_double_sequence.rs b/examples/nrf/src/bin/pwm_double_sequence.rs index cfd8db86..16e50e90 100644 --- a/examples/nrf/src/bin/pwm_double_sequence.rs +++ b/examples/nrf/src/bin/pwm_double_sequence.rs @@ -3,16 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::pwm::{ Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, StartSequence, }; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let seq_words_0: [u16; 5] = [1000, 250, 100, 50, 0]; let seq_words_1: [u16; 4] = [50, 100, 250, 1000]; diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index b7a04c03..b9aca9aa 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let seq_words: [u16; 5] = [1000, 250, 100, 50, 0]; let mut config = Config::default(); diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs index f5c587c3..6594fa34 100644 --- a/examples/nrf/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs @@ -5,16 +5,16 @@ use core::future::pending; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; use embassy_nrf::ppi::Ppi; use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; -use embassy_nrf::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let seq_words: [u16; 5] = [1000, 250, 100, 50, 0]; let mut config = Config::default(); diff --git a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs index d6b3f005..711c8a17 100644 --- a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs +++ b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::pwm::{ Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, SingleSequencer, }; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; // WS2812B LED light demonstration. Drives just one light. @@ -27,7 +26,8 @@ const RES: u16 = 0x8000; // Provides data to a WS2812b (Neopixel) LED and makes it go blue. The data // line is assumed to be P1_05. #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut config = Config::default(); config.sequence_load = SequenceLoad::Common; config.prescaler = Prescaler::Div1; diff --git a/examples/nrf/src/bin/pwm_servo.rs b/examples/nrf/src/bin/pwm_servo.rs index d28a5a17..19228f43 100644 --- a/examples/nrf/src/bin/pwm_servo.rs +++ b/examples/nrf/src/bin/pwm_servo.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::pwm::{Prescaler, SimplePwm}; -use embassy_nrf::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut pwm = SimplePwm::new_1ch(p.PWM0, p.P0_05); // sg90 microervo requires 50hz or 20ms period // set_period can only set down to 125khz so we cant use it directly diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs index 6bda82f7..600bba07 100644 --- a/examples/nrf/src/bin/qdec.rs +++ b/examples/nrf/src/bin/qdec.rs @@ -3,13 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::qdec::{self, Qdec}; -use embassy_nrf::{interrupt, Peripherals}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let irq = interrupt::take!(QDEC); let config = qdec::Config::default(); let mut rotary_enc = Qdec::new(p.QDEC, irq, p.P0_31, p.P0_30, config); diff --git a/examples/nrf/src/bin/qspi.rs b/examples/nrf/src/bin/qspi.rs index 57e0fdbe..bdcf710b 100644 --- a/examples/nrf/src/bin/qspi.rs +++ b/examples/nrf/src/bin/qspi.rs @@ -3,8 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{assert_eq, info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_nrf::{interrupt, qspi, Peripherals}; +use embassy_executor::Spawner; +use embassy_nrf::{interrupt, qspi}; use {defmt_rtt as _, panic_probe as _}; const PAGE_SIZE: usize = 4096; @@ -15,7 +15,8 @@ const PAGE_SIZE: usize = 4096; struct AlignedBuf([u8; 4096]); #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); // Config for the MX25R64 present in the nRF52840 DK let mut config = qspi::Config::default(); config.read_opcode = qspi::ReadOpcode::READ4IO; diff --git a/examples/nrf/src/bin/qspi_lowpower.rs b/examples/nrf/src/bin/qspi_lowpower.rs index 080b27a1..9341a237 100644 --- a/examples/nrf/src/bin/qspi_lowpower.rs +++ b/examples/nrf/src/bin/qspi_lowpower.rs @@ -5,9 +5,9 @@ use core::mem; use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_nrf::{interrupt, qspi, Peripherals}; +use embassy_executor::Spawner; +use embassy_nrf::{interrupt, qspi}; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; // Workaround for alignment requirements. @@ -16,7 +16,8 @@ use {defmt_rtt as _, panic_probe as _}; struct AlignedBuf([u8; 64]); #[embassy_executor::main] -async fn main(_spawner: Spawner, mut p: Peripherals) { +async fn main(_p: Spawner) { + let mut p = embassy_nrf::init(Default::default()); let mut irq = interrupt::take!(QSPI); loop { diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs index 9199d3ae..415579be 100644 --- a/examples/nrf/src/bin/raw_spawn.rs +++ b/examples/nrf/src/bin/raw_spawn.rs @@ -5,9 +5,9 @@ use core::mem; use cortex_m_rt::entry; use defmt::{info, unwrap}; -use embassy_executor::executor::raw::TaskStorage; -use embassy_executor::executor::Executor; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::raw::TaskStorage; +use embassy_executor::Executor; +use embassy_time::{Duration, Timer}; use embassy_util::Forever; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/nrf/src/bin/rng.rs b/examples/nrf/src/bin/rng.rs index a4314e8b..64707394 100644 --- a/examples/nrf/src/bin/rng.rs +++ b/examples/nrf/src/bin/rng.rs @@ -2,14 +2,15 @@ #![no_main] #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::rng::Rng; -use embassy_nrf::{interrupt, Peripherals}; use rand::Rng as _; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut rng = Rng::new(p.RNG, interrupt::take!(RNG)); // Async API diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs index 65c78d84..7cf58809 100644 --- a/examples/nrf/src/bin/saadc.rs +++ b/examples/nrf/src/bin/saadc.rs @@ -3,14 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; -use embassy_nrf::{interrupt, Peripherals}; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, mut p: Peripherals) { +async fn main(_p: Spawner) { + let mut p = embassy_nrf::init(Default::default()); let config = Config::default(); let channel_config = ChannelConfig::single_ended(&mut p.P0_02); let mut saadc = Saadc::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]); diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf/src/bin/saadc_continuous.rs index d0305736..bb50ac65 100644 --- a/examples/nrf/src/bin/saadc_continuous.rs +++ b/examples/nrf/src/bin/saadc_continuous.rs @@ -3,17 +3,18 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::Duration; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState}; use embassy_nrf::timer::Frequency; -use embassy_nrf::{interrupt, Peripherals}; +use embassy_time::Duration; use {defmt_rtt as _, panic_probe as _}; // Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer #[embassy_executor::main] -async fn main(_spawner: Spawner, mut p: Peripherals) { +async fn main(_p: Spawner) { + let mut p = embassy_nrf::init(Default::default()); let config = Config::default(); let channel_1_config = ChannelConfig::single_ended(&mut p.P0_02); let channel_2_config = ChannelConfig::single_ended(&mut p.P0_03); @@ -27,7 +28,7 @@ async fn main(_spawner: Spawner, mut p: Peripherals) { // This delay demonstrates that starting the timer prior to running // the task sampler is benign given the calibration that follows. - embassy_executor::time::Timer::after(Duration::from_millis(500)).await; + embassy_time::Timer::after(Duration::from_millis(500)).await; saadc.calibrate().await; let mut bufs = [[[0; 3]; 500]; 2]; diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf/src/bin/self_spawn.rs index e0152802..196255a5 100644 --- a/examples/nrf/src/bin/self_spawn.rs +++ b/examples/nrf/src/bin/self_spawn.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_nrf::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task(pool_size = 2)] @@ -16,7 +15,8 @@ async fn my_task(spawner: Spawner, n: u32) { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); info!("Hello World!"); unwrap!(spawner.spawn(my_task(spawner, 0))); } diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf/src/bin/self_spawn_current_executor.rs index 1d8309d7..8a179886 100644 --- a/examples/nrf/src/bin/self_spawn_current_executor.rs +++ b/examples/nrf/src/bin/self_spawn_current_executor.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_nrf::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task(pool_size = 2)] @@ -16,7 +15,8 @@ async fn my_task(n: u32) { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); info!("Hello World!"); unwrap!(spawner.spawn(my_task(0))); } diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs index fd741b21..132e0166 100644 --- a/examples/nrf/src/bin/spim.rs +++ b/examples/nrf/src/bin/spim.rs @@ -3,13 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::{interrupt, spim, Peripherals}; +use embassy_nrf::{interrupt, spim}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("running!"); let mut config = spim::Config::default(); diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs index 654098e0..b06ac709 100644 --- a/examples/nrf/src/bin/temp.rs +++ b/examples/nrf/src/bin/temp.rs @@ -3,14 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::temp::Temp; -use embassy_nrf::{interrupt, Peripherals}; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let irq = interrupt::take!(TEMP); let mut temp = Temp::new(p.TEMP, irq); diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs index 61ff1d6d..c22b5acd 100644 --- a/examples/nrf/src/bin/timer.rs +++ b/examples/nrf/src/bin/timer.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_nrf::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -25,7 +24,8 @@ async fn run2() { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_nrf::init(Default::default()); unwrap!(spawner.spawn(run1())); unwrap!(spawner.spawn(run2())); } diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs index bb7ee9db..a027cc1e 100644 --- a/examples/nrf/src/bin/twim.rs +++ b/examples/nrf/src/bin/twim.rs @@ -7,15 +7,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::twim::{self, Twim}; -use embassy_nrf::{interrupt, Peripherals}; use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x50; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("Initializing TWI..."); let config = twim::Config::default(); let irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); diff --git a/examples/nrf/src/bin/twim_lowpower.rs b/examples/nrf/src/bin/twim_lowpower.rs index ebf3d710..e30cc968 100644 --- a/examples/nrf/src/bin/twim_lowpower.rs +++ b/examples/nrf/src/bin/twim_lowpower.rs @@ -11,16 +11,17 @@ use core::mem; use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_nrf::interrupt; use embassy_nrf::twim::{self, Twim}; -use embassy_nrf::{interrupt, Peripherals}; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x50; #[embassy_executor::main] -async fn main(_spawner: Spawner, mut p: Peripherals) { +async fn main(_p: Spawner) { + let mut p = embassy_nrf::init(Default::default()); info!("Started!"); let mut irq = interrupt::take!(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); diff --git a/examples/nrf/src/bin/uart.rs b/examples/nrf/src/bin/uart.rs index 5f363b69..600f7a6e 100644 --- a/examples/nrf/src/bin/uart.rs +++ b/examples/nrf/src/bin/uart.rs @@ -3,12 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_nrf::{interrupt, uarte, Peripherals}; +use embassy_executor::Spawner; +use embassy_nrf::{interrupt, uarte}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut config = uarte::Config::default(); config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs index 0f455dff..09ec624c 100644 --- a/examples/nrf/src/bin/uart_idle.rs +++ b/examples/nrf/src/bin/uart_idle.rs @@ -3,12 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_nrf::{interrupt, uarte, Peripherals}; +use embassy_executor::Spawner; +use embassy_nrf::{interrupt, uarte}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut config = uarte::Config::default(); config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs index 2de5f90c..dab8e475 100644 --- a/examples/nrf/src/bin/uart_split.rs +++ b/examples/nrf/src/bin/uart_split.rs @@ -3,10 +3,10 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::peripherals::UARTE0; use embassy_nrf::uarte::UarteRx; -use embassy_nrf::{interrupt, uarte, Peripherals}; +use embassy_nrf::{interrupt, uarte}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::mpmc::Channel; use {defmt_rtt as _, panic_probe as _}; @@ -14,7 +14,8 @@ use {defmt_rtt as _, panic_probe as _}; static CHANNEL: Channel = Channel::new(); #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let mut config = uarte::Config::default(); config.parity = uarte::Parity::EXCLUDED; config.baudrate = uarte::Baudrate::BAUD115200; diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index 93cb0590..f0a87031 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs @@ -8,12 +8,12 @@ use core::sync::atomic::{AtomicBool, Ordering}; use core::task::Waker; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; use embassy_nrf::rng::Rng; use embassy_nrf::usb::{Driver, PowerUsb}; -use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; +use embassy_nrf::{interrupt, pac, peripherals}; use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; @@ -82,7 +82,8 @@ async fn net_task(stack: &'static Stack) -> ! { } #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let clock: pac::CLOCK = unsafe { mem::transmute(()) }; info!("Enabling ext hfosc..."); diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index 863f3e5d..cf0078ee 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs @@ -7,10 +7,10 @@ use core::mem; use core::sync::atomic::{AtomicBool, Ordering}; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Input, Pin, Pull}; use embassy_nrf::usb::{Driver, PowerUsb}; -use embassy_nrf::{interrupt, pac, Peripherals}; +use embassy_nrf::{interrupt, pac}; use embassy_usb::control::OutResponse; use embassy_usb::{Builder, Config, DeviceStateHandler}; use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; @@ -23,7 +23,8 @@ use {defmt_rtt as _, panic_probe as _}; static SUSPENDED: AtomicBool = AtomicBool::new(false); #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let clock: pac::CLOCK = unsafe { mem::transmute(()) }; info!("Enabling ext hfosc..."); diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs index 88bf87bd..7cd2ece1 100644 --- a/examples/nrf/src/bin/usb_hid_mouse.rs +++ b/examples/nrf/src/bin/usb_hid_mouse.rs @@ -6,10 +6,10 @@ use core::mem; use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_nrf::usb::{Driver, PowerUsb}; -use embassy_nrf::{interrupt, pac, Peripherals}; +use embassy_nrf::{interrupt, pac}; +use embassy_time::{Duration, Timer}; use embassy_usb::control::OutResponse; use embassy_usb::{Builder, Config}; use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; @@ -18,7 +18,8 @@ use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let clock: pac::CLOCK = unsafe { mem::transmute(()) }; info!("Enabling ext hfosc..."); diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs index 7d233d24..a68edb32 100644 --- a/examples/nrf/src/bin/usb_serial.rs +++ b/examples/nrf/src/bin/usb_serial.rs @@ -6,9 +6,9 @@ use core::mem; use defmt::{info, panic}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::usb::{Driver, Instance, PowerUsb, UsbSupply}; -use embassy_nrf::{interrupt, pac, Peripherals}; +use embassy_nrf::{interrupt, pac}; use embassy_usb::driver::EndpointError; use embassy_usb::{Builder, Config}; use embassy_usb_serial::{CdcAcmClass, State}; @@ -16,7 +16,8 @@ use futures::future::join; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let clock: pac::CLOCK = unsafe { mem::transmute(()) }; info!("Enabling ext hfosc..."); diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 95631532..4c1a9308 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs @@ -6,9 +6,9 @@ use core::mem; use defmt::{info, panic, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::usb::{Driver, PowerUsb}; -use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; +use embassy_nrf::{interrupt, pac, peripherals}; use embassy_usb::driver::EndpointError; use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb_serial::{CdcAcmClass, State}; @@ -33,7 +33,8 @@ async fn echo_task(mut class: CdcAcmClass<'static, MyDriver>) { } #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); let clock: pac::CLOCK = unsafe { mem::transmute(()) }; info!("Enabling ext hfosc..."); diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs index 560cb356..b0b9c3b8 100644 --- a/examples/nrf/src/bin/wdt.rs +++ b/examples/nrf/src/bin/wdt.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::wdt::{Config, Watchdog}; -use embassy_nrf::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_nrf::init(Default::default()); info!("Hello World!"); let mut config = Config::default(); diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 94c3d801..c2dcf429 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -6,14 +6,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] } -atomic-polyfill = "0.1.5" defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs index e53fca1a..7aa36a19 100644 --- a/examples/rp/src/bin/blinky.rs +++ b/examples/rp/src/bin/blinky.rs @@ -3,14 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_rp::{gpio, Peripherals}; +use embassy_executor::Spawner; +use embassy_rp::gpio; +use embassy_time::{Duration, Timer}; use gpio::{Level, Output}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); let mut led = Output::new(p.PIN_25, Level::Low); loop { diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index 02cbc941..c5422c61 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs @@ -2,13 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_rp::gpio::{Input, Level, Output, Pull}; -use embassy_rp::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); let button = Input::new(p.PIN_28, Pull::Up); let mut led = Output::new(p.PIN_25, Level::Low); diff --git a/examples/rp/src/bin/gpio_async.rs b/examples/rp/src/bin/gpio_async.rs index ba905b01..52d13a9d 100644 --- a/examples/rp/src/bin/gpio_async.rs +++ b/examples/rp/src/bin/gpio_async.rs @@ -3,9 +3,9 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_rp::{gpio, Peripherals}; +use embassy_executor::Spawner; +use embassy_rp::gpio; +use embassy_time::{Duration, Timer}; use gpio::{Input, Level, Output, Pull}; use {defmt_rtt as _, panic_probe as _}; @@ -20,7 +20,8 @@ use {defmt_rtt as _, panic_probe as _}; /// continue and turn off the LED, and then wait for 2 seconds before completing /// the loop and starting over again. #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); let mut led = Output::new(p.PIN_25, Level::Low); let mut async_input = Input::new(p.PIN_16, Pull::None); diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs index a3160c10..88003ee1 100644 --- a/examples/rp/src/bin/spi.rs +++ b/examples/rp/src/bin/spi.rs @@ -3,14 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_rp::spi::Spi; -use embassy_rp::{gpio, spi, Peripherals}; +use embassy_rp::{gpio, spi}; use gpio::{Level, Output}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); info!("Hello World!"); // Example for resistive touch sensor in Waveshare Pico-ResTouch diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs index 2760b23f..f0e54d87 100644 --- a/examples/rp/src/bin/spi_display.rs +++ b/examples/rp/src/bin/spi_display.rs @@ -5,11 +5,11 @@ use core::cell::RefCell; use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::Delay; +use embassy_executor::Spawner; use embassy_rp::gpio::{Level, Output}; +use embassy_rp::spi; use embassy_rp::spi::Spi; -use embassy_rp::{spi, Peripherals}; +use embassy_time::Delay; use embedded_graphics::image::{Image, ImageRawLE}; use embedded_graphics::mono_font::ascii::FONT_10X20; use embedded_graphics::mono_font::MonoTextStyle; @@ -28,7 +28,8 @@ use crate::touch::Touch; const TOUCH_FREQ: u32 = 200_000; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); info!("Hello World!"); let bl = p.PIN_13; diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs index 0d295489..c63b31ca 100644 --- a/examples/rp/src/bin/uart.rs +++ b/examples/rp/src/bin/uart.rs @@ -2,18 +2,19 @@ #![no_main] #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; -use embassy_rp::{uart, Peripherals}; +use embassy_executor::Spawner; +use embassy_rp::uart; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); let config = uart::Config::default(); - let mut uart = uart::Uart::new(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config); - uart.send("Hello World!\r\n".as_bytes()); + let mut uart = uart::Uart::new_with_rtscts(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config); + uart.blocking_write("Hello World!\r\n".as_bytes()).unwrap(); loop { - uart.send("hello there!\r\n".as_bytes()); + uart.blocking_write("hello there!\r\n".as_bytes()).unwrap(); cortex_m::asm::delay(1_000_000); } } diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 54499796..b7009017 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -5,9 +5,11 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "time", "nightly"] } -embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "dhcpv4", "pool-16"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] } +embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] } embedded-io = { version = "0.3.0", features = ["async", "std", "futures"] } +critical-section = { version = "1.1", features = ["std"] } async-io = "1.6.0" env_logger = "0.9.0" diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 20258528..52860926 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -1,7 +1,7 @@ #![feature(type_alias_impl_trait)] use clap::Parser; -use embassy_executor::executor::{Executor, Spawner}; +use embassy_executor::{Executor, Spawner}; use embassy_net::tcp::TcpSocket; use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; use embassy_util::Forever; diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs new file mode 100644 index 00000000..07e11c38 --- /dev/null +++ b/examples/std/src/bin/net_udp.rs @@ -0,0 +1,109 @@ +#![feature(type_alias_impl_trait)] + +use clap::Parser; +use embassy_executor::{Executor, Spawner}; +use embassy_net::udp::UdpSocket; +use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; +use embassy_util::Forever; +use heapless::Vec; +use log::*; +use rand_core::{OsRng, RngCore}; + +#[path = "../tuntap.rs"] +mod tuntap; + +use crate::tuntap::TunTapDevice; + +macro_rules! forever { + ($val:expr) => {{ + type T = impl Sized; + static FOREVER: Forever = Forever::new(); + FOREVER.put_with(move || $val) + }}; +} + +#[derive(Parser)] +#[clap(version = "1.0")] +struct Opts { + /// TAP device name + #[clap(long, default_value = "tap0")] + tap: String, + /// use a static IP instead of DHCP + #[clap(long)] + static_ip: bool, +} + +#[embassy_executor::task] +async fn net_task(stack: &'static Stack) -> ! { + stack.run().await +} + +#[embassy_executor::task] +async fn main_task(spawner: Spawner) { + let opts: Opts = Opts::parse(); + + // Init network device + let device = TunTapDevice::new(&opts.tap).unwrap(); + + // Choose between dhcp or static ip + let config = if opts.static_ip { + ConfigStrategy::Static(embassy_net::Config { + address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), + dns_servers: Vec::new(), + gateway: Some(Ipv4Address::new(192, 168, 69, 1)), + }) + } else { + ConfigStrategy::Dhcp + }; + + // Generate random seed + let mut seed = [0; 8]; + OsRng.fill_bytes(&mut seed); + let seed = u64::from_le_bytes(seed); + + // Init network stack + let stack = &*forever!(Stack::new( + device, + config, + forever!(StackResources::<1, 2, 8>::new()), + seed + )); + + // Launch network task + spawner.spawn(net_task(stack)).unwrap(); + + // Then we can use it! + let mut rx_meta = [PacketMetadata::EMPTY; 16]; + let mut rx_buffer = [0; 4096]; + let mut tx_meta = [PacketMetadata::EMPTY; 16]; + let mut tx_buffer = [0; 4096]; + let mut buf = [0; 4096]; + + let mut socket = UdpSocket::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer); + socket.bind(9400).unwrap(); + + loop { + let (n, ep) = socket.recv_from(&mut buf).await.unwrap(); + if let Ok(s) = core::str::from_utf8(&buf[..n]) { + info!("ECHO (to {}): {}", ep, s); + } else { + info!("ECHO (to {}): bytearray len {}", ep, n); + } + socket.send_to(&buf[..n], ep).await.unwrap(); + } +} + +static EXECUTOR: Forever = Forever::new(); + +fn main() { + env_logger::builder() + .filter_level(log::LevelFilter::Debug) + .filter_module("async_io", log::LevelFilter::Info) + .format_timestamp_nanos() + .init(); + + let executor = EXECUTOR.put(Executor::new()); + executor.run(|spawner| { + spawner.spawn(main_task(spawner)).unwrap(); + }); +} diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs index b803d1ef..35cba4ce 100644 --- a/examples/std/src/bin/serial.rs +++ b/examples/std/src/bin/serial.rs @@ -4,7 +4,7 @@ mod serial_port; use async_io::Async; -use embassy_executor::executor::Executor; +use embassy_executor::Executor; use embassy_util::Forever; use embedded_io::asynch::Read; use log::*; diff --git a/examples/std/src/bin/tick.rs b/examples/std/src/bin/tick.rs index 9ca900df..b9de9d87 100644 --- a/examples/std/src/bin/tick.rs +++ b/examples/std/src/bin/tick.rs @@ -1,7 +1,7 @@ #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use log::*; #[embassy_executor::task] diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index 3ba29763..8476200d 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml @@ -6,12 +6,13 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" defmt = "0.3" defmt-rtt = "0.3" panic-probe = "0.3" embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] } diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs index c9081ea1..db78233e 100644 --- a/examples/stm32f0/src/bin/hello.rs +++ b/examples/stm32f0/src/bin/hello.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_stm32::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, _p: Peripherals) -> ! { +async fn main(_spawner: Spawner) -> ! { + let _p = embassy_stm32::init(Default::default()); loop { Timer::after(Duration::from_secs(1)).await; info!("Hello"); diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml index 9ce553b6..fbc96400 100644 --- a/examples/stm32f1/Cargo.toml +++ b/examples/stm32f1/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } @@ -13,7 +14,7 @@ embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", fea defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs index e54593fe..2d6b4a0e 100644 --- a/examples/stm32f1/src/bin/adc.rs +++ b/examples/stm32f1/src/bin/adc.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Delay, Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::adc::Adc; -use embassy_stm32::Peripherals; +use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut adc = Adc::new(p.ADC1, &mut Delay); diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs index 5171043e..b9b0ac23 100644 --- a/examples/stm32f1/src/bin/blinky.rs +++ b/examples/stm32f1/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PC13, Level::High, Speed::Low); diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index 549d1bfb..180b6aab 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs @@ -3,20 +3,18 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::time::Hertz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(Hertz(36_000_000)); - config -} + let _p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, _p: Peripherals) -> ! { loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index cf7facb7..a9c46068 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs @@ -3,28 +3,26 @@ #![feature(type_alias_impl_trait)] use defmt::{panic, *}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::time::Hertz; use embassy_stm32::usb::{Driver, Instance}; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; +use embassy_time::{Duration, Timer}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.hse = Some(Hertz(8_000_000)); config.rcc.sys_ck = Some(Hertz(48_000_000)); config.rcc.pclk1 = Some(Hertz(24_000_000)); - config -} + let mut p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, mut p: Peripherals) { info!("Hello World!"); { diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml index a3fb736d..27894df5 100644 --- a/examples/stm32f2/Cargo.toml +++ b/examples/stm32f2/Cargo.toml @@ -5,13 +5,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs index 48ae2e71..d8c89a51 100644 --- a/examples/stm32f2/src/bin/blinky.rs +++ b/examples/stm32f2/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB14, Level::High, Speed::Low); diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs index 01e63b15..17f09538 100644 --- a/examples/stm32f2/src/bin/pll.rs +++ b/examples/stm32f2/src/bin/pll.rs @@ -5,17 +5,19 @@ use core::convert::TryFrom; use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::rcc::{ APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, PLLPreDiv, PLLSrc, }; use embassy_stm32::time::Hertz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -// Example config for maximum performance on a NUCLEO-F207ZG board -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + // Example config for maximum performance on a NUCLEO-F207ZG board + let mut config = Config::default(); // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal) config.rcc.hse = Some(HSEConfig { @@ -40,11 +42,9 @@ fn config() -> Config { config.rcc.apb1_pre = APBPrescaler::Div4; // 120 MHz / 2 = 60 MHz APB2 frequency config.rcc.apb2_pre = APBPrescaler::Div2; - config -} -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, _p: Peripherals) { + let _p = embassy_stm32::init(config); + loop { Timer::after(Duration::from_millis(1000)).await; info!("1s elapsed"); diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml index 410e9b3e..b5ea28bb 100644 --- a/examples/stm32f3/Cargo.toml +++ b/examples/stm32f3/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } @@ -14,7 +15,7 @@ embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs index 7146eaa5..185785ce 100644 --- a/examples/stm32f3/src/bin/blinky.rs +++ b/examples/stm32f3/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PA5, Level::High, Speed::Low); diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index ef511031..61fc6dca 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs @@ -11,12 +11,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{with_timeout, Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; use embassy_stm32::peripherals::PA0; -use embassy_stm32::Peripherals; +use embassy_time::{with_timeout, Duration, Timer}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::mpmc::Channel; use {defmt_rtt as _, panic_probe as _}; @@ -100,7 +99,8 @@ enum ButtonEvent { static CHANNEL: Channel = Channel::new(); #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) { +async fn main(spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let button = Input::new(p.PA0, Pull::Down); let button = ExtiInput::new(button, p.EXTI0); info!("Press the USER button..."); diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs index dee06e5d..1266778c 100644 --- a/examples/stm32f3/src/bin/button_exti.rs +++ b/examples/stm32f3/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PA0, Pull::Down); diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs index be2f6f67..2cf24dbd 100644 --- a/examples/stm32f3/src/bin/flash.rs +++ b/examples/stm32f3/src/bin/flash.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); const ADDR: u32 = 0x26000; diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index bd9953a0..65773210 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs @@ -3,21 +3,19 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::time::Hertz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.hse = Some(Hertz(8_000_000)); config.rcc.sysclk = Some(Hertz(16_000_000)); - config -} + let _p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, _p: Peripherals) -> ! { loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index fba5b286..e96c3124 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs @@ -59,10 +59,10 @@ use cortex_m_rt::entry; use defmt::*; -use embassy_executor::time::{Duration, Instant, Timer}; use embassy_stm32::executor::{Executor, InterruptExecutor}; use embassy_stm32::interrupt; use embassy_stm32::interrupt::InterruptExt; +use embassy_time::{Duration, Instant, Timer}; use embassy_util::Forever; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs index f554c509..95b2b686 100644 --- a/examples/stm32f3/src/bin/spi_dma.rs +++ b/examples/stm32f3/src/bin/spi_dma.rs @@ -6,15 +6,15 @@ use core::fmt::Write; use core::str::from_utf8; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use heapless::String; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut spi = Spi::new( diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs index 62d16502..3bc5a287 100644 --- a/examples/stm32f3/src/bin/usart_dma.rs +++ b/examples/stm32f3/src/bin/usart_dma.rs @@ -5,15 +5,15 @@ use core::fmt::Write; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use heapless::String; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let config = Config::default(); diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index 87b1138f..d3702fc3 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs @@ -3,32 +3,28 @@ #![feature(type_alias_impl_trait)] use defmt::{panic, *}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::time::mhz; use embassy_stm32::usb::{Driver, Instance}; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; +use embassy_time::{Duration, Timer}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); - config.rcc.hse = Some(mhz(8)); config.rcc.sysclk = Some(mhz(48)); config.rcc.pclk1 = Some(mhz(24)); config.rcc.pclk2 = Some(mhz(24)); config.rcc.pll48 = true; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); // Needed for nucleo-stm32f303ze diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 3c58320d..04a217af 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -6,13 +6,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-io = "0.3.0" diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index 27ed4fcc..87118507 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Delay, Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::adc::Adc; -use embassy_stm32::Peripherals; +use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut adc = Adc::new(p.ADC1, &mut Delay); diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index f71fe098..b27bee4c 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB7, Level::High, Speed::Low); diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index 60dfb362..dfe587d4 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Down); diff --git a/examples/stm32f4/src/bin/dac.rs b/examples/stm32f4/src/bin/dac.rs index 392f5bf4..d97ae708 100644 --- a/examples/stm32f4/src/bin/dac.rs +++ b/examples/stm32f4/src/bin/dac.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dac::{Channel, Dac, Value}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { +async fn main(_spawner: Spawner) -> ! { + let p = embassy_stm32::init(Default::default()); info!("Hello World, dude!"); let mut dac = Dac::new_1ch(p.DAC, p.PA4); diff --git a/examples/stm32f4/src/bin/flash.rs b/examples/stm32f4/src/bin/flash.rs index 4f780656..393d61e8 100644 --- a/examples/stm32f4/src/bin/flash.rs +++ b/examples/stm32f4/src/bin/flash.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); let mut f = Flash::unlock(p.FLASH); diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index f957656e..c409703f 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs @@ -3,20 +3,18 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::time::Hertz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(Hertz(84_000_000)); - config -} + let _p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, _p: Peripherals) -> ! { loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index fba5b286..e96c3124 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs @@ -59,10 +59,10 @@ use cortex_m_rt::entry; use defmt::*; -use embassy_executor::time::{Duration, Instant, Timer}; use embassy_stm32::executor::{Executor, InterruptExecutor}; use embassy_stm32::interrupt; use embassy_stm32::interrupt::InterruptExt; +use embassy_time::{Duration, Instant, Timer}; use embassy_util::Forever; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index 0b352c2b..7c590205 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs @@ -3,16 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::pwm::Channel; use embassy_stm32::time::khz; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let ch1 = PwmPin::new_ch1(p.PE9); diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index 6eef1996..0edd8a61 100644 --- a/examples/stm32f4/src/bin/sdmmc.rs +++ b/examples/stm32f4/src/bin/sdmmc.rs @@ -3,20 +3,17 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::sdmmc::Sdmmc; use embassy_stm32::time::mhz; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(48)); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { + let p = embassy_stm32::init(config); info!("Hello World!"); let irq = interrupt::take!(SDIO); diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs index 023ca097..3d2a1a1a 100644 --- a/examples/stm32f4/src/bin/spi_dma.rs +++ b/examples/stm32f4/src/bin/spi_dma.rs @@ -6,15 +6,15 @@ use core::fmt::Write; use core::str::from_utf8; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use heapless::String; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut spi = Spi::new( diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs index 2555998c..7bcecbd2 100644 --- a/examples/stm32f4/src/bin/usart_buffered.rs +++ b/examples/stm32f4/src/bin/usart_buffered.rs @@ -3,15 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; +use embassy_stm32::interrupt; use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; -use embassy_stm32::{interrupt, Peripherals}; use embedded_io::asynch::BufRead; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let config = Config::default(); diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index 7859ba2a..bb41b8b4 100644 --- a/examples/stm32f4/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs @@ -5,15 +5,15 @@ use core::fmt::Write; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use heapless::String; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let config = Config::default(); diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index 48394f4f..b2c587fa 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::wdg::IndependentWatchdog; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB7, Level::High, Speed::Low); diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 081bed84..29d6da4d 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } embedded-io = { version = "0.3.0", features = ["async"] } @@ -13,7 +14,7 @@ embedded-io = { version = "0.3.0", features = ["async"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } @@ -21,5 +22,5 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa heapless = { version = "0.7.5", default-features = false } nb = "1.0.0" rand_core = "0.6.3" -critical-section = "0.2.3" +critical-section = "1.1" embedded-storage = "0.3.0" diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs index 2a813c05..80fad8c4 100644 --- a/examples/stm32f7/src/bin/adc.rs +++ b/examples/stm32f7/src/bin/adc.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Delay, Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::adc::Adc; -use embassy_stm32::Peripherals; +use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut adc = Adc::new(p.ADC1, &mut Delay); diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs index f71fe098..b27bee4c 100644 --- a/examples/stm32f7/src/bin/blinky.rs +++ b/examples/stm32f7/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB7, Level::High, Speed::Low); diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs index 60dfb362..dfe587d4 100644 --- a/examples/stm32f7/src/bin/button_exti.rs +++ b/examples/stm32f7/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Down); diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 33504af7..bdffabcb 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -3,8 +3,7 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, Stack, StackResources}; use embassy_stm32::eth::generic_smi::GenericSMI; @@ -12,7 +11,8 @@ use embassy_stm32::eth::{Ethernet, State}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::time::mhz; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; +use embassy_time::{Duration, Timer}; use embassy_util::Forever; use embedded_io::asynch::Write; use rand_core::RngCore; @@ -33,14 +33,12 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(200)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(spawner: Spawner, p: Peripherals) -> ! { info!("Hello World!"); // Generate random seed. diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs index 15864cab..c10781d0 100644 --- a/examples/stm32f7/src/bin/flash.rs +++ b/examples/stm32f7/src/bin/flash.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); const ADDR: u32 = 0x8_0000; diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs index f957656e..c409703f 100644 --- a/examples/stm32f7/src/bin/hello.rs +++ b/examples/stm32f7/src/bin/hello.rs @@ -3,20 +3,18 @@ #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::time::Hertz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(Hertz(84_000_000)); - config -} + let _p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, _p: Peripherals) -> ! { loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index 1f321df1..3bf427ec 100644 --- a/examples/stm32f7/src/bin/sdmmc.rs +++ b/examples/stm32f7/src/bin/sdmmc.rs @@ -3,20 +3,18 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::sdmmc::Sdmmc; use embassy_stm32::time::mhz; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(200)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { info!("Hello World!"); let irq = interrupt::take!(SDMMC1); diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs index 9884d163..07270479 100644 --- a/examples/stm32f7/src/bin/usart_dma.rs +++ b/examples/stm32f7/src/bin/usart_dma.rs @@ -5,15 +5,15 @@ use core::fmt::Write; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use heapless::String; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let config = Config::default(); let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, p.DMA1_CH1, NoDma, config); diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index 3dedeac6..5c80d43e 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml @@ -5,13 +5,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs index f71fe098..b27bee4c 100644 --- a/examples/stm32g0/src/bin/blinky.rs +++ b/examples/stm32g0/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB7, Level::High, Speed::Low); diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs index 0832386e..ef32d4c4 100644 --- a/examples/stm32g0/src/bin/button_exti.rs +++ b/examples/stm32g0/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Up); diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml index 60c62ad1..74c645cf 100644 --- a/examples/stm32g4/Cargo.toml +++ b/examples/stm32g4/Cargo.toml @@ -5,14 +5,15 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs index ea3c563b..8a65b069 100644 --- a/examples/stm32g4/src/bin/blinky.rs +++ b/examples/stm32g4/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PA5, Level::High, Speed::Low); diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs index 60dfb362..dfe587d4 100644 --- a/examples/stm32g4/src/bin/button_exti.rs +++ b/examples/stm32g4/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Down); diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 7c16d0a3..017e89e4 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs @@ -3,16 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::pwm::Channel; use embassy_stm32::time::khz; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let ch1 = PwmPin::new_ch1(p.PA5); diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 8b1999b3..a416796e 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml @@ -5,24 +5,26 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } -embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } +embassy-net = { path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16", "unstable-traits"] } embedded-io = { version = "0.3.0", features = ["async"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } embedded-hal-async = { version = "0.1.0-alpha.1" } +embedded-nal-async = "0.2.0" panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.7.5", default-features = false } rand_core = "0.6.3" -critical-section = "0.2.5" +critical-section = "1.1" micromath = "2.0.0" stm32-fmc = "0.2.4" embedded-storage = "0.3.0" diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index f50976a3..0e1e28c7 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs @@ -3,25 +3,23 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Delay, Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::adc::{Adc, SampleTime}; use embassy_stm32::rcc::AdcClockSource; use embassy_stm32::time::mhz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.per_ck = Some(mhz(64)); config.rcc.adc_clock_source = AdcClockSource::PerCk; - config -} + let mut p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, mut p: Peripherals) { info!("Hello World!"); let mut adc = Adc::new(p.ADC3, &mut Delay); diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs index 98ce15cc..12f08c0f 100644 --- a/examples/stm32h7/src/bin/blinky.rs +++ b/examples/stm32h7/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB14, Level::High, Speed::Low); diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs index 60dfb362..dfe587d4 100644 --- a/examples/stm32h7/src/bin/button_exti.rs +++ b/examples/stm32h7/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Down); diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 69187182..9c443b83 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs @@ -2,18 +2,24 @@ #![no_main] #![feature(type_alias_impl_trait)] -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::dcmi::{self, *}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::i2c::I2c; use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; use embassy_stm32::time::{khz, mhz}; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; +use embassy_time::{Duration, Timer}; +use ov7725::*; use {defmt_rtt as _, panic_probe as _}; -#[allow(unused)] -pub fn config() -> Config { +const WIDTH: usize = 100; +const HEIGHT: usize = 100; + +static mut FRAME: [u32; WIDTH * HEIGHT / 2] = [0u32; WIDTH * HEIGHT / 2]; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(400)); @@ -22,24 +28,23 @@ pub fn config() -> Config { config.rcc.pclk2 = Some(mhz(100)); config.rcc.pclk3 = Some(mhz(100)); config.rcc.pclk4 = Some(mhz(100)); - config -} + let p = embassy_stm32::init(config); -use ov7725::*; - -const WIDTH: usize = 100; -const HEIGHT: usize = 100; - -static mut FRAME: [u32; WIDTH * HEIGHT / 2] = [0u32; WIDTH * HEIGHT / 2]; - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { defmt::info!("Hello World!"); let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::Hsi, McoClock::Divided(3)); let mut led = Output::new(p.PE3, Level::High, Speed::Low); let i2c_irq = interrupt::take!(I2C1_EV); - let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, khz(100)); + let cam_i2c = I2c::new( + p.I2C1, + p.PB8, + p.PB9, + i2c_irq, + p.DMA1_CH1, + p.DMA1_CH2, + khz(100), + Default::default(), + ); let mut camera = Ov7725::new(cam_i2c, mco); @@ -78,8 +83,8 @@ mod ov7725 { use core::marker::PhantomData; use defmt::Format; - use embassy_executor::time::{Duration, Timer}; use embassy_stm32::rcc::{Mco, McoInstance}; + use embassy_time::{Duration, Timer}; use embedded_hal_async::i2c::I2c; #[repr(u8)] diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index dece74bb..f1271637 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs @@ -9,19 +9,15 @@ use embassy_stm32::time::mhz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(200)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - #[entry] fn main() -> ! { info!("Hello World, dude!"); - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); let mut dac = Dac::new_1ch(p.DAC1, p.PA4); diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 4282fced..83210bcb 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -3,8 +3,7 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, Stack, StackResources}; use embassy_stm32::eth::generic_smi::GenericSMI; @@ -12,7 +11,8 @@ use embassy_stm32::eth::{Ethernet, State}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::time::mhz; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; +use embassy_time::{Duration, Timer}; use embassy_util::Forever; use embedded_io::asynch::Write; use rand_core::RngCore; @@ -33,16 +33,13 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(spawner: Spawner, p: Peripherals) -> ! { + let p = embassy_stm32::init(config); info!("Hello World!"); // Generate random seed. diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs new file mode 100644 index 00000000..99946f50 --- /dev/null +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -0,0 +1,122 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_net::tcp::client::{TcpClient, TcpClientState}; +use embassy_net::{Stack, StackResources}; +use embassy_stm32::eth::generic_smi::GenericSMI; +use embassy_stm32::eth::{Ethernet, State}; +use embassy_stm32::peripherals::ETH; +use embassy_stm32::rng::Rng; +use embassy_stm32::time::mhz; +use embassy_stm32::{interrupt, Config}; +use embassy_time::{Duration, Timer}; +use embassy_util::Forever; +use embedded_io::asynch::Write; +use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; +use rand_core::RngCore; +use {defmt_rtt as _, panic_probe as _}; + +macro_rules! forever { + ($val:expr) => {{ + type T = impl Sized; + static FOREVER: Forever = Forever::new(); + FOREVER.put_with(move || $val) + }}; +} + +type Device = Ethernet<'static, ETH, GenericSMI, 4, 4>; + +#[embassy_executor::task] +async fn net_task(stack: &'static Stack) -> ! { + stack.run().await +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) -> ! { + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); + info!("Hello World!"); + + // Generate random seed. + let mut rng = Rng::new(p.RNG); + let mut seed = [0; 8]; + rng.fill_bytes(&mut seed); + let seed = u64::from_le_bytes(seed); + + let eth_int = interrupt::take!(ETH); + let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + + let device = unsafe { + Ethernet::new( + forever!(State::new()), + p.ETH, + eth_int, + p.PA1, + p.PA2, + p.PC1, + p.PA7, + p.PC4, + p.PC5, + p.PG13, + p.PB13, + p.PG11, + GenericSMI, + mac_addr, + 0, + ) + }; + + let config = embassy_net::ConfigStrategy::Dhcp; + //let config = embassy_net::ConfigStrategy::Static(embassy_net::Config { + // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), + // dns_servers: Vec::new(), + // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), + //}); + + // Init network stack + let stack = &*forever!(Stack::new( + device, + config, + forever!(StackResources::<1, 2, 8>::new()), + seed + )); + + // Launch network task + unwrap!(spawner.spawn(net_task(&stack))); + + info!("Network task initialized"); + + // To ensure DHCP configuration before trying connect + Timer::after(Duration::from_secs(20)).await; + + static STATE: TcpClientState<1, 1024, 1024> = TcpClientState::new(); + let client = TcpClient::new(&stack, &STATE); + + loop { + let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(10, 42, 0, 1), 8000)); + + info!("connecting..."); + let r = client.connect(addr).await; + if let Err(e) = r { + info!("connect error: {:?}", e); + Timer::after(Duration::from_secs(1)).await; + continue; + } + let mut connection = r.unwrap(); + info!("connected!"); + loop { + let r = connection.write_all(b"Hello\n").await; + if let Err(e) = r { + info!("write error: {:?}", e); + return; + } + Timer::after(Duration::from_secs(1)).await; + } + } +} diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs index 0c477deb..6682c64d 100644 --- a/examples/stm32h7/src/bin/flash.rs +++ b/examples/stm32h7/src/bin/flash.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); const ADDR: u32 = 0x08_0000; diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs index 5140a6e2..85c690fe 100644 --- a/examples/stm32h7/src/bin/fmc.rs +++ b/examples/stm32h7/src/bin/fmc.rs @@ -3,23 +3,21 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Delay, Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::fmc::Fmc; use embassy_stm32::time::mhz; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Delay, Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.pll1.q_ck = Some(mhz(100)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); let mut core_peri = cortex_m::Peripherals::take().unwrap(); diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index f2477c7a..1972f8ff 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -3,16 +3,17 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::low_level::AFType; use embassy_stm32::gpio::Speed; use embassy_stm32::pwm::*; use embassy_stm32::time::{khz, mhz, Hertz}; -use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef, Peripherals}; +use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef}; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(400)); @@ -21,11 +22,8 @@ pub fn config() -> Config { config.rcc.pclk2 = Some(mhz(100)); config.rcc.pclk3 = Some(mhz(100)); config.rcc.pclk4 = Some(mhz(100)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, khz(10)); diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs index 83ba3742..036455d5 100644 --- a/examples/stm32h7/src/bin/mco.rs +++ b/examples/stm32h7/src/bin/mco.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB14, Level::High, Speed::Low); diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index 36ed2e4a..c5c0dd29 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs @@ -3,15 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::pwm::Channel; use embassy_stm32::time::{khz, mhz}; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(400)); @@ -20,11 +21,7 @@ pub fn config() -> Config { config.rcc.pclk2 = Some(mhz(100)); config.rcc.pclk3 = Some(mhz(100)); config.rcc.pclk4 = Some(mhz(100)); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { + let p = embassy_stm32::init(config); info!("Hello World!"); let ch1 = PwmPin::new_ch1(p.PA6); diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index 81fb3d16..af9be0b6 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::rng::Rng; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut rng = Rng::new(p.RNG); diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index 19ae5ade..26d1db01 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs @@ -3,20 +3,17 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::sdmmc::Sdmmc; use embassy_stm32::time::mhz; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(200)); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { + let p = embassy_stm32::init(config); info!("Hello World!"); let irq = interrupt::take!(SDMMC1); diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs index 2fc75c7a..be2ac268 100644 --- a/examples/stm32h7/src/bin/signal.rs +++ b/examples/stm32h7/src/bin/signal.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; -use embassy_stm32::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; use embassy_util::channel::signal::Signal; use {defmt_rtt as _, panic_probe as _}; @@ -25,7 +24,8 @@ async fn my_sending_task() { } #[embassy_executor::main] -async fn main(spawner: Spawner, _p: Peripherals) { +async fn main(spawner: Spawner) { + let _p = embassy_stm32::init(Default::default()); unwrap!(spawner.spawn(my_sending_task())); loop { diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index dc8cb7f4..c28f937a 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs @@ -7,7 +7,7 @@ use core::str::from_utf8; use cortex_m_rt::entry; use defmt::*; -use embassy_executor::executor::Executor; +use embassy_executor::Executor; use embassy_stm32::dma::NoDma; use embassy_stm32::peripherals::SPI3; use embassy_stm32::time::mhz; @@ -16,14 +16,6 @@ use embassy_util::Forever; use heapless::String; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(200)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - #[embassy_executor::task] async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) { for n in 0u32.. { @@ -45,7 +37,11 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); let spi = spi::Spi::new( p.SPI3, diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 2631ed30..6c78c194 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs @@ -7,7 +7,7 @@ use core::str::from_utf8; use cortex_m_rt::entry; use defmt::*; -use embassy_executor::executor::Executor; +use embassy_executor::Executor; use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; use embassy_stm32::time::mhz; use embassy_stm32::{spi, Config}; @@ -15,14 +15,6 @@ use embassy_util::Forever; use heapless::String; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(200)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - #[embassy_executor::task] async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) { for n in 0u32.. { @@ -41,7 +33,11 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); let spi = spi::Spi::new( p.SPI3, diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index e491fb39..1384d54c 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs @@ -4,7 +4,7 @@ use cortex_m_rt::entry; use defmt::*; -use embassy_executor::executor::Executor; +use embassy_executor::Executor; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_util::Forever; diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index aacda45b..f8d58bb8 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs @@ -6,7 +6,7 @@ use core::fmt::Write; use cortex_m_rt::entry; use defmt::*; -use embassy_executor::executor::Executor; +use embassy_executor::Executor; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_util::Forever; diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs index 12bb0ce9..64080ec4 100644 --- a/examples/stm32h7/src/bin/usart_split.rs +++ b/examples/stm32h7/src/bin/usart_split.rs @@ -3,11 +3,10 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::peripherals::{DMA1_CH1, UART7}; use embassy_stm32::usart::{Config, Uart, UartRx}; -use embassy_stm32::Peripherals; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::mpmc::Channel; use {defmt_rtt as _, panic_probe as _}; @@ -27,7 +26,8 @@ async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) { static CHANNEL: Channel = Channel::new(); #[embassy_executor::main] -async fn main(spawner: Spawner, p: Peripherals) -> ! { +async fn main(spawner: Spawner) -> ! { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let config = Config::default(); diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 7edda042..fdb716d1 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml @@ -9,7 +9,8 @@ nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true} @@ -22,7 +23,7 @@ defmt-rtt = "0.3" embedded-storage = "0.3.0" embedded-io = "0.3.0" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs index 8cf21eff..07fad07c 100644 --- a/examples/stm32l0/src/bin/blinky.rs +++ b/examples/stm32l0/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB5, Level::High, Speed::Low); diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs index a5e05c3a..9d194471 100644 --- a/examples/stm32l0/src/bin/button.rs +++ b/examples/stm32l0/src/bin/button.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PB2, Pull::Up); diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs index 22a096af..af82b995 100644 --- a/examples/stm32l0/src/bin/button_exti.rs +++ b/examples/stm32l0/src/bin/button_exti.rs @@ -3,20 +3,18 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; +use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> embassy_stm32::Config { - let mut config = embassy_stm32::Config::default(); +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let mut config = Config::default(); config.rcc.enable_hsi48 = true; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { let button = Input::new(p.PB2, Pull::Up); let mut button = ExtiInput::new(button, p.EXTI2); diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs index 7ad5ae3a..867cb4d3 100644 --- a/examples/stm32l0/src/bin/flash.rs +++ b/examples/stm32l0/src/bin/flash.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); const ADDR: u32 = 0x26000; diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs index 29e54c1b..303558b9 100644 --- a/examples/stm32l0/src/bin/lorawan.rs +++ b/examples/stm32l0/src/bin/lorawan.rs @@ -6,26 +6,25 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] +use embassy_executor::Spawner; use embassy_lora::sx127x::*; use embassy_lora::LoraTimer; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::rng::Rng; +use embassy_stm32::spi; use embassy_stm32::time::khz; -use embassy_stm32::{spi, Peripherals}; use lorawan::default_crypto::DefaultFactory as Crypto; use lorawan_device::async_device::{region, Device, JoinMode}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> embassy_stm32::Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; config.rcc.enable_hsi48 = true; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: embassy_executor::executor::Spawner, p: Peripherals) { // SPI for sx127x let spi = spi::Spi::new( p.SPI1, diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs index cd711a43..bd87e62a 100644 --- a/examples/stm32l0/src/bin/raw_spawn.rs +++ b/examples/stm32l0/src/bin/raw_spawn.rs @@ -5,9 +5,9 @@ use core::mem; use cortex_m_rt::entry; use defmt::*; -use embassy_executor::executor::raw::TaskStorage; -use embassy_executor::executor::Executor; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::raw::TaskStorage; +use embassy_executor::Executor; +use embassy_time::{Duration, Timer}; use embassy_util::Forever; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs index 74694295..9b5b3e27 100644 --- a/examples/stm32l0/src/bin/spi.rs +++ b/examples/stm32l0/src/bin/spi.rs @@ -3,16 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World, folks!"); let mut spi = Spi::new( diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs index 1c5ce94d..66657d0f 100644 --- a/examples/stm32l0/src/bin/usart_dma.rs +++ b/examples/stm32l0/src/bin/usart_dma.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, p.DMA1_CH2, p.DMA1_CH3, Config::default()); usart.write(b"Hello Embassy World!\r\n").await.unwrap(); diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs index b77d97f8..0e223738 100644 --- a/examples/stm32l0/src/bin/usart_irq.rs +++ b/examples/stm32l0/src/bin/usart_irq.rs @@ -3,15 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; +use embassy_stm32::interrupt; use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; -use embassy_stm32::{interrupt, Peripherals}; use embedded_io::asynch::{Read, Write}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hi!"); static mut TX_BUFFER: [u8; 8] = [0; 8]; diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml index d69de9c5..43f844b6 100644 --- a/examples/stm32l1/Cargo.toml +++ b/examples/stm32l1/Cargo.toml @@ -5,13 +5,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs index 58306be9..8a345d23 100644 --- a/examples/stm32l1/src/bin/blinky.rs +++ b/examples/stm32l1/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PA12, Level::High, Speed::Low); diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs index 78938fe3..a76b9879 100644 --- a/examples/stm32l1/src/bin/flash.rs +++ b/examples/stm32l1/src/bin/flash.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); const ADDR: u32 = 0x26000; diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs index 05e869e7..0a532e8e 100644 --- a/examples/stm32l1/src/bin/spi.rs +++ b/examples/stm32l1/src/bin/spi.rs @@ -3,16 +3,16 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World, folks!"); let mut spi = Spi::new( diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 8ac974c9..eaffa253 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -7,14 +7,15 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5vi", "time-driver-any", "exti", "unstable-traits"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index 93a20d5e..281346e5 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs @@ -3,9 +3,9 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::time::Delay; use embassy_stm32::adc::{Adc, Resolution}; use embassy_stm32::pac; +use embassy_time::Delay; use {defmt_rtt as _, panic_probe as _}; #[cortex_m_rt::entry] diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index 3d689b5e..033292ff 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB14, Level::High, Speed::Low); diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index 0832386e..ef32d4c4 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Up); diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs index 058529ec..d54c080c 100644 --- a/examples/stm32l4/src/bin/i2c.rs +++ b/examples/stm32l4/src/bin/i2c.rs @@ -3,20 +3,30 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::i2c::I2c; +use embassy_stm32::interrupt; use embassy_stm32::time::Hertz; -use embassy_stm32::{interrupt, Peripherals}; use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x5F; const WHOAMI: u8 = 0x0F; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { +async fn main(_spawner: Spawner) -> ! { + let p = embassy_stm32::init(Default::default()); let irq = interrupt::take!(I2C2_EV); - let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000)); + let mut i2c = I2c::new( + p.I2C2, + p.PB10, + p.PB11, + irq, + NoDma, + NoDma, + Hertz(100_000), + Default::default(), + ); let mut data = [0u8; 1]; unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data)); diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs index 2dae9c2d..35a86660 100644 --- a/examples/stm32l4/src/bin/i2c_blocking_async.rs +++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs @@ -4,11 +4,11 @@ use defmt::*; use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::i2c::I2c; +use embassy_stm32::interrupt; use embassy_stm32::time::Hertz; -use embassy_stm32::{interrupt, Peripherals}; use embedded_hal_async::i2c::I2c as I2cTrait; use {defmt_rtt as _, panic_probe as _}; @@ -16,9 +16,19 @@ const ADDRESS: u8 = 0x5F; const WHOAMI: u8 = 0x0F; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { +async fn main(_spawner: Spawner) -> ! { + let p = embassy_stm32::init(Default::default()); let irq = interrupt::take!(I2C2_EV); - let i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000)); + let i2c = I2c::new( + p.I2C2, + p.PB10, + p.PB11, + irq, + NoDma, + NoDma, + Hertz(100_000), + Default::default(), + ); let mut i2c = BlockingAsync::new(i2c); let mut data = [0u8; 1]; diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs index 9e71d404..3ce9398a 100644 --- a/examples/stm32l4/src/bin/i2c_dma.rs +++ b/examples/stm32l4/src/bin/i2c_dma.rs @@ -3,19 +3,29 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::i2c::I2c; +use embassy_stm32::interrupt; use embassy_stm32::time::Hertz; -use embassy_stm32::{interrupt, Peripherals}; use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x5F; const WHOAMI: u8 = 0x0F; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { +async fn main(_spawner: Spawner) -> ! { + let p = embassy_stm32::init(Default::default()); let irq = interrupt::take!(I2C2_EV); - let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, p.DMA1_CH4, p.DMA1_CH5, Hertz(100_000)); + let mut i2c = I2c::new( + p.I2C2, + p.PB10, + p.PB11, + irq, + p.DMA1_CH4, + p.DMA1_CH5, + Hertz(100_000), + Default::default(), + ); let mut data = [0u8; 1]; unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index ed47fc6c..c9302bb9 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs @@ -3,13 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; use embassy_stm32::rng::Rng; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); // 72Mhz clock (16 / 1 * 18 / 4) config.rcc.mux = ClockSrc::PLL( @@ -19,11 +20,8 @@ fn config() -> Config { PLLMul::Mul18, Some(PLLClkDiv::Div6), // 48Mhz (16 / 1 * 18 / 6) ); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); let mut rng = Rng::new(p.RNG); diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs index e06b29b8..62ef0130 100644 --- a/examples/stm32l4/src/bin/spi_blocking_async.rs +++ b/examples/stm32l4/src/bin/spi_blocking_async.rs @@ -4,17 +4,17 @@ use defmt::*; use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use embedded_hal_async::spi::SpiBus; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let spi = Spi::new( diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs index e44754be..89471db5 100644 --- a/examples/stm32l4/src/bin/spi_dma.rs +++ b/examples/stm32l4/src/bin/spi_dma.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut spi = Spi::new( diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index fdd5a85e..72890689 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs @@ -5,15 +5,15 @@ use core::fmt::Write; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use heapless::String; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let config = Config::default(); diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 6466994e..4d96d31f 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml @@ -7,7 +7,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } @@ -20,7 +21,7 @@ defmt = "0.3" defmt-rtt = "0.3" panic-probe = { version = "0.3", features = ["print-defmt"] } -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs index 99462e59..e80ad2b3 100644 --- a/examples/stm32l5/src/bin/button_exti.rs +++ b/examples/stm32l5/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC13, Pull::Down); diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs index 45094374..d359847e 100644 --- a/examples/stm32l5/src/bin/rng.rs +++ b/examples/stm32l5/src/bin/rng.rs @@ -3,13 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; use embassy_stm32::rng::Rng; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.mux = ClockSrc::PLL( PLLSource::HSI16, @@ -18,11 +19,8 @@ fn config() -> Config { PLLMul::Mul8, Some(PLLClkDiv::Div2), ); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); let mut rng = Rng::new(p.RNG); diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 9e1df15d..7c53d03c 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs @@ -7,14 +7,14 @@ use core::sync::atomic::{AtomicBool, Ordering}; use core::task::Waker; use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; use embassy_stm32::rcc::*; use embassy_stm32::rng::Rng; use embassy_stm32::time::Hertz; use embassy_stm32::usb::Driver; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; use embassy_usb::{Builder, UsbDevice}; use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; @@ -83,18 +83,13 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) { let mut config = Config::default(); - config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); config.rcc.hsi48 = true; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(spawner: Spawner, p: Peripherals) { // Create the driver, from the HAL. let irq = interrupt::take!(USB_FS); let driver = Driver::new(p.USB, irq, p.PA12, p.PA11); diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs index 6aac0088..f7e3d93e 100644 --- a/examples/stm32l5/src/bin/usb_hid_mouse.rs +++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs @@ -4,12 +4,12 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::rcc::*; use embassy_stm32::time::Hertz; use embassy_stm32::usb::Driver; use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_time::{Duration, Timer}; use embassy_usb::control::OutResponse; use embassy_usb::Builder; use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; @@ -17,18 +17,13 @@ use futures::future::join; use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); - config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); config.rcc.hsi48 = true; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { // Create the driver, from the HAL. let irq = interrupt::take!(USB_FS); let driver = Driver::new(p.USB, irq, p.PA12, p.PA11); diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs index 508bce8a..323db655 100644 --- a/examples/stm32l5/src/bin/usb_serial.rs +++ b/examples/stm32l5/src/bin/usb_serial.rs @@ -3,29 +3,24 @@ #![feature(type_alias_impl_trait)] use defmt::{panic, *}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::rcc::*; use embassy_stm32::time::Hertz; use embassy_stm32::usb::{Driver, Instance}; -use embassy_stm32::{interrupt, Config, Peripherals}; +use embassy_stm32::{interrupt, Config}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); - config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); config.rcc.hsi48 = true; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); // Create the driver, from the HAL. diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml index 4ce95be4..48833664 100644 --- a/examples/stm32u5/Cargo.toml +++ b/examples/stm32u5/Cargo.toml @@ -5,13 +5,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32u5/src/bin/blinky.rs b/examples/stm32u5/src/bin/blinky.rs index 4f3eabc5..976fb0b9 100644 --- a/examples/stm32u5/src/bin/blinky.rs +++ b/examples/stm32u5/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) -> ! { +async fn main(_spawner: Spawner) -> ! { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PH7, Level::Low, Speed::Medium); diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index dc9107dd..b4630076 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml @@ -5,13 +5,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] } defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs index 3d8e8391..f9bf90d2 100644 --- a/examples/stm32wb/src/bin/blinky.rs +++ b/examples/stm32wb/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB0, Level::High, Speed::Low); diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs index 41afaf4d..3648db6f 100644 --- a/examples/stm32wb/src/bin/button_exti.rs +++ b/examples/stm32wb/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PC4, Pull::Up); diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 00d63f02..ae33478a 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml @@ -5,7 +5,8 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } @@ -15,7 +16,7 @@ lorawan = { version = "0.7.1", default-features = false, features = ["default-cr defmt = "0.3" defmt-rtt = "0.3" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-storage = "0.3.0" diff --git a/examples/stm32wl/src/bin/blinky.rs b/examples/stm32wl/src/bin/blinky.rs index e764b4cc..6af5099c 100644 --- a/examples/stm32wl/src/bin/blinky.rs +++ b/examples/stm32wl/src/bin/blinky.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; +use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let mut led = Output::new(p.PB15, Level::High, Speed::Low); diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs index 9f143597..1f02db5c 100644 --- a/examples/stm32wl/src/bin/button_exti.rs +++ b/examples/stm32wl/src/bin/button_exti.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; -use embassy_stm32::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello World!"); let button = Input::new(p.PA0, Pull::Up); diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs index 46183b8a..eb748976 100644 --- a/examples/stm32wl/src/bin/flash.rs +++ b/examples/stm32wl/src/bin/flash.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::flash::Flash; -use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); info!("Hello Flash!"); const ADDR: u32 = 0x36000; diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 2db022ea..7e8a8946 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs @@ -5,26 +5,25 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] +use embassy_executor::Spawner; use embassy_lora::stm32wl::*; use embassy_lora::LoraTimer; use embassy_stm32::dma::NoDma; use embassy_stm32::gpio::{Level, Output, Pin, Speed}; use embassy_stm32::rng::Rng; use embassy_stm32::subghz::*; -use embassy_stm32::{interrupt, pac, Peripherals}; +use embassy_stm32::{interrupt, pac}; use lorawan::default_crypto::DefaultFactory as Crypto; use lorawan_device::async_device::{region, Device, JoinMode}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> embassy_stm32::Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; config.rcc.enable_lsi = true; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: embassy_executor::executor::Spawner, p: Peripherals) { unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } let ctrl1 = Output::new(p.PC3.degrade(), Level::High, Speed::High); diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index 775dfbbf..d16e3f5e 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs @@ -6,12 +6,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::interrupt; use embassy_stm32::interrupt::{Interrupt, InterruptExt}; use embassy_stm32::subghz::*; -use embassy_stm32::{interrupt, Peripherals}; use embassy_util::channel::signal::Signal; use {defmt_rtt as _, panic_probe as _}; @@ -51,14 +52,12 @@ const TCXO_MODE: TcxoMode = TcxoMode::new() const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40); -fn config() -> embassy_stm32::Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: embassy_executor::executor::Spawner, p: Peripherals) { let mut led1 = Output::new(p.PB15, Level::High, Speed::Low); let mut led2 = Output::new(p.PB9, Level::Low, Speed::Low); let mut led3 = Output::new(p.PB11, Level::Low, Speed::Low); diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml index 4e26f023..c7f98036 100644 --- a/examples/wasm/Cargo.toml +++ b/examples/wasm/Cargo.toml @@ -8,10 +8,11 @@ crate-type = ["cdylib"] [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] } wasm-logger = "0.2.0" wasm-bindgen = "0.2" web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } log = "0.4.11" -critical-section = "0.2.5" +critical-section = "1.1" diff --git a/examples/wasm/src/lib.rs b/examples/wasm/src/lib.rs index 2e961e65..d44c020b 100644 --- a/examples/wasm/src/lib.rs +++ b/examples/wasm/src/lib.rs @@ -1,8 +1,8 @@ #![feature(type_alias_impl_trait)] #![allow(incomplete_features)] -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Timer}; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; #[embassy_executor::task] async fn ticker() { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c6d0f485..f5e342ed 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2022-07-13" +channel = "nightly-2022-08-16" components = [ "rust-src", "rustfmt" ] targets = [ "thumbv7em-none-eabi", diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml index 31d70778..9d5aba0c 100644 --- a/stm32-metapac/Cargo.toml +++ b/stm32-metapac/Cargo.toml @@ -40,7 +40,7 @@ flavors = [ ] [dependencies] -cortex-m = "0.7.3" +cortex-m = "0.7.6" cortex-m-rt = { version = ">=0.6.15,<0.8", optional = true } # BEGIN BUILD DEPENDENCIES diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index d19243b9..8740cc48 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml @@ -5,13 +5,14 @@ version = "0.1.0" [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits"] } defmt = "0.3.0" defmt-rtt = "0.3.0" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs index 6f6baf77..af22fe27 100644 --- a/tests/rp/src/bin/gpio.rs +++ b/tests/rp/src/bin/gpio.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::{assert, *}; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_rp::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull}; -use embassy_rp::Peripherals; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); info!("Hello World!"); let (mut a, mut b) = (p.PIN_0, p.PIN_1); diff --git a/tests/rp/src/bin/gpio_async.rs b/tests/rp/src/bin/gpio_async.rs index 1098682a..1eeaac1f 100644 --- a/tests/rp/src/bin/gpio_async.rs +++ b/tests/rp/src/bin/gpio_async.rs @@ -3,15 +3,15 @@ #![feature(type_alias_impl_trait)] use defmt::{assert, *}; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Instant, Timer}; +use embassy_executor::Spawner; use embassy_rp::gpio::{Input, Level, Output, Pull}; -use embassy_rp::Peripherals; +use embassy_time::{Duration, Instant, Timer}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); info!("embassy-rp gpio_async test"); // On the CI device the following pins are connected with each other. diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index c1cca99d..1d12995a 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -14,13 +14,14 @@ stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board [dependencies] embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "time-tick-32768hz"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } +embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "tick-32768hz"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } defmt = "0.3.0" defmt-rtt = "0.3.0" -cortex-m = "0.7.3" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" } diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index 8eab731b..18fd85d4 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs @@ -5,13 +5,13 @@ #[path = "../example_common.rs"] mod example_common; use defmt::assert; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull, Speed}; -use embassy_stm32::Peripherals; use example_common::*; -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(config()); info!("Hello World!"); // Arduino pins D0 and D1 diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs index 6d38b0bb..1c5dc87c 100644 --- a/tests/stm32/src/bin/spi.rs +++ b/tests/stm32/src/bin/spi.rs @@ -5,15 +5,15 @@ #[path = "../example_common.rs"] mod example_common; use defmt::assert_eq; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::spi::{self, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use example_common::*; -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(config()); info!("Hello World!"); #[cfg(feature = "stm32f103c8")] diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs index 8147c5f0..cb2152e0 100644 --- a/tests/stm32/src/bin/spi_dma.rs +++ b/tests/stm32/src/bin/spi_dma.rs @@ -5,14 +5,14 @@ #[path = "../example_common.rs"] mod example_common; use defmt::assert_eq; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::spi::{self, Spi}; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; use example_common::*; -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(config()); info!("Hello World!"); #[cfg(feature = "stm32f103c8")] diff --git a/tests/stm32/src/bin/timer.rs b/tests/stm32/src/bin/timer.rs index 76b07ca1..e00e43bf 100644 --- a/tests/stm32/src/bin/timer.rs +++ b/tests/stm32/src/bin/timer.rs @@ -5,13 +5,13 @@ #[path = "../example_common.rs"] mod example_common; use defmt::assert; -use embassy_executor::executor::Spawner; -use embassy_executor::time::{Duration, Instant, Timer}; -use embassy_stm32::Peripherals; +use embassy_executor::Spawner; +use embassy_time::{Duration, Instant, Timer}; use example_common::*; -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, _p: Peripherals) { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let _p = embassy_stm32::init(config()); info!("Hello World!"); let start = Instant::now(); diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs index 7b60e4b2..fb4b3fcc 100644 --- a/tests/stm32/src/bin/usart.rs +++ b/tests/stm32/src/bin/usart.rs @@ -5,14 +5,14 @@ #[path = "../example_common.rs"] mod example_common; use defmt::assert_eq; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use example_common::*; -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(config()); info!("Hello World!"); #[cfg(feature = "stm32wb55rg")] diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs index 323c41ca..09382a02 100644 --- a/tests/stm32/src/bin/usart_dma.rs +++ b/tests/stm32/src/bin/usart_dma.rs @@ -5,13 +5,13 @@ #[path = "../example_common.rs"] mod example_common; use defmt::assert_eq; -use embassy_executor::executor::Spawner; +use embassy_executor::Spawner; use embassy_stm32::usart::{Config, Uart}; -use embassy_stm32::Peripherals; use example_common::*; -#[embassy_executor::main(config = "config()")] -async fn main(_spawner: Spawner, p: Peripherals) { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(config()); info!("Hello World!"); #[cfg(feature = "stm32wb55rg")]