diff --git a/examples/rtfm-blinky.rs b/examples/rtfm-blinky.rs new file mode 100644 index 0000000000000000000000000000000000000000..87eacd1453a95d448a69520eedd7b1f7ba28b20d --- /dev/null +++ b/examples/rtfm-blinky.rs @@ -0,0 +1,60 @@ +#![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() + } +}