Skip to content

Commit 2090a28

Browse files
bors[bot]phoracektherealprof
authored
Merge #295
295: Add an RTIC example r=therealprof a=phoracek This example presents integration with RTIC [1]. Built for STM32F4 Discovery, toggles an onboard LED upon an interrupt fired by an onboard button. [1] https://rtic.rs/ Signed-off-by: Petr Horacek <[email protected]> Co-authored-by: Petr Horacek <[email protected]> Co-authored-by: Daniel Egger <[email protected]>
2 parents 96fb17c + ccc0661 commit 2090a28

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added an example of integration with RTIC.
13+
1014
### Changed
1115

1216
- Update the sdio driver to match the changes in the PAC

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ embedded-graphics = "0.6.2"
5151
usb-device = "0.2.5"
5252
usbd-serial = "0.1.0"
5353
micromath = "1.0.0"
54+
cortex-m-rtic = "0.5.6"
5455

5556
[features]
5657
device-selected = []
@@ -134,3 +135,7 @@ required-features = ["rt", "stm32f411"]
134135
[[example]]
135136
name = "can-send"
136137
required-features = ["can", "stm32f405"]
138+
139+
[[example]]
140+
name = "rtic"
141+
required-features = ["rt", "stm32f407"]

examples/rtic.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#![deny(unsafe_code)]
2+
#![deny(warnings)]
3+
#![no_std]
4+
#![no_main]
5+
6+
extern crate rtic;
7+
8+
use panic_halt as _;
9+
use rtic::app;
10+
use stm32f4xx_hal::{
11+
gpio::{gpioa::PA0, gpiod::PD12, Edge, Input, Output, PullDown, PushPull},
12+
prelude::*,
13+
};
14+
15+
#[app(device = stm32f4xx_hal::stm32, peripherals = true)]
16+
const APP: () = {
17+
struct Resources {
18+
button: PA0<Input<PullDown>>,
19+
led: PD12<Output<PushPull>>,
20+
}
21+
22+
#[init]
23+
fn init(mut ctx: init::Context) -> init::LateResources {
24+
let mut syscfg = ctx.device.SYSCFG.constrain();
25+
26+
let gpiod = ctx.device.GPIOD.split();
27+
let led = gpiod.pd12.into_push_pull_output();
28+
29+
let gpioa = ctx.device.GPIOA.split();
30+
let mut button = gpioa.pa0.into_pull_down_input();
31+
button.make_interrupt_source(&mut syscfg);
32+
button.enable_interrupt(&mut ctx.device.EXTI);
33+
button.trigger_on_edge(&mut ctx.device.EXTI, Edge::RISING);
34+
35+
init::LateResources { button, led }
36+
}
37+
38+
#[task(binds = EXTI0, resources = [button, led])]
39+
fn button_click(ctx: button_click::Context) {
40+
ctx.resources.button.clear_interrupt_pending_bit();
41+
ctx.resources.led.toggle().unwrap();
42+
}
43+
};

0 commit comments

Comments
 (0)