From 5a9135961f34505714e23f12e4cf4bacfa492dcd Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Fri, 14 Apr 2023 21:53:56 +0200 Subject: Split remove old examples --- examples/stm32f3_blinky/src/main.rs | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/stm32f3_blinky/src/main.rs (limited to 'examples/stm32f3_blinky/src') diff --git a/examples/stm32f3_blinky/src/main.rs b/examples/stm32f3_blinky/src/main.rs new file mode 100644 index 0000000..e208d09 --- /dev/null +++ b/examples/stm32f3_blinky/src/main.rs @@ -0,0 +1,74 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] +#![feature(type_alias_impl_trait)] + +use panic_rtt_target as _; +use rtic::app; +use rtic_monotonics::systick::*; +use rtt_target::{rprintln, rtt_init_print}; +use stm32f3xx_hal::gpio::{Output, PushPull, PA5}; +use stm32f3xx_hal::prelude::*; + +#[app(device = stm32f3xx_hal::pac, peripherals = true, dispatchers = [SPI1])] +mod app { + use super::*; + + rtic_monotonics::make_systick_handler!(); + + #[shared] + struct Shared {} + + #[local] + struct Local { + led: PA5>, + state: bool, + } + + #[init] + fn init(cx: init::Context) -> (Shared, Local) { + // Setup clocks + let mut flash = cx.device.FLASH.constrain(); + let mut rcc = cx.device.RCC.constrain(); + + Systick::start(cx.core.SYST, 36_000_000); // default STM32F303 clock-rate is 36MHz + + rtt_init_print!(); + rprintln!("init"); + + let _clocks = rcc + .cfgr + .use_hse(8.MHz()) + .sysclk(36.MHz()) + .pclk1(36.MHz()) + .freeze(&mut flash.acr); + + // Setup LED + let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb); + let mut led = gpioa + .pa5 + .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper); + led.set_high().unwrap(); + + // Schedule the blinking task + blink::spawn().ok(); + + (Shared {}, Local { led, state: false }) + } + + #[task(local = [led, state])] + async fn blink(cx: blink::Context) { + loop { + rprintln!("blink"); + if *cx.local.state { + cx.local.led.set_high().unwrap(); + *cx.local.state = false; + } else { + cx.local.led.set_low().unwrap(); + *cx.local.state = true; + } + Systick::delay(1000.millis()).await; + } + } +} -- cgit v1.2.3 From 0411ed10b19433a7ea969436afd4bc705ade538c Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Fri, 14 Apr 2023 22:05:31 +0200 Subject: stm32f3_blinky: update to latest version --- examples/stm32f3_blinky/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/stm32f3_blinky/src') diff --git a/examples/stm32f3_blinky/src/main.rs b/examples/stm32f3_blinky/src/main.rs index e208d09..b6da714 100644 --- a/examples/stm32f3_blinky/src/main.rs +++ b/examples/stm32f3_blinky/src/main.rs @@ -15,8 +15,6 @@ use stm32f3xx_hal::prelude::*; mod app { use super::*; - rtic_monotonics::make_systick_handler!(); - #[shared] struct Shared {} @@ -32,7 +30,9 @@ mod app { let mut flash = cx.device.FLASH.constrain(); let mut rcc = cx.device.RCC.constrain(); - Systick::start(cx.core.SYST, 36_000_000); // default STM32F303 clock-rate is 36MHz + // 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, 36_000_000, systick_mono_token); // default STM32F303 clock-rate is 36MHz rtt_init_print!(); rprintln!("init"); -- cgit v1.2.3