Skip to content

Commit

Permalink
Merge pull request #1523 from embassy-rs/static-cell
Browse files Browse the repository at this point in the history
Use make_static! from static-cell v1.1
  • Loading branch information
Dirbaio committed Jun 1, 2023
2 parents d7d66bd + 1d8321b commit 626ec5f
Show file tree
Hide file tree
Showing 39 changed files with 170 additions and 301 deletions.
2 changes: 1 addition & 1 deletion embassy-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ embassy-macros = { version = "0.2.0", path = "../embassy-macros" }
embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true}
atomic-polyfill = "1.0.1"
critical-section = "1.1"
static_cell = "1.0"
static_cell = "1.1"

# arch-cortex-m dependencies
cortex-m = { version = "0.7.6", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion embassy-rp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ rp2040-boot2 = "0.3"

[dev-dependencies]
embassy-executor = { version = "0.2.0", path = "../embassy-executor", features = ["arch-std", "executor-thread"] }
static_cell = "1.0"
static_cell = "1.1"
2 changes: 1 addition & 1 deletion embassy-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ futures-util = { version = "0.3.17", features = [ "channel" ] }

# Enable critical-section implementation for std, for tests
critical-section = { version = "1.1", features = ["std"] }
static_cell = "1.0"
static_cell = "1.1"
1 change: 1 addition & 0 deletions examples/boot/bootloader/rp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ debug = ["defmt-rtt", "defmt"]

[profile.release]
debug = true
opt-level = 's'
4 changes: 2 additions & 2 deletions examples/nrf52840/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"

[features]
default = ["nightly"]
nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits",
nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-net/nightly", "embassy-nrf/unstable-traits", "embassy-time/nightly", "embassy-time/unstable-traits", "static_cell/nightly",
"embassy-usb", "embedded-io/async", "embassy-net", "embassy-lora", "lora-phy", "lorawan-device", "lorawan"]

