aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2022-08-23 23:01:51 -0400
committerQuentin Smith <[email protected]>2022-08-23 23:01:51 -0400
commit2900ab79e7afa0ca3e0d800f8a91c3253a333db1 (patch)
treea5066235f8b1ac6c2520105db2e5c48630bc006d /examples
parent14eae9ca06f63a69ccc29d5fd9e1dec3848a3e98 (diff)
parent529535194d4b5d58b31fd6a7541176105e3c63f7 (diff)
Merge remote-tracking branch 'origin/master' into nrf-pdm
Diffstat (limited to 'examples')
-rw-r--r--examples/boot/application/nrf/Cargo.toml2
-rw-r--r--examples/boot/application/stm32f3/Cargo.toml2
-rw-r--r--examples/boot/application/stm32f7/Cargo.toml2
-rw-r--r--examples/boot/application/stm32h7/Cargo.toml2
-rw-r--r--examples/boot/application/stm32l0/Cargo.toml2
-rw-r--r--examples/boot/application/stm32l1/Cargo.toml2
-rw-r--r--examples/boot/application/stm32l4/Cargo.toml2
-rw-r--r--examples/boot/application/stm32wl/Cargo.toml2
-rw-r--r--examples/nrf-rtos-trace/.cargo/config.toml9
-rw-r--r--examples/nrf-rtos-trace/Cargo.toml35
-rw-r--r--examples/nrf-rtos-trace/build.rs36
-rw-r--r--examples/nrf-rtos-trace/memory.x7
-rw-r--r--examples/nrf-rtos-trace/src/bin/rtos_trace.rs69
-rw-r--r--examples/nrf/Cargo.toml4
-rw-r--r--examples/nrf/src/bin/channel.rs4
-rw-r--r--examples/nrf/src/bin/channel_sender_receiver.rs10
-rw-r--r--examples/nrf/src/bin/multiprio.rs14
-rw-r--r--examples/nrf/src/bin/mutex.rs4
-rw-r--r--examples/nrf/src/bin/pubsub.rs4
-rw-r--r--examples/nrf/src/bin/raw_spawn.rs6
-rw-r--r--examples/nrf/src/bin/uart_split.rs4
-rw-r--r--examples/nrf/src/bin/usb_ethernet.rs18
-rw-r--r--examples/nrf/src/bin/usb_hid_keyboard.rs4
-rw-r--r--examples/nrf/src/bin/usb_serial_multitask.rs6
-rw-r--r--examples/rp/Cargo.toml2
-rw-r--r--examples/std/Cargo.toml3
-rw-r--r--examples/std/src/bin/net.rs16
-rw-r--r--examples/std/src/bin/net_udp.rs16
-rw-r--r--examples/std/src/bin/serial.rs6
-rw-r--r--examples/stm32f0/Cargo.toml2
-rw-r--r--examples/stm32f1/Cargo.toml2
-rw-r--r--examples/stm32f2/Cargo.toml2
-rw-r--r--examples/stm32f3/Cargo.toml3
-rw-r--r--examples/stm32f3/src/bin/button_events.rs4
-rw-r--r--examples/stm32f3/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f4/Cargo.toml3
-rw-r--r--examples/stm32f4/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f7/Cargo.toml3
-rw-r--r--examples/stm32f7/src/bin/eth.rs14
-rw-r--r--examples/stm32g0/Cargo.toml2
-rw-r--r--examples/stm32g4/Cargo.toml2
-rw-r--r--examples/stm32h7/Cargo.toml3
-rw-r--r--examples/stm32h7/src/bin/eth.rs14
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs14
-rw-r--r--examples/stm32h7/src/bin/signal.rs2
-rw-r--r--examples/stm32h7/src/bin/spi.rs6
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs6
-rw-r--r--examples/stm32h7/src/bin/usart.rs6
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs6
-rw-r--r--examples/stm32h7/src/bin/usart_split.rs4
-rw-r--r--examples/stm32l0/Cargo.toml3
-rw-r--r--examples/stm32l0/src/bin/raw_spawn.rs6
-rw-r--r--examples/stm32l1/Cargo.toml2
-rw-r--r--examples/stm32l4/Cargo.toml2
-rw-r--r--examples/stm32l5/Cargo.toml3
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs18
-rw-r--r--examples/stm32u5/Cargo.toml2
-rw-r--r--examples/stm32wb/Cargo.toml2
-rw-r--r--examples/stm32wl/Cargo.toml2
-rw-r--r--examples/stm32wl/src/bin/subghz.rs2
-rw-r--r--examples/wasm/Cargo.toml4
-rw-r--r--examples/wasm/README.md2
62 files changed, 316 insertions, 151 deletions
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml
index ef9346639..b9ff92578 100644
--- a/examples/boot/application/nrf/Cargo.toml
+++ b/examples/boot/application/nrf/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-nrf-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util" } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync" }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly"] }
10embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } 10embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] }
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml
index 27eafa653..f143d1e8d 100644
--- a/examples/boot/application/stm32f3/Cargo.toml
+++ b/examples/boot/application/stm32f3/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32f3-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] }
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml
index 7de0b82d7..29c87eee1 100644
--- a/examples/boot/application/stm32f7/Cargo.toml
+++ b/examples/boot/application/stm32f7/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32f7-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] }
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml
index 65d34c70b..5669527fe 100644
--- a/examples/boot/application/stm32h7/Cargo.toml
+++ b/examples/boot/application/stm32h7/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32h7-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml
index 8f37869e3..48624d5ec 100644
--- a/examples/boot/application/stm32l0/Cargo.toml
+++ b/examples/boot/application/stm32l0/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32l0-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] }
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml
index 6abf1986d..00b638ca5 100644
--- a/examples/boot/application/stm32l1/Cargo.toml
+++ b/examples/boot/application/stm32l1/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32l1-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] }
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml
index 6f2d12ff1..51ba730d5 100644
--- a/examples/boot/application/stm32l4/Cargo.toml
+++ b/examples/boot/application/stm32l4/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32l4-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] }
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml
index be97d4ebb..182acf694 100644
--- a/examples/boot/application/stm32wl/Cargo.toml
+++ b/examples/boot/application/stm32wl/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32wl-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] }
diff --git a/examples/nrf-rtos-trace/.cargo/config.toml b/examples/nrf-rtos-trace/.cargo/config.toml
new file mode 100644
index 000000000..8ca28df39
--- /dev/null
+++ b/examples/nrf-rtos-trace/.cargo/config.toml
@@ -0,0 +1,9 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip nRF52840_xxAA"
4
5[build]
6target = "thumbv7em-none-eabi"
7
8[env]
9DEFMT_LOG = "trace"
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml
new file mode 100644
index 000000000..87c9f33f5
--- /dev/null
+++ b/examples/nrf-rtos-trace/Cargo.toml
@@ -0,0 +1,35 @@
1[package]
2edition = "2021"
3name = "embassy-nrf-rtos-trace-examples"
4version = "0.1.0"
5
6[features]
7default = ["log", "nightly"]
8nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits"]
9log = [
10 "dep:log",
11 "embassy-sync/log",
12 "embassy-executor/log",
13 "embassy-time/log",
14 "embassy-nrf/log",
15]
16
17[dependencies]
18embassy-sync = { version = "0.1.0", path = "../../embassy-sync" }
19embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt", "integrated-timers"] }
20embassy-time = { version = "0.1.0", path = "../../embassy-time" }
21embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
22
23cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
24cortex-m-rt = "0.7.0"
25panic-probe = { version = "0.3" }
26futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
27rand = { version = "0.8.4", default-features = false }
28serde = { version = "1.0.136", default-features = false }
29rtos-trace = "0.1.3"
30systemview-target = { version = "0.1.2", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] }
31log = { version = "0.4.17", optional = true }
32
33[[bin]]
34name = "rtos_trace"
35required-features = ["nightly"]
diff --git a/examples/nrf-rtos-trace/build.rs b/examples/nrf-rtos-trace/build.rs
new file mode 100644
index 000000000..36cdb65a8
--- /dev/null
+++ b/examples/nrf-rtos-trace/build.rs
@@ -0,0 +1,36 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 #[cfg(feature = "defmt")]
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36}
diff --git a/examples/nrf-rtos-trace/memory.x b/examples/nrf-rtos-trace/memory.x
new file mode 100644
index 000000000..9b04edec0
--- /dev/null
+++ b/examples/nrf-rtos-trace/memory.x
@@ -0,0 +1,7 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */
5 FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
6 RAM : ORIGIN = 0x20000000, LENGTH = 256K
7}
diff --git a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs
new file mode 100644
index 000000000..7d1ad87c8
--- /dev/null
+++ b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs
@@ -0,0 +1,69 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use core::task::Poll;
6
7use embassy_executor::Spawner;
8use embassy_time::{Duration, Instant, Timer};
9#[cfg(feature = "log")]
10use log::*;
11use panic_probe as _;
12// N.B. systemview_target cannot be used at the same time as defmt_rtt.
13use rtos_trace;
14use systemview_target::SystemView;
15
16static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new();
17rtos_trace::global_trace! {SystemView}
18
19struct TraceInfo();
20
21impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo {
22 fn system_description() {}
23 fn sysclock() -> u32 {
24 64000000
25 }
26}
27rtos_trace::global_application_callbacks! {TraceInfo}
28
29#[embassy_executor::task]
30async fn run1() {
31 loop {
32 #[cfg(feature = "log")]
33 info!("DING DONG");
34 #[cfg(not(feature = "log"))]
35 rtos_trace::trace::marker(13);
36 Timer::after(Duration::from_ticks(16000)).await;
37 }
38}
39
40#[embassy_executor::task]
41async fn run2() {
42 loop {
43 Timer::at(Instant::from_ticks(0)).await;
44 }
45}
46
47#[embassy_executor::task]
48async fn run3() {
49 futures::future::poll_fn(|cx| {
50 cx.waker().wake_by_ref();
51 Poll::<()>::Pending
52 })
53 .await;
54}
55
56#[embassy_executor::main]
57async fn main(spawner: Spawner) {
58 let _p = embassy_nrf::init(Default::default());
59 LOGGER.init();
60 #[cfg(feature = "log")]
61 {
62 ::log::set_logger(&LOGGER).ok();
63 ::log::set_max_level(::log::LevelFilter::Trace);
64 }
65
66 spawner.spawn(run1()).unwrap();
67 spawner.spawn(run2()).unwrap();
68 spawner.spawn(run3()).unwrap();
69}
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml
index 876dcf734..8309dda08 100644
--- a/examples/nrf/Cargo.toml
+++ b/examples/nrf/Cargo.toml
@@ -8,7 +8,8 @@ default = ["nightly"]
8nightly = ["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"] 8nightly = ["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"]
9 9
10[dependencies] 10[dependencies]
11embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 11embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
12embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 13embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
13embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 14embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
14embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } 15embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
@@ -22,6 +23,7 @@ embedded-io = "0.3.0"
22defmt = "0.3" 23defmt = "0.3"
23defmt-rtt = "0.3" 24defmt-rtt = "0.3"
24 25
26static_cell = "1.0"
25cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } 27cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
26cortex-m-rt = "0.7.0" 28cortex-m-rt = "0.7.0"
27panic-probe = { version = "0.3", features = ["print-defmt"] } 29panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs
index 195200988..d782a79e7 100644
--- a/examples/nrf/src/bin/channel.rs
+++ b/examples/nrf/src/bin/channel.rs
@@ -5,9 +5,9 @@
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_sync::channel::Channel;
8use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
9use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
10use embassy_util::channel::mpmc::Channel;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13enum LedState { 13enum LedState {
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs
index c9c458aec..fcccdaed5 100644
--- a/examples/nrf/src/bin/channel_sender_receiver.rs
+++ b/examples/nrf/src/bin/channel_sender_receiver.rs
@@ -5,10 +5,10 @@
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; 7use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
8use embassy_sync::blocking_mutex::raw::NoopRawMutex;
9use embassy_sync::channel::{Channel, Receiver, Sender};
8use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
9use embassy_util::blocking_mutex::raw::NoopRawMutex; 11use static_cell::StaticCell;
10use embassy_util::channel::mpmc::{Channel, Receiver, Sender};
11use embassy_util::Forever;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14enum LedState { 14enum LedState {
@@ -16,7 +16,7 @@ enum LedState {
16 Off, 16 Off,
17} 17}
18 18
19static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new(); 19static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new();
20 20
21#[embassy_executor::task] 21#[embassy_executor::task]
22async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { 22async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
@@ -43,7 +43,7 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta
43#[embassy_executor::main] 43#[embassy_executor::main]
44async fn main(spawner: Spawner) { 44async fn main(spawner: Spawner) {
45 let p = embassy_nrf::init(Default::default()); 45 let p = embassy_nrf::init(Default::default());
46 let channel = CHANNEL.put(Channel::new()); 46 let channel = CHANNEL.init(Channel::new());
47 47
48 unwrap!(spawner.spawn(send_task(channel.sender()))); 48 unwrap!(spawner.spawn(send_task(channel.sender())));
49 unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); 49 unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver())));
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs
index b653689a7..25806ae48 100644
--- a/examples/nrf/src/bin/multiprio.rs
+++ b/examples/nrf/src/bin/multiprio.rs
@@ -63,7 +63,7 @@ use embassy_nrf::executor::{Executor, InterruptExecutor};
63use embassy_nrf::interrupt; 63use embassy_nrf::interrupt;
64use embassy_nrf::interrupt::InterruptExt; 64use embassy_nrf::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use static_cell::StaticCell;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
69#[embassy_executor::task] 69#[embassy_executor::task]
@@ -108,9 +108,9 @@ async fn run_low() {
108 } 108 }
109} 109}
110 110
111static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new(); 111static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new();
112static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new(); 112static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new();
113static EXECUTOR_LOW: Forever<Executor> = Forever::new(); 113static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
114 114
115#[entry] 115#[entry]
116fn main() -> ! { 116fn main() -> ! {
@@ -121,19 +121,19 @@ fn main() -> ! {
121 // High-priority executor: SWI1_EGU1, priority level 6 121 // High-priority executor: SWI1_EGU1, priority level 6
122 let irq = interrupt::take!(SWI1_EGU1); 122 let irq = interrupt::take!(SWI1_EGU1);
123 irq.set_priority(interrupt::Priority::P6); 123 irq.set_priority(interrupt::Priority::P6);
124 let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); 124 let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
125 let spawner = executor.start(); 125 let spawner = executor.start();
126 unwrap!(spawner.spawn(run_high())); 126 unwrap!(spawner.spawn(run_high()));
127 127
128 // Medium-priority executor: SWI0_EGU0, priority level 7 128 // Medium-priority executor: SWI0_EGU0, priority level 7
129 let irq = interrupt::take!(SWI0_EGU0); 129 let irq = interrupt::take!(SWI0_EGU0);
130 irq.set_priority(interrupt::Priority::P7); 130 irq.set_priority(interrupt::Priority::P7);
131 let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); 131 let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
132 let spawner = executor.start(); 132 let spawner = executor.start();
133 unwrap!(spawner.spawn(run_med())); 133 unwrap!(spawner.spawn(run_med()));
134 134
135 // Low priority executor: runs in thread mode, using WFE/SEV 135 // Low priority executor: runs in thread mode, using WFE/SEV
136 let executor = EXECUTOR_LOW.put(Executor::new()); 136 let executor = EXECUTOR_LOW.init(Executor::new());
137 executor.run(|spawner| { 137 executor.run(|spawner| {
138 unwrap!(spawner.spawn(run_low())); 138 unwrap!(spawner.spawn(run_low()));
139 }); 139 });
diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs
index 876297883..c402c6ba1 100644
--- a/examples/nrf/src/bin/mutex.rs
+++ b/examples/nrf/src/bin/mutex.rs
@@ -4,9 +4,9 @@
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
8use embassy_sync::mutex::Mutex;
7use embassy_time::{Duration, Timer}; 9use embassy_time::{Duration, Timer};
8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_util::mutex::Mutex;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); 12static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0);
diff --git a/examples/nrf/src/bin/pubsub.rs b/examples/nrf/src/bin/pubsub.rs
index 1d90217f2..688e6d075 100644
--- a/examples/nrf/src/bin/pubsub.rs
+++ b/examples/nrf/src/bin/pubsub.rs
@@ -4,9 +4,9 @@
4 4
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
8use embassy_sync::pubsub::{DynSubscriber, PubSubChannel, Subscriber};
7use embassy_time::{Duration, Timer}; 9use embassy_time::{Duration, Timer};
8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_util::channel::pubsub::{DynSubscriber, PubSubChannel, Subscriber};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12/// Create the message bus. It has a queue of 4, supports 3 subscribers and 1 publisher 12/// Create the message bus. It has a queue of 4, supports 3 subscribers and 1 publisher
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs
index 415579be7..1b067f5e4 100644
--- a/examples/nrf/src/bin/raw_spawn.rs
+++ b/examples/nrf/src/bin/raw_spawn.rs
@@ -8,7 +8,7 @@ use defmt::{info, unwrap};
8use embassy_executor::raw::TaskStorage; 8use embassy_executor::raw::TaskStorage;
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
11use embassy_util::Forever; 11use static_cell::StaticCell;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14async fn run1() { 14async fn run1() {
@@ -25,14 +25,14 @@ async fn run2() {
25 } 25 }
26} 26}
27 27
28static EXECUTOR: Forever<Executor> = Forever::new(); 28static EXECUTOR: StaticCell<Executor> = StaticCell::new();
29 29
30#[entry] 30#[entry]
31fn main() -> ! { 31fn main() -> ! {
32 info!("Hello World!"); 32 info!("Hello World!");
33 33
34 let _p = embassy_nrf::init(Default::default()); 34 let _p = embassy_nrf::init(Default::default());
35 let executor = EXECUTOR.put(Executor::new()); 35 let executor = EXECUTOR.init(Executor::new());
36 36
37 let run1_task = TaskStorage::new(); 37 let run1_task = TaskStorage::new();
38 let run2_task = TaskStorage::new(); 38 let run2_task = TaskStorage::new();
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
index dab8e475d..1adaf53fd 100644
--- a/examples/nrf/src/bin/uart_split.rs
+++ b/examples/nrf/src/bin/uart_split.rs
@@ -7,8 +7,8 @@ use embassy_executor::Spawner;
7use embassy_nrf::peripherals::UARTE0; 7use embassy_nrf::peripherals::UARTE0;
8use embassy_nrf::uarte::UarteRx; 8use embassy_nrf::uarte::UarteRx;
9use embassy_nrf::{interrupt, uarte}; 9use embassy_nrf::{interrupt, uarte};
10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 10use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy_util::channel::mpmc::Channel; 11use embassy_sync::channel::Channel;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); 14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs
index f0a870317..ca6c7e0d1 100644
--- a/examples/nrf/src/bin/usb_ethernet.rs
+++ b/examples/nrf/src/bin/usb_ethernet.rs
@@ -14,21 +14,21 @@ use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources};
14use embassy_nrf::rng::Rng; 14use embassy_nrf::rng::Rng;
15use embassy_nrf::usb::{Driver, PowerUsb}; 15use embassy_nrf::usb::{Driver, PowerUsb};
16use embassy_nrf::{interrupt, pac, peripherals}; 16use embassy_nrf::{interrupt, pac, peripherals};
17use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
18use embassy_sync::channel::Channel;
17use embassy_usb::{Builder, Config, UsbDevice}; 19use embassy_usb::{Builder, Config, UsbDevice};
18use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 20use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
20use embassy_util::channel::mpmc::Channel;
21use embassy_util::Forever;
22use embedded_io::asynch::{Read, Write}; 21use embedded_io::asynch::{Read, Write};
22use static_cell::StaticCell;
23use {defmt_rtt as _, panic_probe as _}; 23use {defmt_rtt as _, panic_probe as _};
24 24
25type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; 25type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>;
26 26
27macro_rules! forever { 27macro_rules! singleton {
28 ($val:expr) => {{ 28 ($val:expr) => {{
29 type T = impl Sized; 29 type T = impl Sized;
30 static FOREVER: Forever<T> = Forever::new(); 30 static STATIC_CELL: StaticCell<T> = StaticCell::new();
31 FOREVER.put_with(move || $val) 31 STATIC_CELL.init_with(move || $val)
32 }}; 32 }};
33} 33}
34 34
@@ -116,7 +116,7 @@ async fn main(spawner: Spawner) {
116 control_buf: [u8; 128], 116 control_buf: [u8; 128],
117 serial_state: State<'static>, 117 serial_state: State<'static>,
118 } 118 }
119 let res: &mut Resources = forever!(Resources { 119 let res: &mut Resources = singleton!(Resources {
120 device_descriptor: [0; 256], 120 device_descriptor: [0; 256],
121 config_descriptor: [0; 256], 121 config_descriptor: [0; 256],
122 bos_descriptor: [0; 256], 122 bos_descriptor: [0; 256],
@@ -174,10 +174,10 @@ async fn main(spawner: Spawner) {
174 174
175 // Init network stack 175 // Init network stack
176 let device = Device { mac_addr: our_mac_addr }; 176 let device = Device { mac_addr: our_mac_addr };
177 let stack = &*forever!(Stack::new( 177 let stack = &*singleton!(Stack::new(
178 device, 178 device,
179 config, 179 config,
180 forever!(StackResources::<1, 2, 8>::new()), 180 singleton!(StackResources::<1, 2, 8>::new()),
181 seed 181 seed
182 )); 182 ));
183 183
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs
index cf0078eec..ba2159c72 100644
--- a/examples/nrf/src/bin/usb_hid_keyboard.rs
+++ b/examples/nrf/src/bin/usb_hid_keyboard.rs
@@ -8,14 +8,14 @@ use core::sync::atomic::{AtomicBool, Ordering};
8 8
9use defmt::*; 9use defmt::*;
10use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_futures::{select, Either};
11use embassy_nrf::gpio::{Input, Pin, Pull}; 12use embassy_nrf::gpio::{Input, Pin, Pull};
12use embassy_nrf::usb::{Driver, PowerUsb}; 13use embassy_nrf::usb::{Driver, PowerUsb};
13use embassy_nrf::{interrupt, pac}; 14use embassy_nrf::{interrupt, pac};
15use embassy_sync::signal::Signal;
14use embassy_usb::control::OutResponse; 16use embassy_usb::control::OutResponse;
15use embassy_usb::{Builder, Config, DeviceStateHandler}; 17use embassy_usb::{Builder, Config, DeviceStateHandler};
16use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; 18use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State};
17use embassy_util::channel::signal::Signal;
18use embassy_util::{select, Either};
19use futures::future::join; 19use futures::future::join;
20use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; 20use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor};
21use {defmt_rtt as _, panic_probe as _}; 21use {defmt_rtt as _, panic_probe as _};
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs
index 4c1a93087..d62d7e520 100644
--- a/examples/nrf/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf/src/bin/usb_serial_multitask.rs
@@ -12,7 +12,7 @@ use embassy_nrf::{interrupt, pac, peripherals};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
13use embassy_usb::{Builder, Config, UsbDevice}; 13use embassy_usb::{Builder, Config, UsbDevice};
14use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
15use embassy_util::Forever; 15use static_cell::StaticCell;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; 18type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>;
@@ -67,8 +67,8 @@ async fn main(spawner: Spawner) {
67 control_buf: [u8; 64], 67 control_buf: [u8; 64],
68 serial_state: State<'static>, 68 serial_state: State<'static>,
69 } 69 }
70 static RESOURCES: Forever<Resources> = Forever::new(); 70 static RESOURCES: StaticCell<Resources> = StaticCell::new();
71 let res = RESOURCES.put(Resources { 71 let res = RESOURCES.init(Resources {
72 device_descriptor: [0; 256], 72 device_descriptor: [0; 256],
73 config_descriptor: [0; 256], 73 config_descriptor: [0; 256],
74 bos_descriptor: [0; 256], 74 bos_descriptor: [0; 256],
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index c2dcf429a..d804a660b 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -5,7 +5,7 @@ version = "0.1.0"
5 5
6 6
7[dependencies] 7[dependencies]
8embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 8embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
11embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] } 11embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac"] }
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml
index b7009017c..c7cec6b19 100644
--- a/examples/std/Cargo.toml
+++ b/examples/std/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-std-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["log"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] }
10embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] } 10embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] }
@@ -20,3 +20,4 @@ libc = "0.2.101"
20clap = { version = "3.0.0-beta.5", features = ["derive"] } 20clap = { version = "3.0.0-beta.5", features = ["derive"] }
21rand_core = { version = "0.6.3", features = ["std"] } 21rand_core = { version = "0.6.3", features = ["std"] }
22heapless = { version = "0.7.5", default-features = false } 22heapless = { version = "0.7.5", default-features = false }
23static_cell = "1.0"
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index 528609260..9b1450b72 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -4,22 +4,22 @@ use clap::Parser;
4use embassy_executor::{Executor, Spawner}; 4use embassy_executor::{Executor, Spawner};
5use embassy_net::tcp::TcpSocket; 5use embassy_net::tcp::TcpSocket;
6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources}; 6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources};
7use embassy_util::Forever;
8use embedded_io::asynch::Write; 7use embedded_io::asynch::Write;
9use heapless::Vec; 8use heapless::Vec;
10use log::*; 9use log::*;
11use rand_core::{OsRng, RngCore}; 10use rand_core::{OsRng, RngCore};
11use static_cell::StaticCell;
12 12
13#[path = "../tuntap.rs"] 13#[path = "../tuntap.rs"]
14mod tuntap; 14mod tuntap;
15 15
16use crate::tuntap::TunTapDevice; 16use crate::tuntap::TunTapDevice;
17 17
18macro_rules! forever { 18macro_rules! singleton {
19 ($val:expr) => {{ 19 ($val:expr) => {{
20 type T = impl Sized; 20 type T = impl Sized;
21 static FOREVER: Forever<T> = Forever::new(); 21 static STATIC_CELL: StaticCell<T> = StaticCell::new();
22 FOREVER.put_with(move || $val) 22 STATIC_CELL.init_with(move || $val)
23 }}; 23 }};
24} 24}
25 25
@@ -63,10 +63,10 @@ async fn main_task(spawner: Spawner) {
63 let seed = u64::from_le_bytes(seed); 63 let seed = u64::from_le_bytes(seed);
64 64
65 // Init network stack 65 // Init network stack
66 let stack = &*forever!(Stack::new( 66 let stack = &*singleton!(Stack::new(
67 device, 67 device,
68 config, 68 config,
69 forever!(StackResources::<1, 2, 8>::new()), 69 singleton!(StackResources::<1, 2, 8>::new()),
70 seed 70 seed
71 )); 71 ));
72 72
@@ -97,7 +97,7 @@ async fn main_task(spawner: Spawner) {
97 } 97 }
98} 98}
99 99
100static EXECUTOR: Forever<Executor> = Forever::new(); 100static EXECUTOR: StaticCell<Executor> = StaticCell::new();
101 101
102fn main() { 102fn main() {
103 env_logger::builder() 103 env_logger::builder()
@@ -106,7 +106,7 @@ fn main() {
106 .format_timestamp_nanos() 106 .format_timestamp_nanos()
107 .init(); 107 .init();
108 108
109 let executor = EXECUTOR.put(Executor::new()); 109 let executor = EXECUTOR.init(Executor::new());
110 executor.run(|spawner| { 110 executor.run(|spawner| {
111 spawner.spawn(main_task(spawner)).unwrap(); 111 spawner.spawn(main_task(spawner)).unwrap();
112 }); 112 });
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs
index 07e11c385..392a97f0d 100644
--- a/examples/std/src/bin/net_udp.rs
+++ b/examples/std/src/bin/net_udp.rs
@@ -4,21 +4,21 @@ use clap::Parser;
4use embassy_executor::{Executor, Spawner}; 4use embassy_executor::{Executor, Spawner};
5use embassy_net::udp::UdpSocket; 5use embassy_net::udp::UdpSocket;
6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; 6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources};
7use embassy_util::Forever;
8use heapless::Vec; 7use heapless::Vec;
9use log::*; 8use log::*;
10use rand_core::{OsRng, RngCore}; 9use rand_core::{OsRng, RngCore};
10use static_cell::StaticCell;
11 11
12#[path = "../tuntap.rs"] 12#[path = "../tuntap.rs"]
13mod tuntap; 13mod tuntap;
14 14
15use crate::tuntap::TunTapDevice; 15use crate::tuntap::TunTapDevice;
16 16
17macro_rules! forever { 17macro_rules! singleton {
18 ($val:expr) => {{ 18 ($val:expr) => {{
19 type T = impl Sized; 19 type T = impl Sized;
20 static FOREVER: Forever<T> = Forever::new(); 20 static STATIC_CELL: StaticCell<T> = StaticCell::new();
21 FOREVER.put_with(move || $val) 21 STATIC_CELL.init_with(move || $val)
22 }}; 22 }};
23} 23}
24 24
@@ -62,10 +62,10 @@ async fn main_task(spawner: Spawner) {
62 let seed = u64::from_le_bytes(seed); 62 let seed = u64::from_le_bytes(seed);
63 63
64 // Init network stack 64 // Init network stack
65 let stack = &*forever!(Stack::new( 65 let stack = &*singleton!(Stack::new(
66 device, 66 device,
67 config, 67 config,
68 forever!(StackResources::<1, 2, 8>::new()), 68 singleton!(StackResources::<1, 2, 8>::new()),
69 seed 69 seed
70 )); 70 ));
71 71
@@ -93,7 +93,7 @@ async fn main_task(spawner: Spawner) {
93 } 93 }
94} 94}
95 95
96static EXECUTOR: Forever<Executor> = Forever::new(); 96static EXECUTOR: StaticCell<Executor> = StaticCell::new();
97 97
98fn main() { 98fn main() {
99 env_logger::builder() 99 env_logger::builder()
@@ -102,7 +102,7 @@ fn main() {
102 .format_timestamp_nanos() 102 .format_timestamp_nanos()
103 .init(); 103 .init();
104 104
105 let executor = EXECUTOR.put(Executor::new()); 105 let executor = EXECUTOR.init(Executor::new());
106 executor.run(|spawner| { 106 executor.run(|spawner| {
107 spawner.spawn(main_task(spawner)).unwrap(); 107 spawner.spawn(main_task(spawner)).unwrap();
108 }); 108 });
diff --git a/examples/std/src/bin/serial.rs b/examples/std/src/bin/serial.rs
index 35cba4cee..85ee54f70 100644
--- a/examples/std/src/bin/serial.rs
+++ b/examples/std/src/bin/serial.rs
@@ -5,10 +5,10 @@ mod serial_port;
5 5
6use async_io::Async; 6use async_io::Async;
7use embassy_executor::Executor; 7use embassy_executor::Executor;
8use embassy_util::Forever;
9use embedded_io::asynch::Read; 8use embedded_io::asynch::Read;
10use log::*; 9use log::*;
11use nix::sys::termios; 10use nix::sys::termios;
11use static_cell::StaticCell;
12 12
13use self::serial_port::SerialPort; 13use self::serial_port::SerialPort;
14 14
@@ -40,7 +40,7 @@ async fn run() {
40 } 40 }
41} 41}
42 42
43static EXECUTOR: Forever<Executor> = Forever::new(); 43static EXECUTOR: StaticCell<Executor> = StaticCell::new();
44 44
45fn main() { 45fn main() {
46 env_logger::builder() 46 env_logger::builder()
@@ -49,7 +49,7 @@ fn main() {
49 .format_timestamp_nanos() 49 .format_timestamp_nanos()
50 .init(); 50 .init();
51 51
52 let executor = EXECUTOR.put(Executor::new()); 52 let executor = EXECUTOR.init(Executor::new());
53 executor.run(|spawner| { 53 executor.run(|spawner| {
54 spawner.spawn(run()).unwrap(); 54 spawner.spawn(run()).unwrap();
55 }); 55 });
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index 8476200d4..cd2995d2c 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -11,7 +11,7 @@ cortex-m-rt = "0.7.0"
11defmt = "0.3" 11defmt = "0.3"
12defmt-rtt = "0.3" 12defmt-rtt = "0.3"
13panic-probe = "0.3" 13panic-probe = "0.3"
14embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 14embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
15embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 15embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
16embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 16embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
17embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] } 17embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f030f4", "time-driver-any"] }
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml
index fbc96400c..8660e743d 100644
--- a/examples/stm32f1/Cargo.toml
+++ b/examples/stm32f1/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32f1-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] }
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml
index 27894df50..b4bff4d85 100644
--- a/examples/stm32f2/Cargo.toml
+++ b/examples/stm32f2/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32f2-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index b5ea28bb6..d152b145f 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32f3-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
@@ -23,3 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
23heapless = { version = "0.7.5", default-features = false } 23heapless = { version = "0.7.5", default-features = false }
24nb = "1.0.0" 24nb = "1.0.0"
25embedded-storage = "0.3.0" 25embedded-storage = "0.3.0"
26static_cell = "1.0"
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs
index 61fc6dcab..02c475f66 100644
--- a/examples/stm32f3/src/bin/button_events.rs
+++ b/examples/stm32f3/src/bin/button_events.rs
@@ -15,9 +15,9 @@ use embassy_executor::Spawner;
15use embassy_stm32::exti::ExtiInput; 15use embassy_stm32::exti::ExtiInput;
16use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; 16use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed};
17use embassy_stm32::peripherals::PA0; 17use embassy_stm32::peripherals::PA0;
18use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
19use embassy_sync::channel::Channel;
18use embassy_time::{with_timeout, Duration, Timer}; 20use embassy_time::{with_timeout, Duration, Timer};
19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
20use embassy_util::channel::mpmc::Channel;
21use {defmt_rtt as _, panic_probe as _}; 21use {defmt_rtt as _, panic_probe as _};
22 22
23struct Leds<'a> { 23struct Leds<'a> {
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs
index e96c31249..9e8228a4b 100644
--- a/examples/stm32f3/src/bin/multiprio.rs
+++ b/examples/stm32f3/src/bin/multiprio.rs
@@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor};
63use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
64use embassy_stm32::interrupt::InterruptExt; 64use embassy_stm32::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use static_cell::StaticCell;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
69#[embassy_executor::task] 69#[embassy_executor::task]
@@ -108,9 +108,9 @@ async fn run_low() {
108 } 108 }
109} 109}
110 110
111static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new(); 111static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new();
112static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new(); 112static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new();
113static EXECUTOR_LOW: Forever<Executor> = Forever::new(); 113static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
114 114
115#[entry] 115#[entry]
116fn main() -> ! { 116fn main() -> ! {
@@ -121,19 +121,19 @@ fn main() -> ! {
121 // High-priority executor: SWI1_EGU1, priority level 6 121 // High-priority executor: SWI1_EGU1, priority level 6
122 let irq = interrupt::take!(UART4); 122 let irq = interrupt::take!(UART4);
123 irq.set_priority(interrupt::Priority::P6); 123 irq.set_priority(interrupt::Priority::P6);
124 let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); 124 let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
125 let spawner = executor.start(); 125 let spawner = executor.start();
126 unwrap!(spawner.spawn(run_high())); 126 unwrap!(spawner.spawn(run_high()));
127 127
128 // Medium-priority executor: SWI0_EGU0, priority level 7 128 // Medium-priority executor: SWI0_EGU0, priority level 7
129 let irq = interrupt::take!(UART5); 129 let irq = interrupt::take!(UART5);
130 irq.set_priority(interrupt::Priority::P7); 130 irq.set_priority(interrupt::Priority::P7);
131 let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); 131 let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
132 let spawner = executor.start(); 132 let spawner = executor.start();
133 unwrap!(spawner.spawn(run_med())); 133 unwrap!(spawner.spawn(run_med()));
134 134
135 // Low priority executor: runs in thread mode, using WFE/SEV 135 // Low priority executor: runs in thread mode, using WFE/SEV
136 let executor = EXECUTOR_LOW.put(Executor::new()); 136 let executor = EXECUTOR_LOW.init(Executor::new());
137 executor.run(|spawner| { 137 executor.run(|spawner| {
138 unwrap!(spawner.spawn(run_low())); 138 unwrap!(spawner.spawn(run_low()));
139 }); 139 });
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 04a217aff..9bfdda92d 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -5,7 +5,7 @@ version = "0.1.0"
5 5
6 6
7[dependencies] 7[dependencies]
8embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 8embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
@@ -23,6 +23,7 @@ heapless = { version = "0.7.5", default-features = false }
23nb = "1.0.0" 23nb = "1.0.0"
24embedded-storage = "0.3.0" 24embedded-storage = "0.3.0"
25micromath = "2.0.0" 25micromath = "2.0.0"
26static_cell = "1.0"
26 27
27usb-device = "0.2" 28usb-device = "0.2"
28usbd-serial = "0.1.1" 29usbd-serial = "0.1.1"
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs
index e96c31249..9e8228a4b 100644
--- a/examples/stm32f4/src/bin/multiprio.rs
+++ b/examples/stm32f4/src/bin/multiprio.rs
@@ -63,7 +63,7 @@ use embassy_stm32::executor::{Executor, InterruptExecutor};
63use embassy_stm32::interrupt; 63use embassy_stm32::interrupt;
64use embassy_stm32::interrupt::InterruptExt; 64use embassy_stm32::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use static_cell::StaticCell;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
69#[embassy_executor::task] 69#[embassy_executor::task]
@@ -108,9 +108,9 @@ async fn run_low() {
108 } 108 }
109} 109}
110 110
111static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::UART4>> = Forever::new(); 111static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new();
112static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::UART5>> = Forever::new(); 112static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new();
113static EXECUTOR_LOW: Forever<Executor> = Forever::new(); 113static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
114 114
115#[entry] 115#[entry]
116fn main() -> ! { 116fn main() -> ! {
@@ -121,19 +121,19 @@ fn main() -> ! {
121 // High-priority executor: SWI1_EGU1, priority level 6 121 // High-priority executor: SWI1_EGU1, priority level 6
122 let irq = interrupt::take!(UART4); 122 let irq = interrupt::take!(UART4);
123 irq.set_priority(interrupt::Priority::P6); 123 irq.set_priority(interrupt::Priority::P6);
124 let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); 124 let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
125 let spawner = executor.start(); 125 let spawner = executor.start();
126 unwrap!(spawner.spawn(run_high())); 126 unwrap!(spawner.spawn(run_high()));
127 127
128 // Medium-priority executor: SWI0_EGU0, priority level 7 128 // Medium-priority executor: SWI0_EGU0, priority level 7
129 let irq = interrupt::take!(UART5); 129 let irq = interrupt::take!(UART5);
130 irq.set_priority(interrupt::Priority::P7); 130 irq.set_priority(interrupt::Priority::P7);
131 let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); 131 let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
132 let spawner = executor.start(); 132 let spawner = executor.start();
133 unwrap!(spawner.spawn(run_med())); 133 unwrap!(spawner.spawn(run_med()));
134 134
135 // Low priority executor: runs in thread mode, using WFE/SEV 135 // Low priority executor: runs in thread mode, using WFE/SEV
136 let executor = EXECUTOR_LOW.put(Executor::new()); 136 let executor = EXECUTOR_LOW.init(Executor::new());
137 executor.run(|spawner| { 137 executor.run(|spawner| {
138 unwrap!(spawner.spawn(run_low())); 138 unwrap!(spawner.spawn(run_low()));
139 }); 139 });
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
index 29d6da4d8..a446fe3fb 100644
--- a/examples/stm32f7/Cargo.toml
+++ b/examples/stm32f7/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32f7-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] }
@@ -24,3 +24,4 @@ nb = "1.0.0"
24rand_core = "0.6.3" 24rand_core = "0.6.3"
25critical-section = "1.1" 25critical-section = "1.1"
26embedded-storage = "0.3.0" 26embedded-storage = "0.3.0"
27static_cell = "1.0"
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index bdffabcb3..5202edf62 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{interrupt, Config}; 14use embassy_stm32::{interrupt, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embassy_util::Forever;
17use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
18use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::StaticCell;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20 20
21macro_rules! forever { 21macro_rules! singleton {
22 ($val:expr) => {{ 22 ($val:expr) => {{
23 type T = impl Sized; 23 type T = impl Sized;
24 static FOREVER: Forever<T> = Forever::new(); 24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 FOREVER.put_with(move || $val) 25 STATIC_CELL.init_with(move || $val)
26 }}; 26 }};
27} 27}
28 28
@@ -52,7 +52,7 @@ async fn main(spawner: Spawner) -> ! {
52 52
53 let device = unsafe { 53 let device = unsafe {
54 Ethernet::new( 54 Ethernet::new(
55 forever!(State::new()), 55 singleton!(State::new()),
56 p.ETH, 56 p.ETH,
57 eth_int, 57 eth_int,
58 p.PA1, 58 p.PA1,
@@ -78,10 +78,10 @@ async fn main(spawner: Spawner) -> ! {
78 //}); 78 //});
79 79
80 // Init network stack 80 // Init network stack
81 let stack = &*forever!(Stack::new( 81 let stack = &*singleton!(Stack::new(
82 device, 82 device,
83 config, 83 config,
84 forever!(StackResources::<1, 2, 8>::new()), 84 singleton!(StackResources::<1, 2, 8>::new()),
85 seed 85 seed
86 )); 86 ));
87 87
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml
index 5c80d43eb..30f2b86f8 100644
--- a/examples/stm32g0/Cargo.toml
+++ b/examples/stm32g0/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32g0-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] }
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml
index 74c645cf5..f81df0b70 100644
--- a/examples/stm32g4/Cargo.toml
+++ b/examples/stm32g4/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32g4-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] }
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index a416796ea..0f76f3226 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32h7-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
@@ -28,6 +28,7 @@ critical-section = "1.1"
28micromath = "2.0.0" 28micromath = "2.0.0"
29stm32-fmc = "0.2.4" 29stm32-fmc = "0.2.4"
30embedded-storage = "0.3.0" 30embedded-storage = "0.3.0"
31static_cell = "1.0"
31 32
32# cargo build/run 33# cargo build/run
33[profile.dev] 34[profile.dev]
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 83210bcb5..4ccc0b5ef 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{interrupt, Config}; 14use embassy_stm32::{interrupt, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embassy_util::Forever;
17use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
18use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::StaticCell;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20 20
21macro_rules! forever { 21macro_rules! singleton {
22 ($val:expr) => {{ 22 ($val:expr) => {{
23 type T = impl Sized; 23 type T = impl Sized;
24 static FOREVER: Forever<T> = Forever::new(); 24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 FOREVER.put_with(move || $val) 25 STATIC_CELL.init_with(move || $val)
26 }}; 26 }};
27} 27}
28 28
@@ -53,7 +53,7 @@ async fn main(spawner: Spawner) -> ! {
53 53
54 let device = unsafe { 54 let device = unsafe {
55 Ethernet::new( 55 Ethernet::new(
56 forever!(State::new()), 56 singleton!(State::new()),
57 p.ETH, 57 p.ETH,
58 eth_int, 58 eth_int,
59 p.PA1, 59 p.PA1,
@@ -79,10 +79,10 @@ async fn main(spawner: Spawner) -> ! {
79 //}); 79 //});
80 80
81 // Init network stack 81 // Init network stack
82 let stack = &*forever!(Stack::new( 82 let stack = &*singleton!(Stack::new(
83 device, 83 device,
84 config, 84 config,
85 forever!(StackResources::<1, 2, 8>::new()), 85 singleton!(StackResources::<1, 2, 8>::new()),
86 seed 86 seed
87 )); 87 ));
88 88
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 99946f504..64fd84141 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -13,17 +13,17 @@ use embassy_stm32::rng::Rng;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{interrupt, Config}; 14use embassy_stm32::{interrupt, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embassy_util::Forever;
17use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
18use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; 17use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
19use rand_core::RngCore; 18use rand_core::RngCore;
19use static_cell::StaticCell;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22macro_rules! forever { 22macro_rules! singleton {
23 ($val:expr) => {{ 23 ($val:expr) => {{
24 type T = impl Sized; 24 type T = impl Sized;
25 static FOREVER: Forever<T> = Forever::new(); 25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 FOREVER.put_with(move || $val) 26 STATIC_CELL.init_with(move || $val)
27 }}; 27 }};
28} 28}
29 29
@@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! {
54 54
55 let device = unsafe { 55 let device = unsafe {
56 Ethernet::new( 56 Ethernet::new(
57 forever!(State::new()), 57 singleton!(State::new()),
58 p.ETH, 58 p.ETH,
59 eth_int, 59 eth_int,
60 p.PA1, 60 p.PA1,
@@ -80,10 +80,10 @@ async fn main(spawner: Spawner) -> ! {
80 //}); 80 //});
81 81
82 // Init network stack 82 // Init network stack
83 let stack = &*forever!(Stack::new( 83 let stack = &*singleton!(Stack::new(
84 device, 84 device,
85 config, 85 config,
86 forever!(StackResources::<1, 2, 8>::new()), 86 singleton!(StackResources::<1, 2, 8>::new()),
87 seed 87 seed
88 )); 88 ));
89 89
diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs
index be2ac268e..cc3e4e3ca 100644
--- a/examples/stm32h7/src/bin/signal.rs
+++ b/examples/stm32h7/src/bin/signal.rs
@@ -4,8 +4,8 @@
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_sync::signal::Signal;
7use embassy_time::{Duration, Timer}; 8use embassy_time::{Duration, Timer};
8use embassy_util::channel::signal::Signal;
9use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
10 10
11static SIGNAL: Signal<u32> = Signal::new(); 11static SIGNAL: Signal<u32> = Signal::new();
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index c28f937a8..1f407f002 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -12,8 +12,8 @@ use embassy_stm32::dma::NoDma;
12use embassy_stm32::peripherals::SPI3; 12use embassy_stm32::peripherals::SPI3;
13use embassy_stm32::time::mhz; 13use embassy_stm32::time::mhz;
14use embassy_stm32::{spi, Config}; 14use embassy_stm32::{spi, Config};
15use embassy_util::Forever;
16use heapless::String; 15use heapless::String;
16use static_cell::StaticCell;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
18 18
19#[embassy_executor::task] 19#[embassy_executor::task]
@@ -31,7 +31,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
31 } 31 }
32} 32}
33 33
34static EXECUTOR: Forever<Executor> = Forever::new(); 34static EXECUTOR: StaticCell<Executor> = StaticCell::new();
35 35
36#[entry] 36#[entry]
37fn main() -> ! { 37fn main() -> ! {
@@ -54,7 +54,7 @@ fn main() -> ! {
54 spi::Config::default(), 54 spi::Config::default(),
55 ); 55 );
56 56
57 let executor = EXECUTOR.put(Executor::new()); 57 let executor = EXECUTOR.init(Executor::new());
58 58
59 executor.run(|spawner| { 59 executor.run(|spawner| {
60 unwrap!(spawner.spawn(main_task(spi))); 60 unwrap!(spawner.spawn(main_task(spi)));
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 6c78c194f..53004fc9b 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -11,8 +11,8 @@ use embassy_executor::Executor;
11use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; 11use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
12use embassy_stm32::time::mhz; 12use embassy_stm32::time::mhz;
13use embassy_stm32::{spi, Config}; 13use embassy_stm32::{spi, Config};
14use embassy_util::Forever;
15use heapless::String; 14use heapless::String;
15use static_cell::StaticCell;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18#[embassy_executor::task] 18#[embassy_executor::task]
@@ -27,7 +27,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) {
27 } 27 }
28} 28}
29 29
30static EXECUTOR: Forever<Executor> = Forever::new(); 30static EXECUTOR: StaticCell<Executor> = StaticCell::new();
31 31
32#[entry] 32#[entry]
33fn main() -> ! { 33fn main() -> ! {
@@ -50,7 +50,7 @@ fn main() -> ! {
50 spi::Config::default(), 50 spi::Config::default(),
51 ); 51 );
52 52
53 let executor = EXECUTOR.put(Executor::new()); 53 let executor = EXECUTOR.init(Executor::new());
54 54
55 executor.run(|spawner| { 55 executor.run(|spawner| {
56 unwrap!(spawner.spawn(main_task(spi))); 56 unwrap!(spawner.spawn(main_task(spi)));
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
index 1384d54c6..87c2b1253 100644
--- a/examples/stm32h7/src/bin/usart.rs
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -7,7 +7,7 @@ use defmt::*;
7use embassy_executor::Executor; 7use embassy_executor::Executor;
8use embassy_stm32::dma::NoDma; 8use embassy_stm32::dma::NoDma;
9use embassy_stm32::usart::{Config, Uart}; 9use embassy_stm32::usart::{Config, Uart};
10use embassy_util::Forever; 10use static_cell::StaticCell;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13#[embassy_executor::task] 13#[embassy_executor::task]
@@ -27,13 +27,13 @@ async fn main_task() {
27 } 27 }
28} 28}
29 29
30static EXECUTOR: Forever<Executor> = Forever::new(); 30static EXECUTOR: StaticCell<Executor> = StaticCell::new();
31 31
32#[entry] 32#[entry]
33fn main() -> ! { 33fn main() -> ! {
34 info!("Hello World!"); 34 info!("Hello World!");
35 35
36 let executor = EXECUTOR.put(Executor::new()); 36 let executor = EXECUTOR.init(Executor::new());
37 37
38 executor.run(|spawner| { 38 executor.run(|spawner| {
39 unwrap!(spawner.spawn(main_task())); 39 unwrap!(spawner.spawn(main_task()));
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index f8d58bb84..3adffcbeb 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -9,8 +9,8 @@ use defmt::*;
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_stm32::dma::NoDma; 10use embassy_stm32::dma::NoDma;
11use embassy_stm32::usart::{Config, Uart}; 11use embassy_stm32::usart::{Config, Uart};
12use embassy_util::Forever;
13use heapless::String; 12use heapless::String;
13use static_cell::StaticCell;
14use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
15 15
16#[embassy_executor::task] 16#[embassy_executor::task]
@@ -30,13 +30,13 @@ async fn main_task() {
30 } 30 }
31} 31}
32 32
33static EXECUTOR: Forever<Executor> = Forever::new(); 33static EXECUTOR: StaticCell<Executor> = StaticCell::new();
34 34
35#[entry] 35#[entry]
36fn main() -> ! { 36fn main() -> ! {
37 info!("Hello World!"); 37 info!("Hello World!");
38 38
39 let executor = EXECUTOR.put(Executor::new()); 39 let executor = EXECUTOR.init(Executor::new());
40 40
41 executor.run(|spawner| { 41 executor.run(|spawner| {
42 unwrap!(spawner.spawn(main_task())); 42 unwrap!(spawner.spawn(main_task()));
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs
index 64080ec45..df2b600f8 100644
--- a/examples/stm32h7/src/bin/usart_split.rs
+++ b/examples/stm32h7/src/bin/usart_split.rs
@@ -7,8 +7,8 @@ use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::peripherals::{DMA1_CH1, UART7}; 8use embassy_stm32::peripherals::{DMA1_CH1, UART7};
9use embassy_stm32::usart::{Config, Uart, UartRx}; 9use embassy_stm32::usart::{Config, Uart, UartRx};
10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 10use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy_util::channel::mpmc::Channel; 11use embassy_sync::channel::Channel;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14#[embassy_executor::task] 14#[embassy_executor::task]
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index fdb716d15..11751a21d 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -8,7 +8,7 @@ default = ["nightly"]
8nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", "embedded-io/async"] 8nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan", "embedded-io/async"]
9 9
10[dependencies] 10[dependencies]
11embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 11embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 12embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
13embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 13embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
14embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 14embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
@@ -29,3 +29,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
29futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 29futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
30heapless = { version = "0.7.5", default-features = false } 30heapless = { version = "0.7.5", default-features = false }
31embedded-hal = "0.2.6" 31embedded-hal = "0.2.6"
32static_cell = "1.0"
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs
index bd87e62a4..edc17304a 100644
--- a/examples/stm32l0/src/bin/raw_spawn.rs
+++ b/examples/stm32l0/src/bin/raw_spawn.rs
@@ -8,7 +8,7 @@ use defmt::*;
8use embassy_executor::raw::TaskStorage; 8use embassy_executor::raw::TaskStorage;
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
11use embassy_util::Forever; 11use static_cell::StaticCell;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14async fn run1() { 14async fn run1() {
@@ -25,14 +25,14 @@ async fn run2() {
25 } 25 }
26} 26}
27 27
28static EXECUTOR: Forever<Executor> = Forever::new(); 28static EXECUTOR: StaticCell<Executor> = StaticCell::new();
29 29
30#[entry] 30#[entry]
31fn main() -> ! { 31fn main() -> ! {
32 info!("Hello World!"); 32 info!("Hello World!");
33 33
34 let _p = embassy_stm32::init(Default::default()); 34 let _p = embassy_stm32::init(Default::default());
35 let executor = EXECUTOR.put(Executor::new()); 35 let executor = EXECUTOR.init(Executor::new());
36 36
37 let run1_task = TaskStorage::new(); 37 let run1_task = TaskStorage::new();
38 let run2_task = TaskStorage::new(); 38 let run2_task = TaskStorage::new();
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml
index 43f844b67..18b35b305 100644
--- a/examples/stm32l1/Cargo.toml
+++ b/examples/stm32l1/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32l1-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] }
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml
index eaffa253e..cb7238e4c 100644
--- a/examples/stm32l4/Cargo.toml
+++ b/examples/stm32l4/Cargo.toml
@@ -6,7 +6,7 @@ version = "0.1.0"
6[features] 6[features]
7 7
8[dependencies] 8[dependencies]
9embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 9embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
12embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } 12embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index 4d96d31fc..624c73c26 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -6,7 +6,7 @@ version = "0.1.0"
6[features] 6[features]
7 7
8[dependencies] 8[dependencies]
9embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 9embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 10embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 11embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
12embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 12embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
@@ -28,3 +28,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
28heapless = { version = "0.7.5", default-features = false } 28heapless = { version = "0.7.5", default-features = false }
29rand_core = { version = "0.6.3", default-features = false } 29rand_core = { version = "0.6.3", default-features = false }
30embedded-io = { version = "0.3.0", features = ["async"] } 30embedded-io = { version = "0.3.0", features = ["async"] }
31static_cell = "1.0"
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index 7c53d03cc..3286f5c4d 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -15,22 +15,22 @@ use embassy_stm32::rng::Rng;
15use embassy_stm32::time::Hertz; 15use embassy_stm32::time::Hertz;
16use embassy_stm32::usb::Driver; 16use embassy_stm32::usb::Driver;
17use embassy_stm32::{interrupt, Config}; 17use embassy_stm32::{interrupt, Config};
18use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
19use embassy_sync::channel::Channel;
18use embassy_usb::{Builder, UsbDevice}; 20use embassy_usb::{Builder, UsbDevice};
19use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 21use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
20use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
21use embassy_util::channel::mpmc::Channel;
22use embassy_util::Forever;
23use embedded_io::asynch::{Read, Write}; 22use embedded_io::asynch::{Read, Write};
24use rand_core::RngCore; 23use rand_core::RngCore;
24use static_cell::StaticCell;
25use {defmt_rtt as _, panic_probe as _}; 25use {defmt_rtt as _, panic_probe as _};
26 26
27type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; 27type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>;
28 28
29macro_rules! forever { 29macro_rules! singleton {
30 ($val:expr) => {{ 30 ($val:expr) => {{
31 type T = impl Sized; 31 type T = impl Sized;
32 static FOREVER: Forever<T> = Forever::new(); 32 static STATIC_CELL: StaticCell<T> = StaticCell::new();
33 FOREVER.put_with(move || $val) 33 STATIC_CELL.init_with(move || $val)
34 }}; 34 }};
35} 35}
36 36
@@ -115,7 +115,7 @@ async fn main(spawner: Spawner) {
115 control_buf: [u8; 128], 115 control_buf: [u8; 128],
116 serial_state: State<'static>, 116 serial_state: State<'static>,
117 } 117 }
118 let res: &mut Resources = forever!(Resources { 118 let res: &mut Resources = singleton!(Resources {
119 device_descriptor: [0; 256], 119 device_descriptor: [0; 256],
120 config_descriptor: [0; 256], 120 config_descriptor: [0; 256],
121 bos_descriptor: [0; 256], 121 bos_descriptor: [0; 256],
@@ -171,10 +171,10 @@ async fn main(spawner: Spawner) {
171 171
172 // Init network stack 172 // Init network stack
173 let device = Device { mac_addr: our_mac_addr }; 173 let device = Device { mac_addr: our_mac_addr };
174 let stack = &*forever!(Stack::new( 174 let stack = &*singleton!(Stack::new(
175 device, 175 device,
176 config, 176 config,
177 forever!(StackResources::<1, 2, 8>::new()), 177 singleton!(StackResources::<1, 2, 8>::new()),
178 seed 178 seed
179 )); 179 ));
180 180
diff --git a/examples/stm32u5/Cargo.toml b/examples/stm32u5/Cargo.toml
index 48833664a..ff0ec9f42 100644
--- a/examples/stm32u5/Cargo.toml
+++ b/examples/stm32u5/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32u5-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] }
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index b46300764..3b10da0ad 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32wb-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55cc", "time-driver-any", "exti"] }
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index ae33478af..5f6679f4b 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-stm32wl-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] }
8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] }
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs
index d16e3f5e4..c5e9bb597 100644
--- a/examples/stm32wl/src/bin/subghz.rs
+++ b/examples/stm32wl/src/bin/subghz.rs
@@ -13,7 +13,7 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::interrupt; 13use embassy_stm32::interrupt;
14use embassy_stm32::interrupt::{Interrupt, InterruptExt}; 14use embassy_stm32::interrupt::{Interrupt, InterruptExt};
15use embassy_stm32::subghz::*; 15use embassy_stm32::subghz::*;
16use embassy_util::channel::signal::Signal; 16use embassy_sync::signal::Signal;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
18 18
19const PING_DATA: &str = "PING"; 19const PING_DATA: &str = "PING";
diff --git a/examples/wasm/Cargo.toml b/examples/wasm/Cargo.toml
index c7f980366..ea61fb921 100644
--- a/examples/wasm/Cargo.toml
+++ b/examples/wasm/Cargo.toml
@@ -7,7 +7,7 @@ version = "0.1.0"
7crate-type = ["cdylib"] 7crate-type = ["cdylib"]
8 8
9[dependencies] 9[dependencies]
10embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["log"] } 10embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["log"] }
11embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly", "integrated-timers"] } 11embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "wasm", "nightly", "integrated-timers"] }
12embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] } 12embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "wasm", "nightly"] }
13 13
@@ -15,4 +15,4 @@ wasm-logger = "0.2.0"
15wasm-bindgen = "0.2" 15wasm-bindgen = "0.2"
16web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] } 16web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Node", "Window" ] }
17log = "0.4.11" 17log = "0.4.11"
18critical-section = "1.1" 18critical-section = { version = "1.1", features = ["std"] }
diff --git a/examples/wasm/README.md b/examples/wasm/README.md
index 4bed4a797..b7fee2dc8 100644
--- a/examples/wasm/README.md
+++ b/examples/wasm/README.md
@@ -3,7 +3,7 @@
3Examples use a CLI tool named `wasm-pack` to build this example: 3Examples use a CLI tool named `wasm-pack` to build this example:
4 4
5``` 5```
6cargo install wasm-pack 6cargo install wasm-pack --version 0.9.1
7``` 7```
8 8
9## Building 9## Building