diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index bf1468642..d970d0332 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -411,10 +411,12 @@ impl Stack { /// ```ignore /// let config = embassy_net::Config::dhcpv4(Default::default()); ///// Init network stack - /// let stack = &*make_static!(embassy_net::Stack::new( + /// static RESOURCES: StaticCell = StaticCell::new(); + /// static STACK: StaticCell = StaticCell::new(); + /// let stack = &*STACK.init(embassy_net::Stack::new( /// device, /// config, - /// make_static!(embassy_net::StackResources::<2>::new()), + /// RESOURCES.init(embassy_net::StackResources::new()), /// seed /// )); /// // Launch network task that runs `stack.run().await` diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs index a41c40eba..4fab8dae4 100644 --- a/embassy-stm32/src/low_power.rs +++ b/embassy-stm32/src/low_power.rs @@ -24,7 +24,7 @@ //! use embassy_executor::Spawner; //! use embassy_stm32::low_power::Executor; //! use embassy_stm32::rtc::{Rtc, RtcConfig}; -//! use static_cell::make_static; +//! use static_cell::StaticCell; //! //! #[cortex_m_rt::entry] //! fn main() -> ! { @@ -41,7 +41,8 @@ //! //! // give the RTC to the executor... //! let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); -//! let rtc = make_static!(rtc); +//! static RTC: StaticCell = StaticCell::new(); +//! let rtc = RTC.init(rtc); //! embassy_stm32::low_power::stop_with_rtc(rtc); //! //! // your application here... diff --git a/examples/nrf52840/src/bin/ethernet_enc28j60.rs b/examples/nrf52840/src/bin/ethernet_enc28j60.rs index d1b796fab..840a16556 100644 --- a/examples/nrf52840/src/bin/ethernet_enc28j60.rs +++ b/examples/nrf52840/src/bin/ethernet_enc28j60.rs @@ -14,7 +14,7 @@ use embassy_nrf::{bind_interrupts, peripherals, spim}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -70,11 +70,20 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static RESOURCES: StaticCell> = StaticCell::new(); + static STACK: StaticCell< + Stack< + Enc28j60< + ExclusiveDevice, Output<'static, peripherals::P0_15>, Delay>, + Output<'static, peripherals::P0_13>, + >, + >, + > = StaticCell::new(); + let stack = STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index b7806f418..de661c019 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 use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, Config, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -71,14 +71,19 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 128])[..], - &mut make_static!([0; 128])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], + &mut MSOS_DESC.init([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -87,14 +92,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -111,12 +118,9 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( - device, - config, - make_static!(StackResources::<2>::new()), - seed - )); + static RESOURCES: StaticCell> = StaticCell::new(); + static STACK: StaticCell>> = StaticCell::new(); + let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed)); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/nrf52840/src/bin/usb_serial_multitask.rs b/examples/nrf52840/src/bin/usb_serial_multitask.rs index cd4392903..7a7bf962b 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}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::driver::EndpointError; use embassy_usb::{Builder, Config, UsbDevice}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,17 +64,23 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; config.composite_with_iads = true; - let state = make_static!(State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(State::new()); // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 128])[..], - &mut make_static!([0; 128])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], + &mut MSOS_DESC.init([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Create classes on the builder. diff --git a/examples/nrf52840/src/bin/wifi_esp_hosted.rs b/examples/nrf52840/src/bin/wifi_esp_hosted.rs index a60822fd9..b56c9bd8d 100644 --- a/examples/nrf52840/src/bin/wifi_esp_hosted.rs +++ b/examples/nrf52840/src/bin/wifi_esp_hosted.rs @@ -13,7 +13,7 @@ use embassy_nrf::{bind_interrupts, peripherals}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; const WIFI_NETWORK: &str = "EmbassyTest"; @@ -61,8 +61,9 @@ async fn main(spawner: Spawner) { let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); let spi = ExclusiveDevice::new(spi, cs, Delay); + static ESP_STATE: StaticCell = StaticCell::new(); let (device, mut control, runner) = embassy_net_esp_hosted::new( - make_static!(embassy_net_esp_hosted::State::new()), + ESP_STATE.init(embassy_net_esp_hosted::State::new()), spi, handshake, ready, @@ -89,11 +90,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static RESOURCES: StaticCell> = StaticCell::new(); + static STACK: StaticCell>> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs index c0fde62ab..b9dba0f1d 100644 --- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs +++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs @@ -20,7 +20,7 @@ use embassy_time::{Delay, Duration}; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -55,7 +55,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -70,11 +71,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs index b19362fc1..36073f20b 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs @@ -22,7 +22,7 @@ use embassy_time::{Delay, Duration, Timer}; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -58,7 +58,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -73,11 +74,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs index c62caed7a..d523a8772 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs @@ -21,7 +21,7 @@ use embassy_time::{Delay, Duration}; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_io_async::Write; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -57,7 +57,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -72,11 +73,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs index 76dabce1c..0cc47cb56 100644 --- a/examples/rp/src/bin/ethernet_w5500_udp.rs +++ b/examples/rp/src/bin/ethernet_w5500_udp.rs @@ -20,7 +20,7 @@ use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -55,7 +55,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -70,11 +71,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs index 14e8810a4..dc57d89c7 100644 --- a/examples/rp/src/bin/uart_buffered_split.rs +++ b/examples/rp/src/bin/uart_buffered_split.rs @@ -15,7 +15,7 @@ use embassy_rp::peripherals::UART0; use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config}; use embassy_time::Timer; use embedded_io_async::{Read, Write}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -27,8 +27,10 @@ async fn main(spawner: Spawner) { let p = embassy_rp::init(Default::default()); let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0); - let tx_buf = &mut make_static!([0u8; 16])[..]; - let rx_buf = &mut make_static!([0u8; 16])[..]; + static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new(); + let tx_buf = &mut TX_BUF.init([0; 16])[..]; + static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new(); + let rx_buf = &mut RX_BUF.init([0; 16])[..]; let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default()); let (rx, mut tx) = uart.split(); diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index cc63029fb..674b83f5d 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs @@ -17,7 +17,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, Config, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -65,14 +65,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -81,14 +85,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -102,11 +108,13 @@ async fn main(spawner: Spawner) { let seed = 1234; // guaranteed random, chosen by a fair dice roll // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index ad1fa6462..20b8aad15 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs @@ -19,7 +19,7 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::Duration; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -59,7 +59,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); @@ -79,11 +80,13 @@ async fn main(spawner: Spawner) { let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( net_device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs index 14ace74e9..b89447b7d 100644 --- a/examples/rp/src/bin/wifi_blinky.rs +++ b/examples/rp/src/bin/wifi_blinky.rs @@ -14,7 +14,7 @@ use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::{Duration, Timer}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -46,7 +46,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs index 7adf52b88..0f7ad27dd 100644 --- a/examples/rp/src/bin/wifi_scan.rs +++ b/examples/rp/src/bin/wifi_scan.rs @@ -16,7 +16,7 @@ use embassy_rp::bind_interrupts; use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -56,7 +56,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index ec6b4ee74..f6cc48d8f 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs @@ -19,7 +19,7 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_time::{Duration, Timer}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -62,7 +62,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); @@ -82,11 +83,13 @@ async fn main(spawner: Spawner) { let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( net_device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index 8d8345057..c62a38d07 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -12,7 +12,7 @@ use embedded_io_async::Write; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -54,11 +54,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index 6c19874d5..e1e015bc8 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs @@ -10,7 +10,7 @@ use embassy_net_tuntap::TunTapDevice; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -53,11 +53,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack: &Stack<_> = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack: &Stack<_> = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index cee04e558..8c80c4beb 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs @@ -25,7 +25,7 @@ use heapless::Vec; use log::*; use nix::sys::termios; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; use crate::serial_port::SerialPort; @@ -88,7 +88,8 @@ async fn main_task(spawner: Spawner) { let port = SerialPort::new(opts.device.as_str(), baudrate).unwrap(); // Init network device - let state = make_static!(embassy_net_ppp::State::<4, 4>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(embassy_net_ppp::State::<4, 4>::new()); let (device, runner) = embassy_net_ppp::new(state); // Generate random seed @@ -97,11 +98,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, Config::default(), // don't configure IP yet - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 98dcc9925..ac99ec626 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs @@ -8,7 +8,7 @@ use embassy_net_tuntap::TunTapDevice; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -50,11 +50,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 79fa375cd..54ef0156b 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs @@ -13,7 +13,7 @@ use embedded_io_async::Write as _; use heapless::Vec; use log::*; use rand_core::{OsRng, RngCore}; -use static_cell::{make_static, StaticCell}; +use static_cell::StaticCell; #[derive(Parser)] #[clap(version = "1.0")] @@ -65,11 +65,13 @@ async fn main_task(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 088d83c06..17a14aac4 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::time::Hertz; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -63,8 +63,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -88,11 +89,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index 6bf5b1cba..57ee35e97 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs @@ -14,7 +14,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, UsbDevice}; use embedded_io_async::Write; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; @@ -68,7 +68,8 @@ async fn main(spawner: Spawner) { let p = embassy_stm32::init(config); // Create the driver, from the HAL. - let ep_out_buffer = &mut make_static!([0; 256])[..]; + static OUTPUT_BUFFER: StaticCell<[u8; 256]> = StaticCell::new(); + let ep_out_buffer = &mut OUTPUT_BUFFER.init([0; 256])[..]; let mut config = embassy_stm32::usb_otg::Config::default(); config.vbus_detection = true; let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config); @@ -88,14 +89,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -104,14 +109,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -128,11 +135,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index 78b21ceaa..06cd1ac7e 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs @@ -12,6 +12,7 @@ use embassy_stm32::can::{ }; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::peripherals::CAN3; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -43,7 +44,8 @@ async fn main(spawner: Spawner) { let rx_pin = Input::new(&mut p.PA15, Pull::Up); core::mem::forget(rx_pin); - let can: &'static mut Can<'static, CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); + static CAN: StaticCell> = StaticCell::new(); + let can = CAN.init(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); can.as_mut() .modify_filters() .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); @@ -56,7 +58,8 @@ async fn main(spawner: Spawner) { let (tx, mut rx) = can.split(); - let tx: &'static mut CanTx<'static, 'static, CAN3> = static_cell::make_static!(tx); + static CAN_TX: StaticCell> = StaticCell::new(); + let tx = CAN_TX.init(tx); spawner.spawn(send_can_message(tx)).unwrap(); loop { diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index dd0069447..86c709852 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -15,7 +15,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,8 +64,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -89,11 +90,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index b2758cba0..8789e4e0b 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs @@ -18,7 +18,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -67,8 +67,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<4, 4>::new()), + PACKETS.init(PacketQueue::<4, 4>::new()), p.ETH, Irqs, p.PA1, @@ -92,11 +93,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index dbddfc22f..a64b3253a 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,8 +64,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<4, 4>::new()), p.ETH, Irqs, p.PA1, @@ -89,11 +90,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 17e1d9fb7..8e84d9964 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -15,7 +15,7 @@ use embassy_time::Timer; use embedded_io_async::Write; use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -65,8 +65,9 @@ async fn main(spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::<16, 16>::new()), + PACKETS.init(PacketQueue::<16, 16>::new()), p.ETH, Irqs, p.PA1, @@ -90,11 +91,13 @@ async fn main(spawner: Spawner) -> ! { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<3>::new()), - seed + RESOURCES.init(StackResources::<3>::new()), + seed, )); // Launch network task diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index 8ec810c7f..eb04fe5e6 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs @@ -36,7 +36,7 @@ use hal::rng::{self, Rng}; use hal::{bind_interrupts, exti, pac, peripherals}; use heapless::Vec; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {embassy_stm32 as hal, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -180,7 +180,8 @@ async fn main(spawner: Spawner) { } }; - let state = make_static!(embassy_net_adin1110::State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(embassy_net_adin1110::State::<8, 8>::new()); let (device, runner) = embassy_net_adin1110::new( MAC, @@ -217,11 +218,13 @@ async fn main(spawner: Spawner) { }; // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, ip_cfg, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 0b0a0e2db..214235bd5 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs @@ -15,7 +15,7 @@ use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; use embassy_usb::{Builder, UsbDevice}; use embedded_io_async::Write; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; @@ -76,14 +76,18 @@ async fn main(spawner: Spawner) { config.device_protocol = 0x01; // Create embassy-usb DeviceBuilder using the driver and config. + static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); + static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); let mut builder = Builder::new( driver, config, - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], - &mut make_static!([0; 256])[..], + &mut DEVICE_DESC.init([0; 256])[..], + &mut CONFIG_DESC.init([0; 256])[..], + &mut BOS_DESC.init([0; 256])[..], &mut [], // no msos descriptors - &mut make_static!([0; 128])[..], + &mut CONTROL_BUF.init([0; 128])[..], ); // Our MAC addr. @@ -92,14 +96,16 @@ async fn main(spawner: Spawner) { let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; // Create classes on the builder. - let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); + static STATE: StaticCell = StaticCell::new(); + let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); // Build the builder. let usb = builder.build(); unwrap!(spawner.spawn(usb_task(usb))); - let (runner, device) = class.into_embassy_net_device::(make_static!(NetState::new()), our_mac_addr); + static NET_STATE: StaticCell> = StaticCell::new(); + let (runner, device) = class.into_embassy_net_device::(NET_STATE.init(NetState::new()), our_mac_addr); unwrap!(spawner.spawn(usb_ncm_task(runner))); let config = embassy_net::Config::dhcpv4(Default::default()); @@ -114,11 +120,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs index f8c76b5a4..454530c03 100644 --- a/examples/stm32wb/src/bin/mac_ffd_net.rs +++ b/examples/stm32wb/src/bin/mac_ffd_net.rs @@ -12,7 +12,7 @@ use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId}; use embassy_stm32_wpan::mac::{self, Runner}; use embassy_stm32_wpan::sub::mm; use embassy_stm32_wpan::TlMbox; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs{ @@ -154,15 +154,21 @@ async fn main(spawner: Spawner) { .unwrap(); defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); + static TX1: StaticCell<[u8; 127]> = StaticCell::new(); + static TX2: StaticCell<[u8; 127]> = StaticCell::new(); + static TX3: StaticCell<[u8; 127]> = StaticCell::new(); + static TX4: StaticCell<[u8; 127]> = StaticCell::new(); + static TX5: StaticCell<[u8; 127]> = StaticCell::new(); let tx_queue = [ - make_static!([0u8; 127]), - make_static!([0u8; 127]), - make_static!([0u8; 127]), - make_static!([0u8; 127]), - make_static!([0u8; 127]), + TX1.init([0u8; 127]), + TX2.init([0u8; 127]), + TX3.init([0u8; 127]), + TX4.init([0u8; 127]), + TX5.init([0u8; 127]), ]; - let runner = make_static!(Runner::new(mbox.mac_subsystem, tx_queue)); + static RUNNER: StaticCell = StaticCell::new(); + let runner = RUNNER.init(Runner::new(mbox.mac_subsystem, tx_queue)); spawner.spawn(run_mac(runner)).unwrap(); diff --git a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs index 60d30a2ff..c26c0d066 100644 --- a/tests/nrf/src/bin/ethernet_enc28j60_perf.rs +++ b/tests/nrf/src/bin/ethernet_enc28j60_perf.rs @@ -14,7 +14,7 @@ use embassy_nrf::spim::{self, Spim}; use embassy_nrf::{bind_interrupts, peripherals}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -68,11 +68,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs index 9eee39ccf..5b43b75d7 100644 --- a/tests/nrf/src/bin/wifi_esp_hosted_perf.rs +++ b/tests/nrf/src/bin/wifi_esp_hosted_perf.rs @@ -13,7 +13,7 @@ use embassy_nrf::spim::{self, Spim}; use embassy_nrf::{bind_interrupts, peripherals}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, embassy_net_esp_hosted as hosted, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -64,8 +64,9 @@ async fn main(spawner: Spawner) { let spi = spim::Spim::new(p.SPI3, Irqs, sck, miso, mosi, config); let spi = ExclusiveDevice::new(spi, cs, Delay); + static STATE: StaticCell = StaticCell::new(); let (device, mut control, runner) = embassy_net_esp_hosted::new( - make_static!(embassy_net_esp_hosted::State::new()), + STATE.init(embassy_net_esp_hosted::State::new()), spi, handshake, ready, @@ -85,11 +86,13 @@ async fn main(spawner: Spawner) { let seed = u64::from_le_bytes(seed); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index de29c06dd..d70ef8ef3 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs @@ -11,7 +11,7 @@ use embassy_rp::gpio::{Level, Output}; use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; use embassy_rp::pio::{InterruptHandler, Pio}; use embassy_rp::{bind_interrupts, rom_data}; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; bind_interrupts!(struct Irqs { @@ -58,7 +58,8 @@ async fn main(spawner: Spawner) { let mut pio = Pio::new(p.PIO0, Irqs); let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); - let state = make_static!(cyw43::State::new()); + static STATE: StaticCell = StaticCell::new(); + let state = STATE.init(cyw43::State::new()); let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; unwrap!(spawner.spawn(wifi_task(runner))); @@ -71,11 +72,13 @@ async fn main(spawner: Spawner) { let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random. // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( net_device, Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); unwrap!(spawner.spawn(net_task(stack))); diff --git a/tests/rp/src/bin/ethernet_w5100s_perf.rs b/tests/rp/src/bin/ethernet_w5100s_perf.rs index a4d253b3c..5588b6427 100644 --- a/tests/rp/src/bin/ethernet_w5100s_perf.rs +++ b/tests/rp/src/bin/ethernet_w5100s_perf.rs @@ -16,7 +16,7 @@ use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use rand::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::task] @@ -51,7 +51,8 @@ async fn main(spawner: Spawner) { let w5500_reset = Output::new(p.PIN_20, Level::High); let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; - let state = make_static!(State::<8, 8>::new()); + static STATE: StaticCell> = StaticCell::new(); + let state = STATE.init(State::<8, 8>::new()); let (device, runner) = embassy_net_wiznet::new( mac_addr, state, @@ -66,11 +67,13 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell>> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, embassy_net::Config::dhcpv4(Default::default()), - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs index 754354944..c01f33a97 100644 --- a/tests/stm32/src/bin/eth.rs +++ b/tests/stm32/src/bin/eth.rs @@ -14,7 +14,7 @@ use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::{bind_interrupts, eth, peripherals, rng}; use rand_core::RngCore; -use static_cell::make_static; +use static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; teleprobe_meta::timeout!(120); @@ -71,8 +71,9 @@ async fn main(spawner: Spawner) { #[cfg(not(feature = "stm32f207zg"))] const PACKET_QUEUE_SIZE: usize = 4; + static PACKETS: StaticCell> = StaticCell::new(); let device = Ethernet::new( - make_static!(PacketQueue::::new()), + PACKETS.init(PacketQueue::::new()), p.ETH, Irqs, p.PA1, @@ -99,11 +100,13 @@ async fn main(spawner: Spawner) { //}); // Init network stack - let stack = &*make_static!(Stack::new( + static STACK: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); + let stack = &*STACK.init(Stack::new( device, config, - make_static!(StackResources::<2>::new()), - seed + RESOURCES.init(StackResources::<2>::new()), + seed, )); // Launch network task diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs index b9810673a..f8e3c43d7 100644 --- a/tests/stm32/src/bin/stop.rs +++ b/tests/stm32/src/bin/stop.rs @@ -15,7 +15,7 @@ use embassy_stm32::rcc::LsConfig; use embassy_stm32::rtc::{Rtc, RtcConfig}; use embassy_stm32::Config; use embassy_time::Timer; -use static_cell::make_static; +use static_cell::StaticCell; #[entry] fn main() -> ! { @@ -64,7 +64,8 @@ async fn async_main(spawner: Spawner) { rtc.set_datetime(now.into()).expect("datetime not set"); - let rtc = make_static!(rtc); + static RTC: StaticCell = StaticCell::new(); + let rtc = RTC.init(rtc); stop_with_rtc(rtc);