Skip to content
Snippets Groups Projects
Commit 04606f40 authored by Carl Österberg's avatar Carl Österberg
Browse files

bare7_1

parent ceb259fa
No related branches found
No related tags found
No related merge requests found
...@@ -203,6 +203,7 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) { ...@@ -203,6 +203,7 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
// `rcc.cfgr.sysclk(64.mhz()).pclk1(64.mhz()).pclk2(64.mhz()).freeze()`; // `rcc.cfgr.sysclk(64.mhz()).pclk1(64.mhz()).pclk2(64.mhz()).freeze()`;
// //
// ** your answer here ** // ** your answer here **
// pclk1 has max frequency of 42 mhz.
// //
// `rcc.cfgr.sysclk(84.mhz()).pclk1(42.mhz()).pclk2(64.mhz()).freeze();` // `rcc.cfgr.sysclk(84.mhz()).pclk1(42.mhz()).pclk2(64.mhz()).freeze();`
// //
......
...@@ -11,23 +11,25 @@ ...@@ -11,23 +11,25 @@
use panic_rtt_target as _; use panic_rtt_target as _;
use rtic::cyccnt::{Instant, U32Ext as _}; use rtic::cyccnt::{Instant, U32Ext as _};
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use stm32f4::stm32f411::GPIOA;
use stm32f4xx_hal::stm32; use stm32f4xx_hal::stm32;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
gpio::{gpioa::PA5, Output, PushPull}, gpio::{gpioa::PA5, Output, PushPull},
prelude::*, prelude::*,
}; };
;
use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin}; use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin};
const OFFSET: u32 = 8_000_000; const OFFSET: u32 = 8_000_000;
#[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)] #[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)]
const APP: () = { const APP: () = {
//We only need the led pin
struct Resources { struct Resources {
// late resources // late resources
GPIOA: stm32::GPIOA, //GPIOA: stm32::GPIOA,
// led: PA5<Output<PushPull>>, led: PA5<Output<PushPull>>,
} }
#[init(schedule = [toggle])] #[init(schedule = [toggle])]
fn init(cx: init::Context) -> init::LateResources { fn init(cx: init::Context) -> init::LateResources {
...@@ -54,8 +56,10 @@ const APP: () = { ...@@ -54,8 +56,10 @@ const APP: () = {
device.GPIOA.moder.modify(|_, w| w.moder5().bits(1)); device.GPIOA.moder.modify(|_, w| w.moder5().bits(1));
// pass on late resources // pass on late resources
// Get the specific pin and make it a push pull output
init::LateResources { init::LateResources {
GPIOA: device.GPIOA, //GPIOA: device.GPIOA,
led: device.GPIOA.split().pa5.into_push_pull_output(),
} }
} }
...@@ -67,17 +71,20 @@ const APP: () = { ...@@ -67,17 +71,20 @@ const APP: () = {
} }
} }
#[task(resources = [GPIOA], schedule = [toggle])] #[task(resources = [led], schedule = [toggle])]
fn toggle(cx: toggle::Context) { fn toggle(cx: toggle::Context) {
static mut TOGGLE: bool = false; static mut TOGGLE: bool = false;
rprintln!("toggle @ {:?}", Instant::now()); rprintln!("toggle @ {:?}", Instant::now());
//use the set high/low for push pull output
if *TOGGLE { if *TOGGLE {
cx.resources.GPIOA.bsrr.write(|w| w.bs5().set_bit()); cx.resources.led.set_high().ok();
} else { } else {
cx.resources.GPIOA.bsrr.write(|w| w.br5().set_bit()); cx.resources.led.set_low().ok();
} }
*TOGGLE = !*TOGGLE; *TOGGLE = !*TOGGLE;
cx.schedule.toggle(cx.scheduled + OFFSET.cycles()).unwrap(); 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) { ...@@ -97,6 +104,7 @@ fn _toggle_generic<E>(led: &mut dyn OutputPin<Error = E>, toggle: &mut bool) {
*toggle = !*toggle; *toggle = !*toggle;
} }
fn _toggleable_generic<E>(led: &mut dyn ToggleableOutputPin<Error = E>) { fn _toggleable_generic<E>(led: &mut dyn ToggleableOutputPin<Error = E>) {
led.toggle().ok(); led.toggle().ok();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment