diff --git a/examples/rtic_bare7.rs b/examples/rtic_bare7.rs index a4e80855ccacf942cb8b8ede91a37a8d9d2c5f65..5cf19410f289fd227659cfdfb5364c5b0591fbf1 100644 --- a/examples/rtic_bare7.rs +++ b/examples/rtic_bare7.rs @@ -8,6 +8,7 @@ #![no_main] #![no_std] + use panic_rtt_target as _; use rtic::cyccnt::{Instant, U32Ext as _}; use rtt_target::{rprintln, rtt_init_print}; @@ -26,15 +27,15 @@ const OFFSET: u32 = 8_000_000; const APP: () = { struct Resources { // late resources - GPIOA: stm32::GPIOA, + //GPIOA: stm32::GPIOA, led: PA5<Output<PushPull>>, - } #[init(schedule = [toggle])] fn init(cx: init::Context) -> init::LateResources { rtt_init_print!(); rprintln!("init"); + let mut core = cx.core; let device = cx.device; @@ -48,22 +49,24 @@ const APP: () = { let now = cx.start; // the start time of the system // Schedule `toggle` to run 8e6 cycles (clock cycles) in the future - cx.schedule.toggle(now + OFFSET.cycles()).unwrap(); + let number_of_toggles = 0; + cx.schedule.toggle(now + OFFSET.cycles(),number_of_toggles).unwrap(); // power on GPIOA, RM0368 6.3.11 device.RCC.ahb1enr.modify(|_, w| w.gpioaen().set_bit()); - // configure PA5 as output, 8.4.1 + // configure PA5 as output, RM0368 8.4.1 device.GPIOA.moder.modify(|_, w| w.moder5().bits(1)); + + let gpioa = device.GPIOA.split(); + // pass on late resources init::LateResources { - GPIOA: device.GPIOA, - led: , + //GPIOA: device.GPIOA, + led: gpioa.pa5.into_push_pull_output(), } } - - #[idle] fn idle(_cx: idle::Context) -> ! { rprintln!("idle"); @@ -73,18 +76,24 @@ const APP: () = { } #[task(resources = [led], schedule = [toggle])] - fn toggle(cx: toggle::Context) { + fn toggle(cx: toggle::Context, mut no_toggled: i32) { static mut TOGGLE: bool = false; rprintln!("toggle @ {:?}", Instant::now()); + rprintln!("times I have toggled {:?}", no_toggled); + no_toggled +=1; + /* if *TOGGLE { - cx.resources.GPIOA.bsrr.write(|w| w.bs5().set_bit()); + cx.resources.led.set_high(); } else { - cx.resources.GPIOA.bsrr.write(|w| w.br5().set_bit()); + cx.resources.led.set_low(); } + */ + + _toggleable_generic(cx.resources.led); - *TOGGLE = !*TOGGLE; - cx.schedule.toggle(cx.scheduled + OFFSET.cycles()).unwrap(); + //*TOGGLE = !*TOGGLE; + cx.schedule.toggle(cx.scheduled + OFFSET.cycles(),no_toggled).unwrap(); } extern "C" { @@ -243,4 +252,4 @@ fn _toggleable_generic<E>(led: &mut dyn ToggleableOutputPin<Error = E>) { // You might find Rust to have long compile times. Yes you are right, // and this type of deep analysis done in release mode is part of the story. // On the other hand, the aggressive optimization allows us to code -// in a generic high level fashion and still have excellent performing binaries. \ No newline at end of file +// in a generic high level fashion and still have excellent performing binaries.