Skip to content
Snippets Groups Projects
Commit ef21c3d4 authored by Per Lindgren's avatar Per Lindgren
Browse files

rtfm-blinky systick

parent e5385e11
No related branches found
No related tags found
No related merge requests found
#![feature(proc_macro)]
#![deny(unsafe_code)]
// #![deny(warnings)]
#![no_std]
extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f4x_hal as hal;
use hal::gpio::gpioa::PA5;
use hal::gpio::{Output, PushPull};
use hal::prelude::*;
use hal::stm32f4x;
use hal::timer::{Event, Timer};
use rtfm::{app, Threshold};
app! {
device: stm32f4x,
resources: {
static LED: PA5<Output<PushPull>>;
},
tasks: {
SYS_TICK: {
path: sys_tick,
resources: [LED],
},
}
}
fn init(p: init::Peripherals) -> init::LateResources {
let mut flash = p.device.FLASH.constrain();
let mut rcc = p.device.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut gpioa = p.device.GPIOA.split(&mut rcc.ahb1);
let led = gpioa
.pa5
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
Timer::syst(p.core.SYST, 1.hz(), clocks).listen(Event::TimeOut);
init::LateResources { LED: led }
}
fn idle() -> ! {
loop {
rtfm::wfi();
}
}
fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) {
if r.LED.is_low() {
r.LED.set_high()
} else {
r.LED.set_low()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment