Skip to content

Commit 190ea8e

Browse files
committed
examples: update rtfm example
Update RTFM to v5.5 and switch to its new name RTIC. Signed-off-by: Sergey Matyukevich <[email protected]>
1 parent 074f62f commit 190ea8e

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ version = "1.0.2"
4545
cortex-m-rt = "0.6.7"
4646
cortex-m-semihosting = "0.3.2"
4747
panic-semihosting = "0.5.1"
48-
cortex-m-rtfm = "0.4.2"
48+
cortex-m-rtic = "0.5.5"
4949

5050
[features]
5151
rt = ["stm32l1/rt"]

examples/rtfm.rs

+43-30
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ extern crate cortex_m;
66
extern crate cortex_m_rt as rt;
77
extern crate cortex_m_semihosting;
88
extern crate panic_semihosting;
9-
extern crate rtfm;
9+
extern crate rtic;
1010
extern crate stm32l1xx_hal as hal;
1111

1212
use cortex_m_semihosting::hprintln;
13-
use rtfm::app;
13+
use rtic::app;
1414

1515
use embedded_hal::digital::v2::OutputPin;
1616
use embedded_hal::digital::v2::ToggleableOutputPin;
@@ -22,50 +22,63 @@ use hal::rcc::Config;
2222
use hal::stm32;
2323
use hal::timer::Timer;
2424

25-
#[app(device = hal::stm32)]
25+
#[app(device = hal::stm32, peripherals = true)]
2626
const APP: () = {
27-
static mut DELTA: u32 = 0;
28-
static mut TIMER: Timer<stm32::TIM2> = ();
29-
static mut TICKS_LED: PB6<Output<PushPull>> = ();
30-
static mut BUSY_LED: PB7<Output<PushPull>> = ();
31-
static EXTI: stm32::EXTI = ();
27+
struct Resources {
28+
// resources
29+
#[init(0)]
30+
DELTA: u32,
31+
32+
// late resources
33+
TIMER: Timer<stm32::TIM2>,
34+
TICKS_LED: PB6<Output<PushPull>>,
35+
BUSY_LED: PB7<Output<PushPull>>,
36+
EXTI: stm32::EXTI,
37+
}
3238

3339
#[init]
34-
fn init() {
35-
let mut rcc = device.RCC.freeze(Config::hsi());
40+
fn init(cx: init::Context) -> init::LateResources {
41+
let mut rcc = cx.device.RCC.freeze(Config::hsi());
3642

37-
let gpiob = device.GPIOB.split();
38-
let mut timer = device.TIM2.timer(1.hz(), &mut rcc);
43+
let gpiob = cx.device.GPIOB.split();
44+
let mut timer = cx.device.TIM2.timer(1.hz(), &mut rcc);
3945

4046
timer.listen();
41-
device.EXTI.listen(0, TriggerEdge::Rising);
47+
cx.device.EXTI.listen(0, TriggerEdge::Rising);
48+
49+
let TICKS_LED = gpiob.pb6.into_push_pull_output();
50+
let BUSY_LED = gpiob.pb7.into_push_pull_output();
51+
let TIMER = timer;
52+
let EXTI = cx.device.EXTI;
4253

43-
TICKS_LED = gpiob.pb6.into_push_pull_output();
44-
BUSY_LED = gpiob.pb7.into_push_pull_output();
45-
TIMER = timer;
46-
EXTI = device.EXTI;
54+
init::LateResources {
55+
TIMER,
56+
TICKS_LED,
57+
BUSY_LED,
58+
EXTI,
59+
}
4760
}
4861

49-
#[interrupt(resources = [TIMER, TICKS_LED, DELTA])]
50-
fn TIM2() {
51-
*resources.DELTA += 1;
62+
#[task(binds = TIM2, resources = [TIMER, TICKS_LED, DELTA])]
63+
fn tim2_handler(cx: tim2_handler::Context) {
64+
*cx.resources.DELTA += 1;
5265

53-
resources.TICKS_LED.toggle().unwrap();
54-
resources.TIMER.clear_irq();
66+
cx.resources.TICKS_LED.toggle().unwrap();
67+
cx.resources.TIMER.clear_irq();
5568
}
5669

57-
#[interrupt(resources = [EXTI, BUSY_LED, DELTA])]
58-
fn EXTI0() {
59-
resources.BUSY_LED.set_high().unwrap();
60-
hprintln!("Δ: {}", resources.DELTA).unwrap();
61-
resources.BUSY_LED.set_low().unwrap();
70+
#[task(binds = EXTI0, resources = [EXTI, BUSY_LED, DELTA])]
71+
fn exti0_handler(cx: exti0_handler::Context) {
72+
cx.resources.BUSY_LED.set_high().unwrap();
73+
hprintln!("Δ: {}", cx.resources.DELTA).unwrap();
74+
cx.resources.BUSY_LED.set_low().unwrap();
6275

63-
*resources.DELTA = 0;
64-
resources.EXTI.clear_irq(0);
76+
*cx.resources.DELTA = 0;
77+
cx.resources.EXTI.clear_irq(0);
6578
}
6679

6780
#[idle]
68-
fn idle() -> ! {
81+
fn idle(_: idle::Context) -> ! {
6982
loop {}
7083
}
7184
};

0 commit comments

Comments
 (0)