aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-06-01 01:32:11 +0200
committerDario Nieuwenhuis <[email protected]>2023-06-01 01:42:34 +0200
commit1d8321b821d114b369d5a087a1a7a6600228b032 (patch)
tree605b3eb96ea10120f7e8bf0741bcc34daab8e9ec
parentd7d66bd74f2ef1bc8903b15df630ddbb8fe97df4 (diff)
Use make_static! from static-cell v1.1
-rw-r--r--embassy-executor/Cargo.toml2
-rw-r--r--embassy-rp/Cargo.toml2
-rw-r--r--embassy-sync/Cargo.toml2
-rw-r--r--examples/nrf52840/Cargo.toml4
-rw-r--r--examples/nrf52840/src/bin/usb_ethernet.rs32
-rw-r--r--examples/nrf52840/src/bin/usb_serial_multitask.rs23
-rw-r--r--examples/nrf5340/Cargo.toml2
-rw-r--r--examples/rp/Cargo.toml2
-rw-r--r--examples/rp/src/bin/ethernet_w5500_multisocket.rs17
-rw-r--r--examples/rp/src/bin/ethernet_w5500_tcp_client.rs17
-rw-r--r--examples/rp/src/bin/ethernet_w5500_tcp_server.rs18
-rw-r--r--examples/rp/src/bin/ethernet_w5500_udp.rs18
-rw-r--r--examples/rp/src/bin/lora_p2p_send_multicore.rs2
-rw-r--r--examples/rp/src/bin/multicore.rs2
-rw-r--r--examples/rp/src/bin/uart_buffered_split.rs15
-rw-r--r--examples/rp/src/bin/usb_ethernet.rs30
-rw-r--r--examples/rp/src/bin/wifi_ap_tcp_server.rs16
-rw-r--r--examples/rp/src/bin/wifi_scan.rs12
-rw-r--r--examples/rp/src/bin/wifi_tcp_server.rs16
-rw-r--r--examples/std/Cargo.toml2
-rw-r--r--examples/std/src/bin/net.rs18
-rw-r--r--examples/std/src/bin/net_dns.rs18
-rw-r--r--examples/std/src/bin/net_udp.rs18
-rw-r--r--examples/std/src/bin/tcp_accept.rs18
-rw-r--r--examples/stm32f0/Cargo.toml2
-rw-r--r--examples/stm32f3/Cargo.toml2
-rw-r--r--examples/stm32f4/Cargo.toml2
-rw-r--r--examples/stm32f4/src/bin/usb_ethernet.rs32
-rw-r--r--examples/stm32f7/Cargo.toml2
-rw-r--r--examples/stm32f7/src/bin/eth.rs21
-rw-r--r--examples/stm32h5/Cargo.toml2
-rw-r--r--examples/stm32h5/src/bin/eth.rs21
-rw-r--r--examples/stm32h7/Cargo.toml2
-rw-r--r--examples/stm32h7/src/bin/eth.rs21
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs21
-rw-r--r--examples/stm32l0/Cargo.toml2
-rw-r--r--examples/stm32l5/Cargo.toml2
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs30
38 files changed, 168 insertions, 300 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index ce032479d..1e5494ef8 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -65,7 +65,7 @@ embassy-macros = { version = "0.2.0", path = "../embassy-macros" }
65embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true} 65embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true}
66atomic-polyfill = "1.0.1" 66atomic-polyfill = "1.0.1"
67critical-section = "1.1" 67critical-section = "1.1"
68static_cell = "1.0" 68static_cell = "1.1"
69 69
70# arch-cortex-m dependencies 70# arch-cortex-m dependencies
71cortex-m = { version = "0.7.6", optional = true } 71cortex-m = { version = "0.7.6", optional = true }
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml
index e032dfdae..5f08c7f33 100644
--- a/embassy-rp/Cargo.toml
+++ b/embassy-rp/Cargo.toml
@@ -86,4 +86,4 @@ rp2040-boot2 = "0.3"
86 86
87[dev-dependencies] 87[dev-dependencies]
88embassy-executor = { version = "0.2.0", path = "../embassy-executor", features = ["arch-std", "executor-thread"] } 88embassy-executor = { version = "0.2.0", path = "../embassy-executor", features = ["arch-std", "executor-thread"] }
89static_cell = "1.0" 89static_cell = "1.1"
diff --git a/embassy-sync/Cargo.toml b/embassy-sync/Cargo.toml
index bc06b92cd..340724eab 100644
--- a/embassy-sync/Cargo.toml
+++ b/embassy-sync/Cargo.toml
@@ -45,4 +45,4 @@ futures-util = { version = "0.3.17", features = [ "channel" ] }
45 45
46# Enable critical-section implementation for std, for tests 46# Enable critical-section implementation for std, for tests
47critical-section = { version = "1.1", features = ["std"] } 47critical-section = { version = "1.1", features = ["std"] }
48static_cell = "1.0" 48static_cell = "1.1"
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml
index 0f75b3ab7..6627b7861 100644
--- a/examples/nrf52840/Cargo.toml
+++ b/examples/nrf52840/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[features] 7[features]
8default = ["nightly"] 8default = ["nightly"]
9nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits", 9nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits", "static_cell/nightly",
10 "embassy-usb", "embedded-io/async", "embassy-net", "embassy-lora", "lora-phy", "lorawan-device", "lorawan"] 10 "embassy-usb", "embedded-io/async", "embassy-net", "embassy-lora", "lora-phy", "lorawan-device", "lorawan"]
11 11
12[dependencies] 12[dependencies]
@@ -26,7 +26,7 @@ lorawan = { version = "0.7.3", default-features = false, features = ["default-cr
26defmt = "0.3" 26defmt = "0.3"
27defmt-rtt = "0.4" 27defmt-rtt = "0.4"
28 28
29static_cell = "1.0" 29static_cell = "1.1"
30cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 30cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
31cortex-m-rt = "0.7.0" 31cortex-m-rt = "0.7.0"
32panic-probe = { version = "0.3", features = ["print-defmt"] } 32panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs
index 786025c43..1065f5b5d 100644
--- a/examples/nrf52840/src/bin/usb_ethernet.rs
+++ b/examples/nrf52840/src/bin/usb_ethernet.rs
@@ -16,7 +16,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState
16use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; 16use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
17use embassy_usb::{Builder, Config, UsbDevice}; 17use embassy_usb::{Builder, Config, UsbDevice};
18use embedded_io::asynch::Write; 18use embedded_io::asynch::Write;
19use static_cell::StaticCell; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22bind_interrupts!(struct Irqs { 22bind_interrupts!(struct Irqs {
@@ -27,15 +27,6 @@ bind_interrupts!(struct Irqs {
27 27
28type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; 28type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
29 29
30macro_rules! singleton {
31 ($val:expr) => {{
32 type T = impl Sized;
33 static STATIC_CELL: StaticCell<T> = StaticCell::new();
34 let (x,) = STATIC_CELL.init(($val,));
35 x
36 }};
37}
38
39const MTU: usize = 1514; 30const MTU: usize = 1514;
40 31
41#[embassy_executor::task] 32#[embassy_executor::task]
@@ -83,11 +74,11 @@ async fn main(spawner: Spawner) {
83 let mut builder = Builder::new( 74 let mut builder = Builder::new(
84 driver, 75 driver,
85 config, 76 config,
86 &mut singleton!([0; 256])[..], 77 &mut make_static!([0; 256])[..],
87 &mut singleton!([0; 256])[..], 78 &mut make_static!([0; 256])[..],
88 &mut singleton!([0; 256])[..], 79 &mut make_static!([0; 256])[..],
89 &mut singleton!([0; 128])[..], 80 &mut make_static!([0; 128])[..],
90 &mut singleton!([0; 128])[..], 81 &mut make_static!([0; 128])[..],
91 ); 82 );
92 83
93 // Our MAC addr. 84 // Our MAC addr.
@@ -96,14 +87,14 @@ async fn main(spawner: Spawner) {
96 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 87 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
97 88
98 // Create classes on the builder. 89 // Create classes on the builder.
99 let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); 90 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64);
100 91
101 // Build the builder. 92 // Build the builder.
102 let usb = builder.build(); 93 let usb = builder.build();
103 94
104 unwrap!(spawner.spawn(usb_task(usb))); 95 unwrap!(spawner.spawn(usb_task(usb)));
105 96
106 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); 97 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
107 unwrap!(spawner.spawn(usb_ncm_task(runner))); 98 unwrap!(spawner.spawn(usb_ncm_task(runner)));
108 99
109 let config = embassy_net::Config::Dhcp(Default::default()); 100 let config = embassy_net::Config::Dhcp(Default::default());
@@ -120,7 +111,12 @@ async fn main(spawner: Spawner) {
120 let seed = u64::from_le_bytes(seed); 111 let seed = u64::from_le_bytes(seed);
121 112
122 // Init network stack 113 // Init network stack
123 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 114 let stack = &*make_static!(Stack::new(
115 device,
116 config,
117 make_static!(StackResources::<2>::new()),
118 seed
119 ));
124 120
125 unwrap!(spawner.spawn(net_task(stack))); 121 unwrap!(spawner.spawn(net_task(stack)));
126 122
diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs
index ac22d9499..cd4392903 100644
--- a/examples/nrf52840/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf52840/src/bin/usb_serial_multitask.rs
@@ -12,7 +12,7 @@ use embassy_nrf::{bind_interrupts, pac, peripherals, usb};
12use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; 12use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
13use embassy_usb::driver::EndpointError; 13use embassy_usb::driver::EndpointError;
14use embassy_usb::{Builder, Config, UsbDevice}; 14use embassy_usb::{Builder, Config, UsbDevice};
15use static_cell::StaticCell; 15use static_cell::make_static;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18bind_interrupts!(struct Irqs { 18bind_interrupts!(struct Irqs {
@@ -20,15 +20,6 @@ bind_interrupts!(struct Irqs {
20 POWER_CLOCK => usb::vbus_detect::InterruptHandler; 20 POWER_CLOCK => usb::vbus_detect::InterruptHandler;
21}); 21});
22 22
23macro_rules! singleton {
24 ($val:expr) => {{
25 type T = impl Sized;
26 static STATIC_CELL: StaticCell<T> = StaticCell::new();
27 let (x,) = STATIC_CELL.init(($val,));
28 x
29 }};
30}
31
32type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; 23type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
33 24
34#[embassy_executor::task] 25#[embassy_executor::task]
@@ -73,17 +64,17 @@ async fn main(spawner: Spawner) {
73 config.device_protocol = 0x01; 64 config.device_protocol = 0x01;
74 config.composite_with_iads = true; 65 config.composite_with_iads = true;
75 66
76 let state = singleton!(State::new()); 67 let state = make_static!(State::new());
77 68
78 // Create embassy-usb DeviceBuilder using the driver and config. 69 // Create embassy-usb DeviceBuilder using the driver and config.
79 let mut builder = Builder::new( 70 let mut builder = Builder::new(
80 driver, 71 driver,
81 config, 72 config,
82 &mut singleton!([0; 256])[..], 73 &mut make_static!([0; 256])[..],
83 &mut singleton!([0; 256])[..], 74 &mut make_static!([0; 256])[..],
84 &mut singleton!([0; 256])[..], 75 &mut make_static!([0; 256])[..],
85 &mut singleton!([0; 128])[..], 76 &mut make_static!([0; 128])[..],
86 &mut singleton!([0; 128])[..], 77 &mut make_static!([0; 128])[..],
87 ); 78 );
88 79
89 // Create classes on the builder. 80 // Create classes on the builder.
diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml
index 40422e7df..efb66bae6 100644
--- a/examples/nrf5340/Cargo.toml
+++ b/examples/nrf5340/Cargo.toml
@@ -42,7 +42,7 @@ embedded-io = { version = "0.4.0", features = [ "async" ]}
42defmt = "0.3" 42defmt = "0.3"
43defmt-rtt = "0.4" 43defmt-rtt = "0.4"
44 44
45static_cell = "1.0" 45static_cell = { version = "1.1", features = ["nightly"]}
46cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 46cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
47cortex-m-rt = "0.7.0" 47cortex-m-rt = "0.7.0"
48panic-probe = { version = "0.3", features = ["print-defmt"] } 48panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index 58b701915..e946b481d 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -45,7 +45,7 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
45embedded-hal-async = "0.2.0-alpha.1" 45embedded-hal-async = "0.2.0-alpha.1"
46embedded-io = { version = "0.4.0", features = ["async", "defmt"] } 46embedded-io = { version = "0.4.0", features = ["async", "defmt"] }
47embedded-storage = { version = "0.3" } 47embedded-storage = { version = "0.3" }
48static_cell = "1.0.0" 48static_cell = { version = "1.1", features = ["nightly"]}
49log = "0.4" 49log = "0.4"
50pio-proc = "0.2" 50pio-proc = "0.2"
51pio = "0.2.1" 51pio = "0.2.1"
diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs
index c8e6d46a6..63e142e7d 100644
--- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs
+++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs
@@ -19,18 +19,9 @@ use embassy_time::Duration;
19use embedded_hal_async::spi::ExclusiveDevice; 19use embedded_hal_async::spi::ExclusiveDevice;
20use embedded_io::asynch::Write; 20use embedded_io::asynch::Write;
21use rand::RngCore; 21use rand::RngCore;
22use static_cell::StaticCell; 22use static_cell::make_static;
23use {defmt_rtt as _, panic_probe as _}; 23use {defmt_rtt as _, panic_probe as _};
24 24
25macro_rules! singleton {
26 ($val:expr) => {{
27 type T = impl Sized;
28 static STATIC_CELL: StaticCell<T> = StaticCell::new();
29 let (x,) = STATIC_CELL.init(($val,));
30 x
31 }};
32}
33
34#[embassy_executor::task] 25#[embassy_executor::task]
35async fn ethernet_task( 26async fn ethernet_task(
36 runner: Runner< 27 runner: Runner<
@@ -62,7 +53,7 @@ async fn main(spawner: Spawner) {
62 let w5500_reset = Output::new(p.PIN_20, Level::High); 53 let w5500_reset = Output::new(p.PIN_20, Level::High);
63 54
64 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; 55 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
65 let state = singleton!(State::<8, 8>::new()); 56 let state = make_static!(State::<8, 8>::new());
66 let (device, runner) = 57 let (device, runner) =
67 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; 58 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
68 unwrap!(spawner.spawn(ethernet_task(runner))); 59 unwrap!(spawner.spawn(ethernet_task(runner)));
@@ -71,10 +62,10 @@ async fn main(spawner: Spawner) {
71 let seed = rng.next_u64(); 62 let seed = rng.next_u64();
72 63
73 // Init network stack 64 // Init network stack
74 let stack = &*singleton!(Stack::new( 65 let stack = &*make_static!(Stack::new(
75 device, 66 device,
76 embassy_net::Config::Dhcp(Default::default()), 67 embassy_net::Config::Dhcp(Default::default()),
77 singleton!(StackResources::<3>::new()), 68 make_static!(StackResources::<3>::new()),
78 seed 69 seed
79 )); 70 ));
80 71
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs
index 9a7c3ad19..a532de00d 100644
--- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs
+++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs
@@ -21,18 +21,9 @@ use embassy_time::{Duration, Timer};
21use embedded_hal_async::spi::ExclusiveDevice; 21use embedded_hal_async::spi::ExclusiveDevice;
22use embedded_io::asynch::Write; 22use embedded_io::asynch::Write;
23use rand::RngCore; 23use rand::RngCore;
24use static_cell::StaticCell; 24use static_cell::make_static;
25use {defmt_rtt as _, panic_probe as _}; 25use {defmt_rtt as _, panic_probe as _};
26 26
27macro_rules! singleton {
28 ($val:expr) => {{
29 type T = impl Sized;
30 static STATIC_CELL: StaticCell<T> = StaticCell::new();
31 let (x,) = STATIC_CELL.init(($val,));
32 x
33 }};
34}
35
36#[embassy_executor::task] 27#[embassy_executor::task]
37async fn ethernet_task( 28async fn ethernet_task(
38 runner: Runner< 29 runner: Runner<
@@ -65,7 +56,7 @@ async fn main(spawner: Spawner) {
65 let w5500_reset = Output::new(p.PIN_20, Level::High); 56 let w5500_reset = Output::new(p.PIN_20, Level::High);
66 57
67 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; 58 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
68 let state = singleton!(State::<8, 8>::new()); 59 let state = make_static!(State::<8, 8>::new());
69 let (device, runner) = 60 let (device, runner) =
70 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; 61 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
71 unwrap!(spawner.spawn(ethernet_task(runner))); 62 unwrap!(spawner.spawn(ethernet_task(runner)));
@@ -74,10 +65,10 @@ async fn main(spawner: Spawner) {
74 let seed = rng.next_u64(); 65 let seed = rng.next_u64();
75 66
76 // Init network stack 67 // Init network stack
77 let stack = &*singleton!(Stack::new( 68 let stack = &*make_static!(Stack::new(
78 device, 69 device,
79 embassy_net::Config::Dhcp(Default::default()), 70 embassy_net::Config::Dhcp(Default::default()),
80 singleton!(StackResources::<2>::new()), 71 make_static!(StackResources::<2>::new()),
81 seed 72 seed
82 )); 73 ));
83 74
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs
index f02543246..599f6b1e9 100644
--- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs
+++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs
@@ -20,18 +20,8 @@ use embassy_time::Duration;
20use embedded_hal_async::spi::ExclusiveDevice; 20use embedded_hal_async::spi::ExclusiveDevice;
21use embedded_io::asynch::Write; 21use embedded_io::asynch::Write;
22use rand::RngCore; 22use rand::RngCore;
23use static_cell::StaticCell; 23use static_cell::make_static;
24use {defmt_rtt as _, panic_probe as _}; 24use {defmt_rtt as _, panic_probe as _};
25
26macro_rules! singleton {
27 ($val:expr) => {{
28 type T = impl Sized;
29 static STATIC_CELL: StaticCell<T> = StaticCell::new();
30 let (x,) = STATIC_CELL.init(($val,));
31 x
32 }};
33}
34
35#[embassy_executor::task] 25#[embassy_executor::task]
36async fn ethernet_task( 26async fn ethernet_task(
37 runner: Runner< 27 runner: Runner<
@@ -64,7 +54,7 @@ async fn main(spawner: Spawner) {
64 let w5500_reset = Output::new(p.PIN_20, Level::High); 54 let w5500_reset = Output::new(p.PIN_20, Level::High);
65 55
66 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; 56 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
67 let state = singleton!(State::<8, 8>::new()); 57 let state = make_static!(State::<8, 8>::new());
68 let (device, runner) = 58 let (device, runner) =
69 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; 59 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
70 unwrap!(spawner.spawn(ethernet_task(runner))); 60 unwrap!(spawner.spawn(ethernet_task(runner)));
@@ -73,10 +63,10 @@ async fn main(spawner: Spawner) {
73 let seed = rng.next_u64(); 63 let seed = rng.next_u64();
74 64
75 // Init network stack 65 // Init network stack
76 let stack = &*singleton!(Stack::new( 66 let stack = &*make_static!(Stack::new(
77 device, 67 device,
78 embassy_net::Config::Dhcp(Default::default()), 68 embassy_net::Config::Dhcp(Default::default()),
79 singleton!(StackResources::<2>::new()), 69 make_static!(StackResources::<2>::new()),
80 seed 70 seed
81 )); 71 ));
82 72
diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs
index 2c54f711e..ac5a65bb6 100644
--- a/examples/rp/src/bin/ethernet_w5500_udp.rs
+++ b/examples/rp/src/bin/ethernet_w5500_udp.rs
@@ -18,18 +18,8 @@ use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0};
18use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; 18use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
19use embedded_hal_async::spi::ExclusiveDevice; 19use embedded_hal_async::spi::ExclusiveDevice;
20use rand::RngCore; 20use rand::RngCore;
21use static_cell::StaticCell; 21use static_cell::make_static;
22use {defmt_rtt as _, panic_probe as _}; 22use {defmt_rtt as _, panic_probe as _};
23
24macro_rules! singleton {
25 ($val:expr) => {{
26 type T = impl Sized;
27 static STATIC_CELL: StaticCell<T> = StaticCell::new();
28 let (x,) = STATIC_CELL.init(($val,));
29 x
30 }};
31}
32
33#[embassy_executor::task] 23#[embassy_executor::task]
34async fn ethernet_task( 24async fn ethernet_task(
35 runner: Runner< 25 runner: Runner<
@@ -61,7 +51,7 @@ async fn main(spawner: Spawner) {
61 let w5500_reset = Output::new(p.PIN_20, Level::High); 51 let w5500_reset = Output::new(p.PIN_20, Level::High);
62 52
63 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; 53 let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
64 let state = singleton!(State::<8, 8>::new()); 54 let state = make_static!(State::<8, 8>::new());
65 let (device, runner) = 55 let (device, runner) =
66 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; 56 embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
67 unwrap!(spawner.spawn(ethernet_task(runner))); 57 unwrap!(spawner.spawn(ethernet_task(runner)));
@@ -70,10 +60,10 @@ async fn main(spawner: Spawner) {
70 let seed = rng.next_u64(); 60 let seed = rng.next_u64();
71 61
72 // Init network stack 62 // Init network stack
73 let stack = &*singleton!(Stack::new( 63 let stack = &*make_static!(Stack::new(
74 device, 64 device,
75 embassy_net::Config::Dhcp(Default::default()), 65 embassy_net::Config::Dhcp(Default::default()),
76 singleton!(StackResources::<2>::new()), 66 make_static!(StackResources::<2>::new()),
77 seed 67 seed
78 )); 68 ));
79 69
diff --git a/examples/rp/src/bin/lora_p2p_send_multicore.rs b/examples/rp/src/bin/lora_p2p_send_multicore.rs
index 5585606d8..eef2f7a53 100644
--- a/examples/rp/src/bin/lora_p2p_send_multicore.rs
+++ b/examples/rp/src/bin/lora_p2p_send_multicore.rs
@@ -7,7 +7,6 @@
7 7
8use defmt::*; 8use defmt::*;
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_executor::_export::StaticCell;
11use embassy_lora::iv::GenericSx126xInterfaceVariant; 10use embassy_lora::iv::GenericSx126xInterfaceVariant;
12use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull}; 11use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull};
13use embassy_rp::multicore::{spawn_core1, Stack}; 12use embassy_rp::multicore::{spawn_core1, Stack};
@@ -19,6 +18,7 @@ use embassy_time::{Delay, Duration, Timer};
19use lora_phy::mod_params::*; 18use lora_phy::mod_params::*;
20use lora_phy::sx1261_2::SX1261_2; 19use lora_phy::sx1261_2::SX1261_2;
21use lora_phy::LoRa; 20use lora_phy::LoRa;
21use static_cell::StaticCell;
22use {defmt_rtt as _, panic_probe as _}; 22use {defmt_rtt as _, panic_probe as _};
23 23
24static mut CORE1_STACK: Stack<4096> = Stack::new(); 24static mut CORE1_STACK: Stack<4096> = Stack::new();
diff --git a/examples/rp/src/bin/multicore.rs b/examples/rp/src/bin/multicore.rs
index 376b2b61e..57278dd6c 100644
--- a/examples/rp/src/bin/multicore.rs
+++ b/examples/rp/src/bin/multicore.rs
@@ -4,13 +4,13 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Executor; 6use embassy_executor::Executor;
7use embassy_executor::_export::StaticCell;
8use embassy_rp::gpio::{Level, Output}; 7use embassy_rp::gpio::{Level, Output};
9use embassy_rp::multicore::{spawn_core1, Stack}; 8use embassy_rp::multicore::{spawn_core1, Stack};
10use embassy_rp::peripherals::PIN_25; 9use embassy_rp::peripherals::PIN_25;
11use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 10use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
12use embassy_sync::channel::Channel; 11use embassy_sync::channel::Channel;
13use embassy_time::{Duration, Timer}; 12use embassy_time::{Duration, Timer};
13use static_cell::StaticCell;
14use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
15 15
16static mut CORE1_STACK: Stack<4096> = Stack::new(); 16static mut CORE1_STACK: Stack<4096> = Stack::new();
diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs
index d6f01b4de..9df99bd58 100644
--- a/examples/rp/src/bin/uart_buffered_split.rs
+++ b/examples/rp/src/bin/uart_buffered_split.rs
@@ -4,34 +4,25 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_executor::_export::StaticCell;
8use embassy_rp::bind_interrupts; 7use embassy_rp::bind_interrupts;
9use embassy_rp::peripherals::UART0; 8use embassy_rp::peripherals::UART0;
10use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; 9use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config};
11use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
12use embedded_io::asynch::{Read, Write}; 11use embedded_io::asynch::{Read, Write};
12use static_cell::make_static;
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
14 14
15bind_interrupts!(struct Irqs { 15bind_interrupts!(struct Irqs {
16 UART0_IRQ => BufferedInterruptHandler<UART0>; 16 UART0_IRQ => BufferedInterruptHandler<UART0>;
17}); 17});
18 18
19macro_rules! singleton {
20 ($val:expr) => {{
21 type T = impl Sized;
22 static STATIC_CELL: StaticCell<T> = StaticCell::new();
23 let (x,) = STATIC_CELL.init(($val,));
24 x
25 }};
26}
27
28#[embassy_executor::main] 19#[embassy_executor::main]
29async fn main(spawner: Spawner) { 20async fn main(spawner: Spawner) {
30 let p = embassy_rp::init(Default::default()); 21 let p = embassy_rp::init(Default::default());
31 let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0); 22 let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0);
32 23
33 let tx_buf = &mut singleton!([0u8; 16])[..]; 24 let tx_buf = &mut make_static!([0u8; 16])[..];
34 let rx_buf = &mut singleton!([0u8; 16])[..]; 25 let rx_buf = &mut make_static!([0u8; 16])[..];
35 let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default()); 26 let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default());
36 let (rx, mut tx) = uart.split(); 27 let (rx, mut tx) = uart.split();
37 28
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs
index 38ff1620d..16fbf5e91 100644
--- a/examples/rp/src/bin/usb_ethernet.rs
+++ b/examples/rp/src/bin/usb_ethernet.rs
@@ -13,7 +13,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState
13use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; 13use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
14use embassy_usb::{Builder, Config, UsbDevice}; 14use embassy_usb::{Builder, Config, UsbDevice};
15use embedded_io::asynch::Write; 15use embedded_io::asynch::Write;
16use static_cell::StaticCell; 16use static_cell::make_static;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
18 18
19bind_interrupts!(struct Irqs { 19bind_interrupts!(struct Irqs {
@@ -22,15 +22,6 @@ bind_interrupts!(struct Irqs {
22 22
23type MyDriver = Driver<'static, peripherals::USB>; 23type MyDriver = Driver<'static, peripherals::USB>;
24 24
25macro_rules! singleton {
26 ($val:expr) => {{
27 type T = impl Sized;
28 static STATIC_CELL: StaticCell<T> = StaticCell::new();
29 let (x,) = STATIC_CELL.init(($val,));
30 x
31 }};
32}
33
34const MTU: usize = 1514; 25const MTU: usize = 1514;
35 26
36#[embassy_executor::task] 27#[embassy_executor::task]
@@ -73,10 +64,10 @@ async fn main(spawner: Spawner) {
73 let mut builder = Builder::new( 64 let mut builder = Builder::new(
74 driver, 65 driver,
75 config, 66 config,
76 &mut singleton!([0; 256])[..], 67 &mut make_static!([0; 256])[..],
77 &mut singleton!([0; 256])[..], 68 &mut make_static!([0; 256])[..],
78 &mut singleton!([0; 256])[..], 69 &mut make_static!([0; 256])[..],
79 &mut singleton!([0; 128])[..], 70 &mut make_static!([0; 128])[..],
80 ); 71 );
81 72
82 // Our MAC addr. 73 // Our MAC addr.
@@ -85,14 +76,14 @@ async fn main(spawner: Spawner) {
85 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 76 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
86 77
87 // Create classes on the builder. 78 // Create classes on the builder.
88 let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); 79 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64);
89 80
90 // Build the builder. 81 // Build the builder.
91 let usb = builder.build(); 82 let usb = builder.build();
92 83
93 unwrap!(spawner.spawn(usb_task(usb))); 84 unwrap!(spawner.spawn(usb_task(usb)));
94 85
95 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); 86 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
96 unwrap!(spawner.spawn(usb_ncm_task(runner))); 87 unwrap!(spawner.spawn(usb_ncm_task(runner)));
97 88
98 let config = embassy_net::Config::Dhcp(Default::default()); 89 let config = embassy_net::Config::Dhcp(Default::default());
@@ -106,7 +97,12 @@ async fn main(spawner: Spawner) {
106 let seed = 1234; // guaranteed random, chosen by a fair dice roll 97 let seed = 1234; // guaranteed random, chosen by a fair dice roll
107 98
108 // Init network stack 99 // Init network stack
109 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 100 let stack = &*make_static!(Stack::new(
101 device,
102 config,
103 make_static!(StackResources::<2>::new()),
104 seed
105 ));
110 106
111 unwrap!(spawner.spawn(net_task(stack))); 107 unwrap!(spawner.spawn(net_task(stack)));
112 108
diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs
index 15264524e..b27d3c9f8 100644
--- a/examples/rp/src/bin/wifi_ap_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs
@@ -16,17 +16,9 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
16use embassy_rp::pio::Pio; 16use embassy_rp::pio::Pio;
17use embassy_time::Duration; 17use embassy_time::Duration;
18use embedded_io::asynch::Write; 18use embedded_io::asynch::Write;
19use static_cell::StaticCell; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 STATIC_CELL.init_with(move || $val)
27 }};
28}
29
30#[embassy_executor::task] 22#[embassy_executor::task]
31async fn wifi_task( 23async fn wifi_task(
32 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, 24 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
@@ -60,7 +52,7 @@ async fn main(spawner: Spawner) {
60 let mut pio = Pio::new(p.PIO0); 52 let mut pio = Pio::new(p.PIO0);
61 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); 53 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
62 54
63 let state = singleton!(cyw43::State::new()); 55 let state = make_static!(cyw43::State::new());
64 let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; 56 let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
65 unwrap!(spawner.spawn(wifi_task(runner))); 57 unwrap!(spawner.spawn(wifi_task(runner)));
66 58
@@ -80,10 +72,10 @@ async fn main(spawner: Spawner) {
80 let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. 72 let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random.
81 73
82 // Init network stack 74 // Init network stack
83 let stack = &*singleton!(Stack::new( 75 let stack = &*make_static!(Stack::new(
84 net_device, 76 net_device,
85 config, 77 config,
86 singleton!(StackResources::<2>::new()), 78 make_static!(StackResources::<2>::new()),
87 seed 79 seed
88 )); 80 ));
89 81
diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs
index aa5e5a399..79534f229 100644
--- a/examples/rp/src/bin/wifi_scan.rs
+++ b/examples/rp/src/bin/wifi_scan.rs
@@ -13,17 +13,9 @@ use embassy_net::Stack;
13use embassy_rp::gpio::{Level, Output}; 13use embassy_rp::gpio::{Level, Output};
14use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; 14use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
15use embassy_rp::pio::Pio; 15use embassy_rp::pio::Pio;
16use static_cell::StaticCell; 16use static_cell::make_static;
17use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, panic_probe as _};
18 18
19macro_rules! singleton {
20 ($val:expr) => {{
21 type T = impl Sized;
22 static STATIC_CELL: StaticCell<T> = StaticCell::new();
23 STATIC_CELL.init_with(move || $val)
24 }};
25}
26
27#[embassy_executor::task] 19#[embassy_executor::task]
28async fn wifi_task( 20async fn wifi_task(
29 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, 21 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
@@ -57,7 +49,7 @@ async fn main(spawner: Spawner) {
57 let mut pio = Pio::new(p.PIO0); 49 let mut pio = Pio::new(p.PIO0);
58 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); 50 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
59 51
60 let state = singleton!(cyw43::State::new()); 52 let state = make_static!(cyw43::State::new());
61 let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; 53 let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
62 unwrap!(spawner.spawn(wifi_task(runner))); 54 unwrap!(spawner.spawn(wifi_task(runner)));
63 55
diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs
index eafa25f68..1a00bca96 100644
--- a/examples/rp/src/bin/wifi_tcp_server.rs
+++ b/examples/rp/src/bin/wifi_tcp_server.rs
@@ -16,17 +16,9 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
16use embassy_rp::pio::Pio; 16use embassy_rp::pio::Pio;
17use embassy_time::Duration; 17use embassy_time::Duration;
18use embedded_io::asynch::Write; 18use embedded_io::asynch::Write;
19use static_cell::StaticCell; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21 21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 STATIC_CELL.init_with(move || $val)
27 }};
28}
29
30#[embassy_executor::task] 22#[embassy_executor::task]
31async fn wifi_task( 23async fn wifi_task(
32 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, 24 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
@@ -60,7 +52,7 @@ async fn main(spawner: Spawner) {
60 let mut pio = Pio::new(p.PIO0); 52 let mut pio = Pio::new(p.PIO0);
61 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); 53 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
62 54
63 let state = singleton!(cyw43::State::new()); 55 let state = make_static!(cyw43::State::new());
64 let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; 56 let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
65 unwrap!(spawner.spawn(wifi_task(runner))); 57 unwrap!(spawner.spawn(wifi_task(runner)));
66 58
@@ -80,10 +72,10 @@ async fn main(spawner: Spawner) {
80 let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. 72 let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random.
81 73
82 // Init network stack 74 // Init network stack
83 let stack = &*singleton!(Stack::new( 75 let stack = &*make_static!(Stack::new(
84 net_device, 76 net_device,
85 config, 77 config,
86 singleton!(StackResources::<2>::new()), 78 make_static!(StackResources::<2>::new()),
87 seed 79 seed
88 )); 80 ));
89 81
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml
index 36770ca9c..878ad8c5a 100644
--- a/examples/std/Cargo.toml
+++ b/examples/std/Cargo.toml
@@ -22,4 +22,4 @@ libc = "0.2.101"
22clap = { version = "3.0.0-beta.5", features = ["derive"] } 22clap = { version = "3.0.0-beta.5", features = ["derive"] }
23rand_core = { version = "0.6.3", features = ["std"] } 23rand_core = { version = "0.6.3", features = ["std"] }
24heapless = { version = "0.7.5", default-features = false } 24heapless = { version = "0.7.5", default-features = false }
25static_cell = "1.0" 25static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index d93616254..b42bfc13b 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -11,21 +11,12 @@ use embedded_io::asynch::Write;
11use heapless::Vec; 11use heapless::Vec;
12use log::*; 12use log::*;
13use rand_core::{OsRng, RngCore}; 13use rand_core::{OsRng, RngCore};
14use static_cell::StaticCell; 14use static_cell::{make_static, StaticCell};
15 15
16#[path = "../tuntap.rs"] 16#[path = "../tuntap.rs"]
17mod tuntap; 17mod tuntap;
18 18
19use crate::tuntap::TunTapDevice; 19use crate::tuntap::TunTapDevice;
20
21macro_rules! singleton {
22 ($val:expr) => {{
23 type T = impl Sized;
24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 STATIC_CELL.init_with(move || $val)
26 }};
27}
28
29#[derive(Parser)] 20#[derive(Parser)]
30#[clap(version = "1.0")] 21#[clap(version = "1.0")]
31struct Opts { 22struct Opts {
@@ -66,7 +57,12 @@ async fn main_task(spawner: Spawner) {
66 let seed = u64::from_le_bytes(seed); 57 let seed = u64::from_le_bytes(seed);
67 58
68 // Init network stack 59 // Init network stack
69 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 60 let stack = &*make_static!(Stack::new(
61 device,
62 config,
63 make_static!(StackResources::<3>::new()),
64 seed
65 ));
70 66
71 // Launch network task 67 // Launch network task
72 spawner.spawn(net_task(stack)).unwrap(); 68 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs
index d1e1f8212..932ac5831 100644
--- a/examples/std/src/bin/net_dns.rs
+++ b/examples/std/src/bin/net_dns.rs
@@ -9,21 +9,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
9use heapless::Vec; 9use heapless::Vec;
10use log::*; 10use log::*;
11use rand_core::{OsRng, RngCore}; 11use rand_core::{OsRng, RngCore};
12use static_cell::StaticCell; 12use static_cell::{make_static, StaticCell};
13 13
14#[path = "../tuntap.rs"] 14#[path = "../tuntap.rs"]
15mod tuntap; 15mod tuntap;
16 16
17use crate::tuntap::TunTapDevice; 17use crate::tuntap::TunTapDevice;
18
19macro_rules! singleton {
20 ($val:expr) => {{
21 type T = impl Sized;
22 static STATIC_CELL: StaticCell<T> = StaticCell::new();
23 STATIC_CELL.init_with(move || $val)
24 }};
25}
26
27#[derive(Parser)] 18#[derive(Parser)]
28#[clap(version = "1.0")] 19#[clap(version = "1.0")]
29struct Opts { 20struct Opts {
@@ -65,7 +56,12 @@ async fn main_task(spawner: Spawner) {
65 let seed = u64::from_le_bytes(seed); 56 let seed = u64::from_le_bytes(seed);
66 57
67 // Init network stack 58 // Init network stack
68 let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 59 let stack: &Stack<_> = &*make_static!(Stack::new(
60 device,
61 config,
62 make_static!(StackResources::<3>::new()),
63 seed
64 ));
69 65
70 // Launch network task 66 // Launch network task
71 spawner.spawn(net_task(stack)).unwrap(); 67 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs
index 4df23edf6..d89ec7643 100644
--- a/examples/std/src/bin/net_udp.rs
+++ b/examples/std/src/bin/net_udp.rs
@@ -7,21 +7,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
7use heapless::Vec; 7use heapless::Vec;
8use log::*; 8use log::*;
9use rand_core::{OsRng, RngCore}; 9use rand_core::{OsRng, RngCore};
10use static_cell::StaticCell; 10use static_cell::{make_static, 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
17macro_rules! singleton {
18 ($val:expr) => {{
19 type T = impl Sized;
20 static STATIC_CELL: StaticCell<T> = StaticCell::new();
21 STATIC_CELL.init_with(move || $val)
22 }};
23}
24
25#[derive(Parser)] 16#[derive(Parser)]
26#[clap(version = "1.0")] 17#[clap(version = "1.0")]
27struct Opts { 18struct Opts {
@@ -62,7 +53,12 @@ async fn main_task(spawner: Spawner) {
62 let seed = u64::from_le_bytes(seed); 53 let seed = u64::from_le_bytes(seed);
63 54
64 // Init network stack 55 // Init network stack
65 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 56 let stack = &*make_static!(Stack::new(
57 device,
58 config,
59 make_static!(StackResources::<3>::new()),
60 seed
61 ));
66 62
67 // Launch network task 63 // Launch network task
68 spawner.spawn(net_task(stack)).unwrap(); 64 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs
index 97ce77f42..d24e218dc 100644
--- a/examples/std/src/bin/tcp_accept.rs
+++ b/examples/std/src/bin/tcp_accept.rs
@@ -12,21 +12,12 @@ use embedded_io::asynch::Write as _;
12use heapless::Vec; 12use heapless::Vec;
13use log::*; 13use log::*;
14use rand_core::{OsRng, RngCore}; 14use rand_core::{OsRng, RngCore};
15use static_cell::StaticCell; 15use static_cell::{make_static, StaticCell};
16 16
17#[path = "../tuntap.rs"] 17#[path = "../tuntap.rs"]
18mod tuntap; 18mod tuntap;
19 19
20use crate::tuntap::TunTapDevice; 20use crate::tuntap::TunTapDevice;
21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 STATIC_CELL.init_with(move || $val)
27 }};
28}
29
30#[derive(Parser)] 21#[derive(Parser)]
31#[clap(version = "1.0")] 22#[clap(version = "1.0")]
32struct Opts { 23struct Opts {
@@ -77,7 +68,12 @@ async fn main_task(spawner: Spawner) {
77 let seed = u64::from_le_bytes(seed); 68 let seed = u64::from_le_bytes(seed);
78 69
79 // Init network stack 70 // Init network stack
80 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 71 let stack = &*make_static!(Stack::new(
72 device,
73 config,
74 make_static!(StackResources::<3>::new()),
75 seed
76 ));
81 77
82 // Launch network task 78 // Launch network task
83 spawner.spawn(net_task(stack)).unwrap(); 79 spawner.spawn(net_task(stack)).unwrap();
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index 9c59c45c6..ff134bb0e 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -16,4 +16,4 @@ embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["de
16embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 16embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
17embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 17embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
18embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } 18embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] }
19static_cell = "1.0" 19static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index 3d314e6c5..0fe9cb122 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -23,4 +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" 26static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index f5f8b632d..3a8efdd06 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -25,7 +25,7 @@ heapless = { version = "0.7.5", default-features = false }
25nb = "1.0.0" 25nb = "1.0.0"
26embedded-storage = "0.3.0" 26embedded-storage = "0.3.0"
27micromath = "2.0.0" 27micromath = "2.0.0"
28static_cell = "1.0" 28static_cell = { version = "1.1", features = ["nightly"]}
29chrono = { version = "^0.4", default-features = false} 29chrono = { version = "^0.4", default-features = false}
30 30
31[profile.release] 31[profile.release]
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs
index c4e395f0f..d229cc3ef 100644
--- a/examples/stm32f4/src/bin/usb_ethernet.rs
+++ b/examples/stm32f4/src/bin/usb_ethernet.rs
@@ -14,20 +14,11 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState
14use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; 14use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
15use embassy_usb::{Builder, UsbDevice}; 15use embassy_usb::{Builder, UsbDevice};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use static_cell::StaticCell; 17use static_cell::make_static;
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; 20type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>;
21 21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 let (x,) = STATIC_CELL.init(($val,));
27 x
28 }};
29}
30
31const MTU: usize = 1514; 22const MTU: usize = 1514;
32 23
33#[embassy_executor::task] 24#[embassy_executor::task]
@@ -60,7 +51,7 @@ async fn main(spawner: Spawner) {
60 let p = embassy_stm32::init(config); 51 let p = embassy_stm32::init(config);
61 52
62 // Create the driver, from the HAL. 53 // Create the driver, from the HAL.
63 let ep_out_buffer = &mut singleton!([0; 256])[..]; 54 let ep_out_buffer = &mut make_static!([0; 256])[..];
64 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer); 55 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer);
65 56
66 // Create embassy-usb Config 57 // Create embassy-usb Config
@@ -81,10 +72,10 @@ async fn main(spawner: Spawner) {
81 let mut builder = Builder::new( 72 let mut builder = Builder::new(
82 driver, 73 driver,
83 config, 74 config,
84 &mut singleton!([0; 256])[..], 75 &mut make_static!([0; 256])[..],
85 &mut singleton!([0; 256])[..], 76 &mut make_static!([0; 256])[..],
86 &mut singleton!([0; 256])[..], 77 &mut make_static!([0; 256])[..],
87 &mut singleton!([0; 128])[..], 78 &mut make_static!([0; 128])[..],
88 ); 79 );
89 80
90 // Our MAC addr. 81 // Our MAC addr.
@@ -93,14 +84,14 @@ async fn main(spawner: Spawner) {
93 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 84 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
94 85
95 // Create classes on the builder. 86 // Create classes on the builder.
96 let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); 87 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64);
97 88
98 // Build the builder. 89 // Build the builder.
99 let usb = builder.build(); 90 let usb = builder.build();
100 91
101 unwrap!(spawner.spawn(usb_task(usb))); 92 unwrap!(spawner.spawn(usb_task(usb)));
102 93
103 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); 94 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
104 unwrap!(spawner.spawn(usb_ncm_task(runner))); 95 unwrap!(spawner.spawn(usb_ncm_task(runner)));
105 96
106 let config = embassy_net::Config::Dhcp(Default::default()); 97 let config = embassy_net::Config::Dhcp(Default::default());
@@ -117,7 +108,12 @@ async fn main(spawner: Spawner) {
117 let seed = u64::from_le_bytes(seed); 108 let seed = u64::from_le_bytes(seed);
118 109
119 // Init network stack 110 // Init network stack
120 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 111 let stack = &*make_static!(Stack::new(
112 device,
113 config,
114 make_static!(StackResources::<2>::new()),
115 seed
116 ));
121 117
122 unwrap!(spawner.spawn(net_task(stack))); 118 unwrap!(spawner.spawn(net_task(stack)));
123 119
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
index 6ddb7186e..7a650067c 100644
--- a/examples/stm32f7/Cargo.toml
+++ b/examples/stm32f7/Cargo.toml
@@ -26,4 +26,4 @@ nb = "1.0.0"
26rand_core = "0.6.3" 26rand_core = "0.6.3"
27critical-section = "1.1" 27critical-section = "1.1"
28embedded-storage = "0.3.0" 28embedded-storage = "0.3.0"
29static_cell = "1.0" 29static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index 6d286c368..d8438241c 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -15,18 +15,8 @@ use embassy_stm32::{bind_interrupts, eth, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::StaticCell; 18use static_cell::make_static;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20
21macro_rules! singleton {
22 ($val:expr) => {{
23 type T = impl Sized;
24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 let (x,) = STATIC_CELL.init(($val,));
26 x
27 }};
28}
29
30bind_interrupts!(struct Irqs { 20bind_interrupts!(struct Irqs {
31 ETH => eth::InterruptHandler; 21 ETH => eth::InterruptHandler;
32}); 22});
@@ -55,7 +45,7 @@ async fn main(spawner: Spawner) -> ! {
55 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; 45 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
56 46
57 let device = Ethernet::new( 47 let device = Ethernet::new(
58 singleton!(PacketQueue::<16, 16>::new()), 48 make_static!(PacketQueue::<16, 16>::new()),
59 p.ETH, 49 p.ETH,
60 Irqs, 50 Irqs,
61 p.PA1, 51 p.PA1,
@@ -80,7 +70,12 @@ async fn main(spawner: Spawner) -> ! {
80 //}); 70 //});
81 71
82 // Init network stack 72 // Init network stack
83 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 73 let stack = &*make_static!(Stack::new(
74 device,
75 config,
76 make_static!(StackResources::<2>::new()),
77 seed
78 ));
84 79
85 // Launch network task 80 // Launch network task
86 unwrap!(spawner.spawn(net_task(&stack))); 81 unwrap!(spawner.spawn(net_task(&stack)));
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml
index b9204fba8..d49a0dde7 100644
--- a/examples/stm32h5/Cargo.toml
+++ b/examples/stm32h5/Cargo.toml
@@ -30,7 +30,7 @@ critical-section = "1.1"
30micromath = "2.0.0" 30micromath = "2.0.0"
31stm32-fmc = "0.2.4" 31stm32-fmc = "0.2.4"
32embedded-storage = "0.3.0" 32embedded-storage = "0.3.0"
33static_cell = "1.0" 33static_cell = { version = "1.1", features = ["nightly"]}
34 34
35# cargo build/run 35# cargo build/run
36[profile.dev] 36[profile.dev]
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs
index fa1f225fe..5d1eadf4b 100644
--- a/examples/stm32h5/src/bin/eth.rs
+++ b/examples/stm32h5/src/bin/eth.rs
@@ -16,18 +16,8 @@ use embassy_stm32::{bind_interrupts, eth, Config};
16use embassy_time::{Duration, Timer}; 16use embassy_time::{Duration, Timer};
17use embedded_io::asynch::Write; 17use embedded_io::asynch::Write;
18use rand_core::RngCore; 18use rand_core::RngCore;
19use static_cell::StaticCell; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 let (x,) = STATIC_CELL.init(($val,));
27 x
28 }};
29}
30
31bind_interrupts!(struct Irqs { 21bind_interrupts!(struct Irqs {
32 ETH => eth::InterruptHandler; 22 ETH => eth::InterruptHandler;
33}); 23});
@@ -74,7 +64,7 @@ async fn main(spawner: Spawner) -> ! {
74 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; 64 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
75 65
76 let device = Ethernet::new( 66 let device = Ethernet::new(
77 singleton!(PacketQueue::<4, 4>::new()), 67 make_static!(PacketQueue::<4, 4>::new()),
78 p.ETH, 68 p.ETH,
79 Irqs, 69 Irqs,
80 p.PA1, 70 p.PA1,
@@ -99,7 +89,12 @@ async fn main(spawner: Spawner) -> ! {
99 //}); 89 //});
100 90
101 // Init network stack 91 // Init network stack
102 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 92 let stack = &*make_static!(Stack::new(
93 device,
94 config,
95 make_static!(StackResources::<2>::new()),
96 seed
97 ));
103 98
104 // Launch network task 99 // Launch network task
105 unwrap!(spawner.spawn(net_task(&stack))); 100 unwrap!(spawner.spawn(net_task(&stack)));
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index 8b534ca05..08b57f988 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -30,7 +30,7 @@ critical-section = "1.1"
30micromath = "2.0.0" 30micromath = "2.0.0"
31stm32-fmc = "0.2.4" 31stm32-fmc = "0.2.4"
32embedded-storage = "0.3.0" 32embedded-storage = "0.3.0"
33static_cell = "1.0" 33static_cell = { version = "1.1", features = ["nightly"]}
34 34
35# cargo build/run 35# cargo build/run
36[profile.dev] 36[profile.dev]
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index dbfc90cf4..3aa7b2271 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -15,18 +15,8 @@ use embassy_stm32::{bind_interrupts, eth, Config};
15use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::StaticCell; 18use static_cell::make_static;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20
21macro_rules! singleton {
22 ($val:expr) => {{
23 type T = impl Sized;
24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 let (x,) = STATIC_CELL.init(($val,));
26 x
27 }};
28}
29
30bind_interrupts!(struct Irqs { 20bind_interrupts!(struct Irqs {
31 ETH => eth::InterruptHandler; 21 ETH => eth::InterruptHandler;
32}); 22});
@@ -56,7 +46,7 @@ async fn main(spawner: Spawner) -> ! {
56 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; 46 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
57 47
58 let device = Ethernet::new( 48 let device = Ethernet::new(
59 singleton!(PacketQueue::<16, 16>::new()), 49 make_static!(PacketQueue::<16, 16>::new()),
60 p.ETH, 50 p.ETH,
61 Irqs, 51 Irqs,
62 p.PA1, 52 p.PA1,
@@ -81,7 +71,12 @@ async fn main(spawner: Spawner) -> ! {
81 //}); 71 //});
82 72
83 // Init network stack 73 // Init network stack
84 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 74 let stack = &*make_static!(Stack::new(
75 device,
76 config,
77 make_static!(StackResources::<2>::new()),
78 seed
79 ));
85 80
86 // Launch network task 81 // Launch network task
87 unwrap!(spawner.spawn(net_task(&stack))); 82 unwrap!(spawner.spawn(net_task(&stack)));
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 14e6b7914..575c716b6 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -16,18 +16,8 @@ use embassy_time::{Duration, Timer};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; 17use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
18use rand_core::RngCore; 18use rand_core::RngCore;
19use static_cell::StaticCell; 19use static_cell::make_static;
20use {defmt_rtt as _, panic_probe as _}; 20use {defmt_rtt as _, panic_probe as _};
21
22macro_rules! singleton {
23 ($val:expr) => {{
24 type T = impl Sized;
25 static STATIC_CELL: StaticCell<T> = StaticCell::new();
26 let (x,) = STATIC_CELL.init(($val,));
27 x
28 }};
29}
30
31bind_interrupts!(struct Irqs { 21bind_interrupts!(struct Irqs {
32 ETH => eth::InterruptHandler; 22 ETH => eth::InterruptHandler;
33}); 23});
@@ -57,7 +47,7 @@ async fn main(spawner: Spawner) -> ! {
57 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; 47 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
58 48
59 let device = Ethernet::new( 49 let device = Ethernet::new(
60 singleton!(PacketQueue::<16, 16>::new()), 50 make_static!(PacketQueue::<16, 16>::new()),
61 p.ETH, 51 p.ETH,
62 Irqs, 52 Irqs,
63 p.PA1, 53 p.PA1,
@@ -82,7 +72,12 @@ async fn main(spawner: Spawner) -> ! {
82 //}); 72 //});
83 73
84 // Init network stack 74 // Init network stack
85 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 75 let stack = &*make_static!(Stack::new(
76 device,
77 config,
78 make_static!(StackResources::<2>::new()),
79 seed
80 ));
86 81
87 // Launch network task 82 // Launch network task
88 unwrap!(spawner.spawn(net_task(&stack))); 83 unwrap!(spawner.spawn(net_task(&stack)));
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index ffb6cdb43..235f1b0b3 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -31,4 +31,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
31futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 31futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
32heapless = { version = "0.7.5", default-features = false } 32heapless = { version = "0.7.5", default-features = false }
33embedded-hal = "0.2.6" 33embedded-hal = "0.2.6"
34static_cell = "1.0" 34static_cell = "1.1"
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml
index acb48c765..2ac9c180d 100644
--- a/examples/stm32l5/Cargo.toml
+++ b/examples/stm32l5/Cargo.toml
@@ -25,4 +25,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
25heapless = { version = "0.7.5", default-features = false } 25heapless = { version = "0.7.5", default-features = false }
26rand_core = { version = "0.6.3", default-features = false } 26rand_core = { version = "0.6.3", default-features = false }
27embedded-io = { version = "0.4.0", features = ["async"] } 27embedded-io = { version = "0.4.0", features = ["async"] }
28static_cell = "1.0" 28static_cell = { version = "1.1", features = ["nightly"]}
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index b84e53d3a..6163e0709 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -15,20 +15,11 @@ use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
15use embassy_usb::{Builder, UsbDevice}; 15use embassy_usb::{Builder, UsbDevice};
16use embedded_io::asynch::Write; 16use embedded_io::asynch::Write;
17use rand_core::RngCore; 17use rand_core::RngCore;
18use static_cell::StaticCell; 18use static_cell::make_static;
19use {defmt_rtt as _, panic_probe as _}; 19use {defmt_rtt as _, panic_probe as _};
20 20
21type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; 21type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>;
22 22
23macro_rules! singleton {
24 ($val:expr) => {{
25 type T = impl Sized;
26 static STATIC_CELL: StaticCell<T> = StaticCell::new();
27 let (x,) = STATIC_CELL.init(($val,));
28 x
29 }};
30}
31
32const MTU: usize = 1514; 23const MTU: usize = 1514;
33 24
34bind_interrupts!(struct Irqs { 25bind_interrupts!(struct Irqs {
@@ -78,10 +69,10 @@ async fn main(spawner: Spawner) {
78 let mut builder = Builder::new( 69 let mut builder = Builder::new(
79 driver, 70 driver,
80 config, 71 config,
81 &mut singleton!([0; 256])[..], 72 &mut make_static!([0; 256])[..],
82 &mut singleton!([0; 256])[..], 73 &mut make_static!([0; 256])[..],
83 &mut singleton!([0; 256])[..], 74 &mut make_static!([0; 256])[..],
84 &mut singleton!([0; 128])[..], 75 &mut make_static!([0; 128])[..],
85 ); 76 );
86 77
87 // Our MAC addr. 78 // Our MAC addr.
@@ -90,14 +81,14 @@ async fn main(spawner: Spawner) {
90 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 81 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
91 82
92 // Create classes on the builder. 83 // Create classes on the builder.
93 let class = CdcNcmClass::new(&mut builder, singleton!(State::new()), host_mac_addr, 64); 84 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64);
94 85
95 // Build the builder. 86 // Build the builder.
96 let usb = builder.build(); 87 let usb = builder.build();
97 88
98 unwrap!(spawner.spawn(usb_task(usb))); 89 unwrap!(spawner.spawn(usb_task(usb)));
99 90
100 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr); 91 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
101 unwrap!(spawner.spawn(usb_ncm_task(runner))); 92 unwrap!(spawner.spawn(usb_ncm_task(runner)));
102 93
103 let config = embassy_net::Config::Dhcp(Default::default()); 94 let config = embassy_net::Config::Dhcp(Default::default());
@@ -112,7 +103,12 @@ async fn main(spawner: Spawner) {
112 let seed = rng.next_u64(); 103 let seed = rng.next_u64();
113 104
114 // Init network stack 105 // Init network stack
115 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed)); 106 let stack = &*make_static!(Stack::new(
107 device,
108 config,
109 make_static!(StackResources::<2>::new()),
110 seed
111 ));
116 112
117 unwrap!(spawner.spawn(net_task(stack))); 113 unwrap!(spawner.spawn(net_task(stack)));
118 114