-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathrtic-tick.rs
49 lines (39 loc) · 1.07 KB
/
rtic-tick.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#![no_main]
#![no_std]
use panic_halt as _;
#[rtic::app(device = stm32f7xx_hal::pac, dispatchers = [USART1])]
mod app {
use stm32f7xx_hal::{
gpio::{Output, PC13},
pac,
prelude::*,
timer::MonoTimerUs,
};
#[shared]
struct Shared {}
#[local]
struct Local {
led: PC13<Output>,
}
#[monotonic(binds = TIM2, default = true)]
type MicrosecMono = MonoTimerUs<pac::TIM2>;
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
let rcc = ctx.device.RCC.constrain();
let clocks = rcc.cfgr.sysclk(48.MHz()).freeze();
let gpioc = ctx.device.GPIOC.split();
let led = gpioc.pc13.into_push_pull_output();
let mono = ctx.device.TIM2.monotonic_us(&clocks);
tick::spawn().ok();
(Shared {}, Local { led }, init::Monotonics(mono))
}
#[idle]
fn idle(_: idle::Context) -> ! {
loop {}
}
#[task(local = [led])]
fn tick(ctx: tick::Context) {
tick::spawn_after(1.secs()).ok();
ctx.local.led.toggle();
}
}