Use make_static! from static-cell v1.1

This commit is contained in:
Dario Nieuwenhuis 2023-06-01 01:32:11 +02:00
parent d7d66bd74f
commit 1d8321b821
38 changed files with 168 additions and 300 deletions

View File

@ -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 }

View File

@ -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"

View File

@ -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"

View File

@ -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]
@ -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"] }

View File

@ -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 {
@ -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]
@ -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.
@ -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());
@ -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)));

View File

@ -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::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@ -20,15 +20,6 @@ bind_interrupts!(struct Irqs {
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]
@ -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.

View File

@ -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"] }

View File

@ -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"

View File

@ -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<
@ -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)));
@ -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
));

View File

@ -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<
@ -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)));
@ -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
));

View File

@ -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<
@ -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)));
@ -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
));

View File

@ -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<
@ -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)));
@ -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
));

View File

@ -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};
@ -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();

View File

@ -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();

View File

@ -4,34 +4,25 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_executor::_export::StaticCell;
use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::UART0;
use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config};
use embassy_time::{Duration, Timer};
use embedded_io::asynch::{Read, Write};
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
UART0_IRQ => BufferedInterruptHandler<UART0>;
});
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::main]
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 singleton!([0u8; 16])[..];
let rx_buf = &mut singleton!([0u8; 16])[..];
let tx_buf = &mut make_static!([0u8; 16])[..];
let rx_buf = &mut make_static!([0u8; 16])[..];
let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default());
let (rx, mut tx) = uart.split();

View File

@ -13,7 +13,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 {
@ -22,15 +22,6 @@ bind_interrupts!(struct Irqs {
type MyDriver = Driver<'static, peripherals::USB>;
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]
@ -73,10 +64,10 @@ 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 make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 128])[..],
);
// Our MAC addr.
@ -85,14 +76,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());
@ -106,7 +97,12 @@ async fn main(spawner: Spawner) {
let seed = 1234; // guaranteed random, chosen by a fair dice roll
// 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)));

View File

@ -16,17 +16,9 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::Pio;
use embassy_time::Duration;
use embedded_io::asynch::Write;
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();
STATIC_CELL.init_with(move || $val)
}};
}
#[embassy_executor::task]
async fn wifi_task(
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) {
let mut pio = Pio::new(p.PIO0);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = singleton!(cyw43::State::new());
let state = make_static!(cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));
@ -80,10 +72,10 @@ 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 = &*singleton!(Stack::new(
let stack = &*make_static!(Stack::new(
net_device,
config,
singleton!(StackResources::<2>::new()),
make_static!(StackResources::<2>::new()),
seed
));

View File

@ -13,17 +13,9 @@ use embassy_net::Stack;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::Pio;
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();
STATIC_CELL.init_with(move || $val)
}};
}
#[embassy_executor::task]
async fn wifi_task(
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) {
let mut pio = Pio::new(p.PIO0);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = singleton!(cyw43::State::new());
let state = make_static!(cyw43::State::new());
let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));

View File

@ -16,17 +16,9 @@ use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
use embassy_rp::pio::Pio;
use embassy_time::Duration;
use embedded_io::asynch::Write;
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();
STATIC_CELL.init_with(move || $val)
}};
}
#[embassy_executor::task]
async fn wifi_task(
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) {
let mut pio = Pio::new(p.PIO0);
let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
let state = singleton!(cyw43::State::new());
let state = make_static!(cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
unwrap!(spawner.spawn(wifi_task(runner)));
@ -80,10 +72,10 @@ 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 = &*singleton!(Stack::new(
let stack = &*make_static!(Stack::new(
net_device,
config,
singleton!(StackResources::<2>::new()),
make_static!(StackResources::<2>::new()),
seed
));

View File

@ -22,4 +22,4 @@ libc = "0.2.101"
clap = { version = "3.0.0-beta.5", features = ["derive"] }
rand_core = { version = "0.6.3", features = ["std"] }
heapless = { version = "0.7.5", default-features = false }
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}

View File

@ -11,21 +11,12 @@ use embedded_io::asynch::Write;
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::StaticCell;
use static_cell::{make_static, StaticCell};
#[path = "../tuntap.rs"]
mod tuntap;
use crate::tuntap::TunTapDevice;
macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
STATIC_CELL.init_with(move || $val)
}};
}
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
@ -66,7 +57,12 @@ async fn main_task(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed));
let stack = &*make_static!(Stack::new(
device,
config,
make_static!(StackResources::<3>::new()),
seed
));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -9,21 +9,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::StaticCell;
use static_cell::{make_static, StaticCell};
#[path = "../tuntap.rs"]
mod tuntap;
use crate::tuntap::TunTapDevice;
macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
STATIC_CELL.init_with(move || $val)
}};
}
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
@ -65,7 +56,12 @@ async fn main_task(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed));
let stack: &Stack<_> = &*make_static!(Stack::new(
device,
config,
make_static!(StackResources::<3>::new()),
seed
));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -7,21 +7,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::StaticCell;
use static_cell::{make_static, StaticCell};
#[path = "../tuntap.rs"]
mod tuntap;
use crate::tuntap::TunTapDevice;
macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
STATIC_CELL.init_with(move || $val)
}};
}
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
@ -62,7 +53,12 @@ async fn main_task(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed));
let stack = &*make_static!(Stack::new(
device,
config,
make_static!(StackResources::<3>::new()),
seed
));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -12,21 +12,12 @@ use embedded_io::asynch::Write as _;
use heapless::Vec;
use log::*;
use rand_core::{OsRng, RngCore};
use static_cell::StaticCell;
use static_cell::{make_static, StaticCell};
#[path = "../tuntap.rs"]
mod tuntap;
use crate::tuntap::TunTapDevice;
macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
STATIC_CELL.init_with(move || $val)
}};
}
#[derive(Parser)]
#[clap(version = "1.0")]
struct Opts {
@ -77,7 +68,12 @@ async fn main_task(spawner: Spawner) {
let seed = u64::from_le_bytes(seed);
// Init network stack
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed));
let stack = &*make_static!(Stack::new(
device,
config,
make_static!(StackResources::<3>::new()),
seed
));
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

View File

@ -16,4 +16,4 @@ embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["de
embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] }
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}

View File

@ -23,4 +23,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
heapless = { version = "0.7.5", default-features = false }
nb = "1.0.0"
embedded-storage = "0.3.0"
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}

View File

@ -25,7 +25,7 @@ heapless = { version = "0.7.5", default-features = false }
nb = "1.0.0"
embedded-storage = "0.3.0"
micromath = "2.0.0"
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}
chrono = { version = "^0.4", default-features = false}
[profile.release]

View File

@ -14,20 +14,11 @@ 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::asynch::Write;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};
type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>;
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]
@ -60,7 +51,7 @@ async fn main(spawner: Spawner) {
let p = embassy_stm32::init(config);
// Create the driver, from the HAL.
let ep_out_buffer = &mut singleton!([0; 256])[..];
let ep_out_buffer = &mut make_static!([0; 256])[..];
let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer);
// Create embassy-usb Config
@ -81,10 +72,10 @@ 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 make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 128])[..],
);
// Our MAC addr.
@ -93,14 +84,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());
@ -117,7 +108,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)));

View File

@ -26,4 +26,4 @@ nb = "1.0.0"
rand_core = "0.6.3"
critical-section = "1.1"
embedded-storage = "0.3.0"
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}

View File

@ -15,18 +15,8 @@ use embassy_stm32::{bind_interrupts, eth, Config};
use embassy_time::{Duration, Timer};
use embedded_io::asynch::Write;
use rand_core::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
}};
}
bind_interrupts!(struct Irqs {
ETH => eth::InterruptHandler;
});
@ -55,7 +45,7 @@ async fn main(spawner: Spawner) -> ! {
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
let device = Ethernet::new(
singleton!(PacketQueue::<16, 16>::new()),
make_static!(PacketQueue::<16, 16>::new()),
p.ETH,
Irqs,
p.PA1,
@ -80,7 +70,12 @@ async fn main(spawner: Spawner) -> ! {
//});
// 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
));
// Launch network task
unwrap!(spawner.spawn(net_task(&stack)));

View File

@ -30,7 +30,7 @@ critical-section = "1.1"
micromath = "2.0.0"
stm32-fmc = "0.2.4"
embedded-storage = "0.3.0"
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}
# cargo build/run
[profile.dev]

View File

@ -16,18 +16,8 @@ use embassy_stm32::{bind_interrupts, eth, Config};
use embassy_time::{Duration, Timer};
use embedded_io::asynch::Write;
use rand_core::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
}};
}
bind_interrupts!(struct Irqs {
ETH => eth::InterruptHandler;
});
@ -74,7 +64,7 @@ async fn main(spawner: Spawner) -> ! {
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
let device = Ethernet::new(
singleton!(PacketQueue::<4, 4>::new()),
make_static!(PacketQueue::<4, 4>::new()),
p.ETH,
Irqs,
p.PA1,
@ -99,7 +89,12 @@ async fn main(spawner: Spawner) -> ! {
//});
// 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
));
// Launch network task
unwrap!(spawner.spawn(net_task(&stack)));

View File

@ -30,7 +30,7 @@ critical-section = "1.1"
micromath = "2.0.0"
stm32-fmc = "0.2.4"
embedded-storage = "0.3.0"
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}
# cargo build/run
[profile.dev]

View File

@ -15,18 +15,8 @@ use embassy_stm32::{bind_interrupts, eth, Config};
use embassy_time::{Duration, Timer};
use embedded_io::asynch::Write;
use rand_core::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
}};
}
bind_interrupts!(struct Irqs {
ETH => eth::InterruptHandler;
});
@ -56,7 +46,7 @@ async fn main(spawner: Spawner) -> ! {
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
let device = Ethernet::new(
singleton!(PacketQueue::<16, 16>::new()),
make_static!(PacketQueue::<16, 16>::new()),
p.ETH,
Irqs,
p.PA1,
@ -81,7 +71,12 @@ async fn main(spawner: Spawner) -> ! {
//});
// 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
));
// Launch network task
unwrap!(spawner.spawn(net_task(&stack)));

View File

@ -16,18 +16,8 @@ use embassy_time::{Duration, Timer};
use embedded_io::asynch::Write;
use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
use rand_core::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
}};
}
bind_interrupts!(struct Irqs {
ETH => eth::InterruptHandler;
});
@ -57,7 +47,7 @@ async fn main(spawner: Spawner) -> ! {
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
let device = Ethernet::new(
singleton!(PacketQueue::<16, 16>::new()),
make_static!(PacketQueue::<16, 16>::new()),
p.ETH,
Irqs,
p.PA1,
@ -82,7 +72,12 @@ async fn main(spawner: Spawner) -> ! {
//});
// 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
));
// Launch network task
unwrap!(spawner.spawn(net_task(&stack)));

View File

@ -31,4 +31,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
heapless = { version = "0.7.5", default-features = false }
embedded-hal = "0.2.6"
static_cell = "1.0"
static_cell = "1.1"

View File

@ -25,4 +25,4 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
heapless = { version = "0.7.5", default-features = false }
rand_core = { version = "0.6.3", default-features = false }
embedded-io = { version = "0.4.0", features = ["async"] }
static_cell = "1.0"
static_cell = { version = "1.1", features = ["nightly"]}

View File

@ -15,20 +15,11 @@ use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
use embassy_usb::{Builder, UsbDevice};
use embedded_io::asynch::Write;
use rand_core::RngCore;
use static_cell::StaticCell;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};
type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>;
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;
bind_interrupts!(struct Irqs {
@ -78,10 +69,10 @@ 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 make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 256])[..],
&mut make_static!([0; 128])[..],
);
// Our MAC addr.
@ -90,14 +81,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());
@ -112,7 +103,12 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();
// 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)));