Skip to content

Commit 258758d

Browse files
committed
update rtic examples
1 parent 1a2fbea commit 258758d

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

.cargo/config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[target.thumbv6m-none-eabi]
2-
# runner = "probe-run --chip STM32G071RBT"
3-
runner = "arm-none-eabi-gdb -q"
2+
runner = "probe-rs run --chip STM32G071GBUx"
3+
# runner = "arm-none-eabi-gdb -q"
44

55
rustflags = [
66
"-C", "linker=arm-none-eabi-ld",
7+
"-C", "link-arg=-Tdefmt.x",
78
"-C", "link-arg=-Tlink.x"
89
]
910

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fugit = "0.3.7"
2222
embedded-hal = "1.0.0"
2323
bare-metal = "1.0.0"
2424

25+
2526
[dependencies.stm32g0]
2627
package = "stm32g0-staging"
2728
version = "0.16.0"
@@ -32,10 +33,14 @@ version = "1.0.2"
3233

3334
[dev-dependencies]
3435
cortex-m-rt = "0.7.5"
35-
cortex-m-rtic = "1.1.4"
3636
cortex-m-semihosting = "0.5.0"
37+
defmt = "0.3.8"
38+
defmt-rtt = "0.4.0"
3739
panic-halt = "1.0.0"
3840
panic-semihosting = "0.6.0"
41+
portable-atomic = {version = "1.7.0", features = ["critical-section"]}
42+
rtic = { version = "2.1.1", features = ["thumbv6-backend"] }
43+
panic-probe = "0.3.2"
3944

4045
[features]
4146
default = ["i2c-blocking"]

examples/rtic.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
#![no_main]
33
#![deny(warnings)]
44

5-
extern crate cortex_m;
6-
extern crate cortex_m_rt as rt;
7-
extern crate panic_semihosting;
8-
extern crate rtic;
5+
extern crate panic_probe;
96
extern crate stm32g0xx_hal as hal;
107

11-
use cortex_m_semihosting::hprintln;
8+
use defmt_rtt as _;
129
use hal::exti::Event;
1310
use hal::gpio::*;
1411
use hal::prelude::*;
@@ -28,22 +25,21 @@ mod app {
2825
struct Local {
2926
exti: stm32::EXTI,
3027
timer: Timer<stm32::TIM17>,
31-
led: PA5<Output<PushPull>>,
28+
led: PA15<Output<PushPull>>,
3229
rtc: Rtc,
3330
}
3431

3532
#[init]
36-
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
33+
fn init(ctx: init::Context) -> (Shared, Local) {
3734
let mut rcc = ctx.device.RCC.constrain();
3835
let gpioa = ctx.device.GPIOA.split(&mut rcc);
39-
let gpioc = ctx.device.GPIOC.split(&mut rcc);
4036

4137
let mut timer = ctx.device.TIM17.timer(&mut rcc);
4238
timer.start(Hertz::Hz(3).into_duration());
4339
timer.listen();
4440

4541
let mut exti = ctx.device.EXTI;
46-
gpioc.pc13.listen(SignalEdge::Falling, &mut exti);
42+
gpioa.pa2.into_pull_up_input().listen(SignalEdge::Falling, &mut exti);
4743

4844
let mut rtc = ctx.device.RTC.constrain(&mut rcc);
4945
rtc.set_date(&Date::new(2019.year(), 11.month(), 24.day()));
@@ -55,9 +51,8 @@ mod app {
5551
timer,
5652
rtc,
5753
exti,
58-
led: gpioa.pa5.into_push_pull_output(),
54+
led: gpioa.pa15.into_push_pull_output(),
5955
},
60-
init::Monotonics(),
6156
)
6257
}
6358

@@ -67,18 +62,15 @@ mod app {
6762
ctx.local.timer.clear_irq();
6863
}
6964

70-
#[task(binds = EXTI4_15, local = [exti, rtc])]
65+
#[task(binds = EXTI2_3, local = [exti, rtc])]
7166
fn button_click(ctx: button_click::Context) {
7267
let date = ctx.local.rtc.get_date();
7368
let time = ctx.local.rtc.get_time();
74-
hprintln!("Button pressed @ {:?} {:?}", date, time);
75-
ctx.local.exti.unpend(Event::GPIO13);
76-
}
77-
78-
#[idle]
79-
fn idle(_: idle::Context) -> ! {
80-
loop {
81-
cortex_m::asm::wfi();
82-
}
69+
defmt::info!(
70+
"Button pressed @ {:?} {:?}",
71+
defmt::Debug2Format(&date),
72+
defmt::Debug2Format(&time)
73+
);
74+
ctx.local.exti.unpend(Event::GPIO2);
8375
}
8476
}

examples/rtic_low_power.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
#![no_main]
33
#![deny(warnings)]
44

5-
extern crate cortex_m;
6-
extern crate cortex_m_rt as rt;
7-
extern crate panic_semihosting;
5+
extern crate panic_probe;
86
extern crate rtic;
97
extern crate stm32g0xx_hal as hal;
108

9+
use defmt_rtt as _;
1110
use hal::exti::Event;
1211
use hal::gpio::*;
1312
use hal::power::{LowPowerMode, PowerMode};
@@ -25,19 +24,17 @@ mod app {
2524
#[local]
2625
struct Local {
2726
exti: stm32::EXTI,
28-
led: PA5<Output<PushPull>>,
27+
led: PA15<Output<PushPull>>,
2928
}
3029

3130
#[init]
32-
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
31+
fn init(ctx: init::Context) -> (Shared, Local) {
3332
let mut rcc = ctx.device.RCC.freeze(rcc::Config::hsi(Prescaler::Div16));
3433
let mut exti = ctx.device.EXTI;
3534

3635
let gpioa = ctx.device.GPIOA.split(&mut rcc);
37-
let gpioc = ctx.device.GPIOC.split(&mut rcc);
38-
39-
let led = gpioa.pa5.into_push_pull_output();
40-
let mut button = gpioc.pc13.listen(SignalEdge::Falling, &mut exti);
36+
let led = gpioa.pa15.into_push_pull_output();
37+
let mut button = gpioa.pa2.into_pull_up_input().listen(SignalEdge::Falling, &mut exti);
4138

4239
let mut power = ctx.device.PWR.constrain(&mut rcc);
4340
power.set_mode(PowerMode::UltraLowPower(LowPowerMode::StopMode2));
@@ -47,13 +44,13 @@ mod app {
4744
scb.set_sleepdeep();
4845
}
4946

50-
(Shared {}, Local { exti, led }, init::Monotonics())
47+
(Shared {}, Local { exti, led })
5148
}
5249

53-
#[task(binds = EXTI4_15, local = [exti, led])]
50+
#[task(binds = EXTI2, local = [exti, led])]
5451
fn button_click(ctx: button_click::Context) {
5552
ctx.local.led.toggle().unwrap();
56-
ctx.local.exti.unpend(Event::GPIO13);
53+
ctx.local.exti.unpend(Event::GPIO2);
5754
}
5855

5956
#[idle]

0 commit comments

Comments
 (0)