aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-08-22 14:12:13 +0000
committerGitHub <[email protected]>2022-08-22 14:12:13 +0000
commit381ac97746c318963b42eec6ced6773301c91519 (patch)
treeb1b3f644b77c6fcf4a0bbe2eabe19caba27c4c08 /examples
parent1b9599025868d3a5d0d8e773593b05df8b2fecf2 (diff)
parent478f4727846f6a43c28fff3b09cb639c0b800465 (diff)
Merge #920
920: Remove Forever, switch to static_cell. r=Dirbaio a=Dirbaio Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/nrf/Cargo.toml1
-rw-r--r--examples/nrf/src/bin/channel_sender_receiver.rs6
-rw-r--r--examples/nrf/src/bin/multiprio.rs14
-rw-r--r--examples/nrf/src/bin/raw_spawn.rs6
-rw-r--r--examples/nrf/src/bin/usb_ethernet.rs14
-rw-r--r--examples/nrf/src/bin/usb_serial_multitask.rs6
-rw-r--r--examples/std/Cargo.toml1
-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/stm32f3/Cargo.toml1
-rw-r--r--examples/stm32f3/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f4/Cargo.toml1
-rw-r--r--examples/stm32f4/src/bin/multiprio.rs14
-rw-r--r--examples/stm32f7/Cargo.toml1
-rw-r--r--examples/stm32f7/src/bin/eth.rs14
-rw-r--r--examples/stm32h7/Cargo.toml1
-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/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/stm32l0/Cargo.toml1
-rw-r--r--examples/stm32l0/src/bin/raw_spawn.rs6
-rw-r--r--examples/stm32l5/Cargo.toml1
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs14
27 files changed, 107 insertions, 99 deletions
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml
index 2fcc31221..17f29b8fb 100644
--- a/examples/nrf/Cargo.toml
+++ b/examples/nrf/Cargo.toml
@@ -22,6 +22,7 @@ embedded-io = "0.3.0"
22defmt = "0.3" 22defmt = "0.3"
23defmt-rtt = "0.3" 23defmt-rtt = "0.3"
24 24
25static_cell = "1.0"
25cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } 26cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
26cortex-m-rt = "0.7.0" 27cortex-m-rt = "0.7.0"
27panic-probe = { version = "0.3", features = ["print-defmt"] } 28panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs
index c9c458aec..d250b6a5c 100644
--- a/examples/nrf/src/bin/channel_sender_receiver.rs
+++ b/examples/nrf/src/bin/channel_sender_receiver.rs
@@ -8,7 +8,7 @@ use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
8use embassy_time::{Duration, Timer}; 8use embassy_time::{Duration, Timer};
9use embassy_util::blocking_mutex::raw::NoopRawMutex; 9use embassy_util::blocking_mutex::raw::NoopRawMutex;
10use embassy_util::channel::mpmc::{Channel, Receiver, Sender}; 10use embassy_util::channel::mpmc::{Channel, Receiver, Sender};
11use embassy_util::Forever; 11use static_cell::StaticCell;
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/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/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs
index f0a870317..d427f7563 100644
--- a/examples/nrf/src/bin/usb_ethernet.rs
+++ b/examples/nrf/src/bin/usb_ethernet.rs
@@ -18,17 +18,17 @@ use embassy_usb::{Builder, Config, UsbDevice};
18use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 18use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
20use embassy_util::channel::mpmc::Channel; 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_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/std/Cargo.toml b/examples/std/Cargo.toml
index b7009017c..164a2b42d 100644
--- a/examples/std/Cargo.toml
+++ b/examples/std/Cargo.toml
@@ -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/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index b5ea28bb6..4e6b0ea1e 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -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/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..f93a1d0f9 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -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..e286d2310 100644
--- a/examples/stm32f7/Cargo.toml
+++ b/examples/stm32f7/Cargo.toml
@@ -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/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index a416796ea..fc5f74f99 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -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/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/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index fdb716d15..72365a640 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -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/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index 4d96d31fc..d8e78088a 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -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..959195518 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -19,18 +19,18 @@ use embassy_usb::{Builder, UsbDevice};
19use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 19use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
20use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 20use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
21use embassy_util::channel::mpmc::Channel; 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