diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs new file mode 100644 index 00000000..d2531b2b --- /dev/null +++ b/examples/stm32h7/src/bin/signal.rs @@ -0,0 +1,41 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +// global logger +use defmt::{info, unwrap}; +use defmt_rtt as _; + +use panic_probe as _; + +use embassy::channel::Signal; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; + +use embassy_stm32::Peripherals; + +static SIGNAL: Signal = Signal::new(); + +#[embassy::task] +async fn my_sending_task() { + let mut counter: u32 = 0; + + loop { + Timer::after(Duration::from_secs(1)).await; + + SIGNAL.signal(counter); + + counter = counter.wrapping_add(1); + } +} + +#[embassy::main] +async fn main(spawner: Spawner, _p: Peripherals) { + unwrap!(spawner.spawn(my_sending_task())); + + loop { + let received_counter = SIGNAL.wait().await; + + info!("signalled, counter: {}", received_counter); + } +}