[dependencies]
Expand All @@ -26,7 +26,7 @@ lorawan = { version = "0.7.3", default-features = false, features = ["default-cr
defmt = "0.3"
defmt-rtt = "0.4"

static_cell = "1.0"
static_cell = "1.1"
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.0"
panic-probe = { version = "0.3", features = ["print-defmt"] }
Expand Down
32 changes: 14 additions & 18 deletions examples/nrf52840/src/bin/usb_ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::asynch::Write;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};

bind_interrupts!(struct Irqs {
Expand All @@ -27,15 +27,6 @@ bind_interrupts!(struct Irqs {

type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;

macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

const MTU: usize = 1514;

#[embassy_executor::task]
Expand Down Expand Up @@ -83,11 +74,11 @@ async fn main(spawner: Spawner) {
let mut builder = Builder::new(
driver,
config,
&mut singleton!([0; 256])[..],
&mut singleton!([0; 256])[..],
&mut singleton!([0; 256])[..],
&mut singleton!([0; 128])[..],
&mut singleton!([0; 128])[..],
&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])[..],
);

// Our MAC addr.
Expand All @@ -96,14 +87,14 @@ 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, singleton!(State::new()), host_mac_addr, 64);
let class = CdcNcmClass::new(&mut builder, make_static!(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::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
unwrap!(spawner.spawn(usb_ncm_task(runner)));

let config = embassy_net::Config::Dhcp(Default::default());
Expand All @@ -120,7 +111,12 @@ async fn main(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);

// Init network stack
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
let stack = &*make_static!(Stack::new(
device,
config,
make_static!(StackResources::<2>::new()),
seed
));

unwrap!(spawner.spawn(net_task(stack)));

Expand Down
23 changes: 7 additions & 16 deletions examples/nrf52840/src/bin/usb_serial_multitask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@ 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::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};

bind_interrupts!(struct Irqs {
USBD => usb::InterruptHandler<peripherals::USBD>;
POWER_CLOCK => usb::vbus_detect::InterruptHandler;
});

macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;

#[embassy_executor::task]
Expand Down Expand Up @@ -73,17 +64,17 @@ async fn main(spawner: Spawner) {
config.device_protocol = 0x01;
config.composite_with_iads = true;

let state = singleton!(State::new());
let state = make_static!(State::new());

// Create embassy-usb DeviceBuilder using the driver and config.
let mut builder = Builder::new(
driver,
config,
&mut singleton!([0; 256])[..],
&mut singleton!([0; 256])[..],
&mut singleton!([0; 256])[..],
&mut singleton!([0; 128])[..],
&mut singleton!([0; 128])[..],
&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])[..],
);

// Create classes on the builder.
Expand Down
2 changes: 1 addition & 1 deletion examples/nrf5340/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ embedded-io = { version = "0.4.0", features = [ "async" ]}
defmt = "0.3"
defmt-rtt = "0.4"

static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.0"
panic-probe = { version = "0.3", features = ["print-defmt"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/rp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
embedded-hal-async = "0.2.0-alpha.1"
embedded-io = { version = "0.4.0", features = ["async", "defmt"] }
embedded-storage = { version = "0.3" }
static_cell = "1.0.0"
static_cell = { version = "1.1", features = ["nightly"]}
log = "0.4"
pio-proc = "0.2"
pio = "0.2.1"
Expand Down
17 changes: 4 additions & 13 deletions examples/rp/src/bin/ethernet_w5500_multisocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,9 @@ use embassy_time::Duration;
use embedded_hal_async::spi::ExclusiveDevice;
use embedded_io::asynch::Write;
use rand::RngCore;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};

macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

#[embassy_executor::task]
async fn ethernet_task(
runner: Runner<
Expand Down Expand Up @@ -62,7 +53,7 @@ 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 = singleton!(State::<8, 8>::new());
let state = make_static!(State::<8, 8>::new());
let (device, runner) =
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
unwrap!(spawner.spawn(ethernet_task(runner)));
Expand All @@ -71,10 +62,10 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();

// Init network stack
let stack = &*singleton!(Stack::new(
let stack = &*make_static!(Stack::new(
device,
embassy_net::Config::Dhcp(Default::default()),
singleton!(StackResources::<3>::new()),
make_static!(StackResources::<3>::new()),
seed
));

Expand Down
17 changes: 4 additions & 13 deletions examples/rp/src/bin/ethernet_w5500_tcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@ use embassy_time::{Duration, Timer};
use embedded_hal_async::spi::ExclusiveDevice;
use embedded_io::asynch::Write;
use rand::RngCore;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};

macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

#[embassy_executor::task]
async fn ethernet_task(
runner: Runner<
Expand Down Expand Up @@ -65,7 +56,7 @@ 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 = singleton!(State::<8, 8>::new());
let state = make_static!(State::<8, 8>::new());
let (device, runner) =
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
unwrap!(spawner.spawn(ethernet_task(runner)));
Expand All @@ -74,10 +65,10 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();

// Init network stack
let stack = &*singleton!(Stack::new(
let stack = &*make_static!(Stack::new(
device,
embassy_net::Config::Dhcp(Default::default()),
singleton!(StackResources::<2>::new()),
make_static!(StackResources::<2>::new()),
seed
));

Expand Down
18 changes: 4 additions & 14 deletions examples/rp/src/bin/ethernet_w5500_tcp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@ use embassy_time::Duration;
use embedded_hal_async::spi::ExclusiveDevice;
use embedded_io::asynch::Write;
use rand::RngCore;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};

macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

#[embassy_executor::task]
async fn ethernet_task(
runner: Runner<
Expand Down Expand Up @@ -64,7 +54,7 @@ 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 = singleton!(State::<8, 8>::new());
let state = make_static!(State::<8, 8>::new());
let (device, runner) =
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
unwrap!(spawner.spawn(ethernet_task(runner)));
Expand All @@ -73,10 +63,10 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();

// Init network stack
let stack = &*singleton!(Stack::new(
let stack = &*make_static!(Stack::new(
device,
embassy_net::Config::Dhcp(Default::default()),
singleton!(StackResources::<2>::new()),
make_static!(StackResources::<2>::new()),
seed
));

Expand Down
18 changes: 4 additions & 14 deletions examples/rp/src/bin/ethernet_w5500_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@ use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0};
use embassy_rp::spi::{Async, Config as SpiConfig, Spi};
use embedded_hal_async::spi::ExclusiveDevice;
use rand::RngCore;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};

macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

#[embassy_executor::task]
async fn ethernet_task(
runner: Runner<
Expand Down Expand Up @@ -61,7 +51,7 @@ 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 = singleton!(State::<8, 8>::new());
let state = make_static!(State::<8, 8>::new());
let (device, runner) =
embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await;
unwrap!(spawner.spawn(ethernet_task(runner)));
Expand All @@ -70,10 +60,10 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();

// Init network stack
let stack = &*singleton!(Stack::new(
let stack = &*make_static!(Stack::new(
device,
embassy_net::Config::Dhcp(Default::default()),
singleton!(StackResources::<2>::new()),
make_static!(StackResources::<2>::new()),
seed
));

Expand Down
2 changes: 1 addition & 1 deletion examples/rp/src/bin/lora_p2p_send_multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use defmt::*;
use embassy_executor::Executor;
use embassy_executor::_export::StaticCell;
use embassy_lora::iv::GenericSx126xInterfaceVariant;
use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull};
use embassy_rp::multicore::{spawn_core1, Stack};
Expand All @@ -19,6 +18,7 @@ use embassy_time::{Delay, Duration, Timer};
use lora_phy::mod_params::*;
use lora_phy::sx1261_2::SX1261_2;
use lora_phy::LoRa;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};

static mut CORE1_STACK: Stack<4096> = Stack::new();
Expand Down
2 changes: 1 addition & 1 deletion examples/rp/src/bin/multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use defmt::*;
use embassy_executor::Executor;
use embassy_executor::_export::StaticCell;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::multicore::{spawn_core1, Stack};
use embassy_rp::peripherals::PIN_25;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::Channel;
use embassy_time::{Duration, Timer};
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};

static mut CORE1_STACK: Stack<4096> = Stack::new();
Expand Down
Loading

0 comments on commit 626ec5f

Please sign in to comment.