From b1467c62b4b4f61ce53b6572c30920a72550ea45 Mon Sep 17 00:00:00 2001 From: cschuhen <47763321+cschuhen@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:25:07 +1000 Subject: Add example of using Embassy HAL(stm32) with RTIC. (#891) The RTIC book mentions Embassy+RTIC but gives no examples. fmt. Add feature flag Seems CI does not deal with 2 levels of depth. Forgot to stage. Thumb m arch. Co-authored-by: Corey Schuhen --- examples/embassy-stm32g4/src/bin/blinky.rs | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/embassy-stm32g4/src/bin/blinky.rs (limited to 'examples/embassy-stm32g4/src/bin') diff --git a/examples/embassy-stm32g4/src/bin/blinky.rs b/examples/embassy-stm32g4/src/bin/blinky.rs new file mode 100644 index 0000000..9cc4899 --- /dev/null +++ b/examples/embassy-stm32g4/src/bin/blinky.rs @@ -0,0 +1,61 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] +#![feature(type_alias_impl_trait)] + +use defmt::*; +use embassy_stm32::gpio::{Level, Output, Speed}; +use rtic::app; +use rtic_monotonics::systick::*; +use {defmt_rtt as _, panic_probe as _}; + +pub mod pac { + pub use embassy_stm32::pac::Interrupt as interrupt; + pub use embassy_stm32::pac::*; +} + +#[app(device = pac, peripherals = false, dispatchers = [SPI1])] +mod app { + use super::*; + + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(cx: init::Context) -> (Shared, Local) { + // Initialize the systick interrupt & obtain the token to prove that we did + let systick_mono_token = rtic_monotonics::create_systick_token!(); + Systick::start(cx.core.SYST, 25_000_000, systick_mono_token); + + let p = embassy_stm32::init(Default::default()); + info!("Hello World!"); + + let mut led = Output::new(p.PC6, Level::High, Speed::Low); + info!("high"); + led.set_high(); + + // Schedule the blinking task + blink::spawn(led).ok(); + + (Shared {}, Local {}) + } + + #[task()] + async fn blink(_cx: blink::Context, mut led: Output<'static, embassy_stm32::peripherals::PC6>) { + let mut state = true; + loop { + info!("blink"); + if state { + led.set_high(); + } else { + led.set_low(); + } + state = !state; + Systick::delay(1000.millis()).await; + } + } +} -- cgit v1.2.3