From 04606f40390ae7231d42e8ab34157a8e58408b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20=C3=96sterberg?= <carl.vilhelms.osterberg@gmail.com> Date: Wed, 10 Mar 2021 17:22:57 +0100 Subject: [PATCH] bare7_1 --- examples/rtic_bare6.rs | 1 + examples/rtic_bare7.rs | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/rtic_bare6.rs b/examples/rtic_bare6.rs index 255ff36..df5f9de 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 0f2dea1..8d31e38 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(); } -- GitLab