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

rtfm-examples

parent 3b9d4134
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ fn init(p: init::Peripherals) -> init::LateResources {
fn idle() -> ! {
loop {
rtfm::wfi();
// rtfm::wfi();
}
}
......
#![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::stm32f4x::{self, TIM2}; // <- TIM2 multiple defined
use hal::timer::{Event, Timer};
use rtfm::{app, Threshold};
app! {
device: stm32f4x,
resources: {
static GREEN_LED: PA5<Output<PushPull>>;
// TIM2 appears both as an interrupt identifier and a register block.
// Both cannot be in scope at the same time.
// Give a qualified path to the register block.
static TIMER: Timer<stm32f4x::TIM2>;
},
tasks: {
TIM2: {
path: tim2,
resources: [GREEN_LED, TIMER],
},
}
}
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);
let mut timer = Timer::tim2(p.device.TIM2, 1.hz(), clocks, &mut rcc.apb1);
timer.listen(Event::TimeOut);
init::LateResources {
GREEN_LED: led,
TIMER: timer,
}
}
fn idle() -> ! {
loop {
//rtfm::wfi();
}
}
fn tim2(_t: &mut Threshold, mut r: TIM2::Resources) {
r.TIMER.wait().unwrap(); // to clear the interrupt
if r.GREEN_LED.is_low() {
r.GREEN_LED.set_high()
} else {
r.GREEN_LED.set_low()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment