diff --git a/examples/rtic_bare6.rs b/examples/rtic_bare6.rs index 255ff36543eba6a24d3004793164498294fc1643..df5f9deb53f89109ea89e205e599e836886342b5 100644 --- a/examples/rtic_bare6.rs +++ b/examples/rtic_bare6.rs @@ -203,6 +203,7 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) { // `rcc.cfgr.sysclk(64.mhz()).pclk1(64.mhz()).pclk2(64.mhz()).freeze()`; // // ** your answer here ** +// pclk1 has max frequency of 42 mhz. // // `rcc.cfgr.sysclk(84.mhz()).pclk1(42.mhz()).pclk2(64.mhz()).freeze();` // diff --git a/examples/rtic_bare7.rs b/examples/rtic_bare7.rs index 0f2dea18411d7e7c80325ad9cff46836177451f1..8d31e382550247afc64110a93ef7141ba39d4e86 100644 --- a/examples/rtic_bare7.rs +++ b/examples/rtic_bare7.rs @@ -11,23 +11,25 @@ use panic_rtt_target as _; use rtic::cyccnt::{Instant, U32Ext as _}; use rtt_target::{rprintln, rtt_init_print}; +use stm32f4::stm32f411::GPIOA; use stm32f4xx_hal::stm32; use stm32f4xx_hal::{ gpio::{gpioa::PA5, Output, PushPull}, prelude::*, }; -; + use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin}; const OFFSET: u32 = 8_000_000; #[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)] const APP: () = { + //We only need the led pin struct Resources { // late resources - GPIOA: stm32::GPIOA, - // led: PA5<Output<PushPull>>, + //GPIOA: stm32::GPIOA, + led: PA5<Output<PushPull>>, } #[init(schedule = [toggle])] fn init(cx: init::Context) -> init::LateResources { @@ -54,8 +56,10 @@ const APP: () = { device.GPIOA.moder.modify(|_, w| w.moder5().bits(1)); // pass on late resources + // Get the specific pin and make it a push pull output init::LateResources { - GPIOA: device.GPIOA, + //GPIOA: device.GPIOA, + led: device.GPIOA.split().pa5.into_push_pull_output(), } } @@ -67,16 +71,19 @@ const APP: () = { } } - #[task(resources = [GPIOA], schedule = [toggle])] + #[task(resources = [led], schedule = [toggle])] fn toggle(cx: toggle::Context) { static mut TOGGLE: bool = false; rprintln!("toggle @ {:?}", Instant::now()); + //use the set high/low for push pull output if *TOGGLE { - cx.resources.GPIOA.bsrr.write(|w| w.bs5().set_bit()); + cx.resources.led.set_high().ok(); + } else { - cx.resources.GPIOA.bsrr.write(|w| w.br5().set_bit()); + cx.resources.led.set_low().ok(); } + *TOGGLE = !*TOGGLE; cx.schedule.toggle(cx.scheduled + OFFSET.cycles()).unwrap(); @@ -97,6 +104,7 @@ fn _toggle_generic<E>(led: &mut dyn OutputPin<Error = E>, toggle: &mut bool) { *toggle = !*toggle; } + fn _toggleable_generic<E>(led: &mut dyn ToggleableOutputPin<Error = E>) { led.toggle().ok(); }