#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f103xx;
use cortex_m::peripheral::syst::SystClkSource;
use rtfm::{app, Threshold};
use stm32f103xx::GPIOC;
app! {
device: stm32f103xx,
resources: {
static ON: bool = false;
},
tasks: {
SYS_TICK: {
path: sys_tick,
resources: [ON],
},
}
}
fn init(mut p: init::Peripherals, r: init::Resources) {
r.ON;
p.device.RCC.apb2enr.modify(|_, w| w.iopcen().enabled());
p.device.GPIOC.bsrr.write(|w| w.bs13().set());
p.device
.GPIOC
.crh
.modify(|_, w| w.mode13().output().cnf13().push());
p.core.SYST.set_clock_source(SystClkSource::Core);
p.core.SYST.set_reload(8_000_000); p.core.SYST.enable_interrupt();
p.core.SYST.enable_counter();
}
fn idle() -> ! {
loop {
rtfm::wfi();
}
}
#[allow(unsafe_code)]
fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) {
*r.ON = !*r.ON;
if *r.ON {
unsafe {
(*GPIOC::ptr()).bsrr.write(|w| w.bs13().set());
}
} else {
unsafe {
(*GPIOC::ptr()).bsrr.write(|w| w.br13().reset());
}
}
}