Skip to content
Snippets Groups Projects
Commit c8a9e969 authored by Jonas Jacobsson's avatar Jonas Jacobsson Committed by Tommy Andersson
Browse files

Update rtic_bare7.rs

parent eee0d25d
Branches
No related tags found
No related merge requests found
......@@ -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" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment