rtic/examples/zero-tasks.rs

46 lines
1.2 KiB
Rust
Raw Permalink Normal View History

//! Minimal example with zero tasks
#![deny(unsafe_code)]
#![deny(warnings)]
2017-07-28 05:40:47 +02:00
// IMPORTANT always include this feature gate
#![feature(proc_macro)]
#![no_std]
extern crate cortex_m_rtfm as rtfm; // IMPORTANT always do this rename
extern crate stm32f103xx; // the device crate
// import the procedural macro
use rtfm::app;
// This macro call indicates that this is a RTFM application
//
// This macro will expand to a `main` function so you don't need to supply
// `main` yourself.
app! {
2017-07-28 05:40:47 +02:00
// this is the path to the device crate
device: stm32f103xx,
}
// The initialization phase.
//
// This runs first and within a *global* critical section. Nothing can preempt
// this function.
fn init(p: init::Peripherals) {
// This function has access to all the peripherals of the device
2017-11-20 05:11:25 +01:00
p.core.SYST;
p.device.GPIOA;
p.device.RCC;
// ..
}
// The idle loop.
//
2017-07-28 05:40:47 +02:00
// This runs after `init` and has a priority of 0. All tasks can preempt this
// function. This function can never return so it must contain some sort of
// endless loop.
fn idle() -> ! {
loop {
// This puts the processor to sleep until there's a task to service
rtfm::wfi();
}
}