Skip to content

Commit b5bfb4f

Browse files
authored
Merge pull request #10 from geomatsi/update-examples
Update examples and add them into CI
2 parents 17fa193 + 8c84406 commit b5bfb4f

File tree

4 files changed

+56
-60
lines changed

4 files changed

+56
-60
lines changed

.travis.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
language: rust
22
rust:
3+
- stable
34
- beta
45
- nightly
56
cache: cargo
67
env:
8+
- MCU=stm32l100,rt
79
- MCU=stm32l100
10+
- MCU=stm32l151,rt
811
- MCU=stm32l151
12+
- MCU=stm32l152,rt
913
- MCU=stm32l152
14+
- MCU=stm32l162,rt
1015
- MCU=stm32l162
1116
matrix:
1217
allow_failures:
1318
- rust: nightly
1419
fast_finish: true
15-
script:
20+
install:
1621
- rustup target add thumbv7m-none-eabi
22+
script:
1723
- cargo build --features=$MCU
24+
- cargo build --features=$MCU --examples

Cargo.toml

+5-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"]
@@ -66,3 +66,7 @@ lto = true
6666
[[example]]
6767
name = "button_irq"
6868
required-features = ["rt"]
69+
70+
[[example]]
71+
name = "timer"
72+
required-features = ["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
};

examples/touch.rs

-28
This file was deleted.

0 commit comments

Comments
 (0)