Select Git revision
exception.rs
blinky.rs 1.06 KiB
//! Blinks an LED
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
extern crate f4;
extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
use cortex_m::peripheral::SystClkSource;
use f4::led::{self, LED};
use rtfm::{app, Threshold};
// CONFIGURATION
const FREQUENCY: u32 = 1; // Hz
// TASKS & RESOURCES
app! {
device: f4::stm32f40x,
resources: {
static ON: bool = false;
},
tasks: {
SYS_TICK: {
path: toggle,
resources: [ON],
},
},
}
// INITIALIZATION PHASE
fn init(p: init::Peripherals, _r: init::Resources) {
led::init(p.GPIOA, p.RCC);
p.SYST.set_clock_source(SystClkSource::Core);
p.SYST.set_reload(16_000_000 / FREQUENCY);
p.SYST.enable_interrupt();
p.SYST.enable_counter();
}
// IDLE LOOP
fn idle() -> ! {
// Sleep
loop {
rtfm::wfi();
}
}
// TASKS
// Toggle the state of the LED
fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) {
**r.ON = !**r.ON;
if **r.ON {
LED.on();
} else {
LED.off();
}
}