summaryrefslogtreecommitdiff
path: root/examples/stm32h7
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-08-22 15:51:44 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-08-22 16:11:40 +0200
commit478f4727846f6a43c28fff3b09cb639c0b800465 (patch)
treeb1b3f644b77c6fcf4a0bbe2eabe19caba27c4c08 /examples/stm32h7
parent1b9599025868d3a5d0d8e773593b05df8b2fecf2 (diff)
downloadembassy-478f4727846f6a43c28fff3b09cb639c0b800465.zip
Remove Forever, switch to static_cell.
Diffstat (limited to 'examples/stm32h7')
-rw-r--r--examples/stm32h7/Cargo.toml1
-rw-r--r--examples/stm32h7/src/bin/eth.rs14
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs14
-rw-r--r--examples/stm32h7/src/bin/spi.rs6
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs6
-rw-r--r--examples/stm32h7/src/bin/usart.rs6
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs6
7 files changed, 27 insertions, 26 deletions
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index a416796e..fc5f74f9 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -28,6 +28,7 @@ critical-section = "1.1"
micromath = "2.0.0"
stm32-fmc = "0.2.4"
embedded-storage = "0.3.0"
+static_cell = "1.0"
# cargo build/run
[profile.dev]
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 83210bcb..4ccc0b5e 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -13,16 +13,16 @@ use embassy_stm32::rng::Rng;
use embassy_stm32::time::mhz;
use embassy_stm32::{interrupt, Config};
use embassy_time::{Duration, Timer};
-use embassy_util::Forever;
use embedded_io::asynch::Write;
use rand_core::RngCore;
+use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
-macro_rules! forever {
+macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
- static FOREVER: Forever<T> = Forever::new();
- FOREVER.put_with(move || $val)
+ static STATIC_CELL: StaticCell<T> = StaticCell::new();
+ STATIC_CELL.init_with(move || $val)
}};
}
@@ -53,7 +53,7 @@ async fn main(spawner: Spawner) -> ! {
let device = unsafe {
Ethernet::new(
- forever!(State::new()),
+ singleton!(State::new()),
p.ETH,
eth_int,
p.PA1,
@@ -79,10 +79,10 @@ async fn main(spawner: Spawner) -> ! {
//});
// Init network stack
- let stack = &*forever!(Stack::new(
+ let stack = &*singleton!(Stack::new(
device,
config,
- forever!(StackResources::<1, 2, 8>::new()),
+ singleton!(StackResources::<1, 2, 8>::new()),
seed
));
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 99946f50..64fd8414 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -13,17 +13,17 @@ use embassy_stm32::rng::Rng;
use embassy_stm32::time::mhz;
use embassy_stm32::{interrupt, Config};
use embassy_time::{Duration, Timer};
-use embassy_util::Forever;
use embedded_io::asynch::Write;
use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect};
use rand_core::RngCore;
+use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
-macro_rules! forever {
+macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
- static FOREVER: Forever<T> = Forever::new();
- FOREVER.put_with(move || $val)
+ static STATIC_CELL: StaticCell<T> = StaticCell::new();
+ STATIC_CELL.init_with(move || $val)
}};
}
@@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! {
let device = unsafe {
Ethernet::new(
- forever!(State::new()),
+ singleton!(State::new()),
p.ETH,
eth_int,
p.PA1,
@@ -80,10 +80,10 @@ async fn main(spawner: Spawner) -> ! {
//});
// Init network stack
- let stack = &*forever!(Stack::new(
+ let stack = &*singleton!(Stack::new(
device,
config,
- forever!(StackResources::<1, 2, 8>::new()),
+ singleton!(StackResources::<1, 2, 8>::new()),
seed
));
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index c28f937a..1f407f00 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -12,8 +12,8 @@ use embassy_stm32::dma::NoDma;
use embassy_stm32::peripherals::SPI3;
use embassy_stm32::time::mhz;
use embassy_stm32::{spi, Config};
-use embassy_util::Forever;
use heapless::String;
+use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@@ -31,7 +31,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
}
}
-static EXECUTOR: Forever<Executor> = Forever::new();
+static EXECUTOR: StaticCell<Executor> = StaticCell::new();
#[entry]
fn main() -> ! {
@@ -54,7 +54,7 @@ fn main() -> ! {
spi::Config::default(),
);
- let executor = EXECUTOR.put(Executor::new());
+ let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task(spi)));
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 6c78c194..53004fc9 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -11,8 +11,8 @@ use embassy_executor::Executor;
use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
use embassy_stm32::time::mhz;
use embassy_stm32::{spi, Config};
-use embassy_util::Forever;
use heapless::String;
+use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@@ -27,7 +27,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) {
}
}
-static EXECUTOR: Forever<Executor> = Forever::new();
+static EXECUTOR: StaticCell<Executor> = StaticCell::new();
#[entry]
fn main() -> ! {
@@ -50,7 +50,7 @@ fn main() -> ! {
spi::Config::default(),
);
- let executor = EXECUTOR.put(Executor::new());
+ let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task(spi)));
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
index 1384d54c..87c2b125 100644
--- a/examples/stm32h7/src/bin/usart.rs
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -7,7 +7,7 @@ use defmt::*;
use embassy_executor::Executor;
use embassy_stm32::dma::NoDma;
use embassy_stm32::usart::{Config, Uart};
-use embassy_util::Forever;
+use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@@ -27,13 +27,13 @@ async fn main_task() {
}
}
-static EXECUTOR: Forever<Executor> = Forever::new();
+static EXECUTOR: StaticCell<Executor> = StaticCell::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
- let executor = EXECUTOR.put(Executor::new());
+ let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task()));
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index f8d58bb8..3adffcbe 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -9,8 +9,8 @@ use defmt::*;
use embassy_executor::Executor;
use embassy_stm32::dma::NoDma;
use embassy_stm32::usart::{Config, Uart};
-use embassy_util::Forever;
use heapless::String;
+use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::task]
@@ -30,13 +30,13 @@ async fn main_task() {
}
}
-static EXECUTOR: Forever<Executor> = Forever::new();
+static EXECUTOR: StaticCell<Executor> = StaticCell::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
- let executor = EXECUTOR.put(Executor::new());
+ let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
unwrap!(spawner.spawn(main_task()));