Skip to content

Commit 2f8b2f8

Browse files
authored
Merge pull request #727 from stm32-rs/rtic2
RTICv2
2 parents 2b74dd8 + 079d3a3 commit 2f8b2f8

File tree

7 files changed

+95
-22
lines changed

7 files changed

+95
-22
lines changed

.github/workflows/ci.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ jobs:
4040
- stm32f479
4141
rust:
4242
- stable
43+
features:
44+
- usb_fs,sdio-host,can,i2s,fsmc_lcd,rtic1
4345
include:
4446
- rust: nightly
4547
mcu: stm32f479
4648
experimental: true
49+
features: usb_fs,sdio-host,can,i2s,fsmc_lcd,rtic2
4750

4851
steps:
4952
- uses: actions/checkout@v4
@@ -55,9 +58,9 @@ jobs:
5558
- name: Cache Dependencies
5659
uses: Swatinem/rust-cache@v2
5760
with:
58-
key: v0.18.0-${{ matrix.mcu }}
61+
key: v0.19.0-${{ matrix.mcu }}
5962

6063
- uses: actions-rs/cargo@v1
6164
with:
6265
command: check
63-
args: --features=${{ matrix.mcu }},usb_fs,sdio-host,can,i2s,fsmc_lcd,rtic --examples
66+
args: --features=${{ matrix.mcu }},${{ matrix.features }} --examples

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- bump embedded-hal to `1.0` (no more RC!)
1414
- make `embedded-hal` `1.0` main implementation
1515
- add `embedded-hal-nb::serial`
16+
- rename `rtic` feature to `rtic1`, add `rtic2`
1617

1718
## [v0.19.0] - 2023-12-11
1819

Cargo.toml

+29-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repository = "https://github.com/stm32-rs/stm32f4xx-hal"
2323
version = "0.19.0"
2424

2525
[package.metadata.docs.rs]
26-
features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd", "rtic", "defmt"]
26+
features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd", "rtic1", "defmt"]
2727
targets = ["thumbv7em-none-eabihf"]
2828

2929
[dependencies]
@@ -42,8 +42,15 @@ void = { default-features = false, version = "1.0.2" }
4242
display-interface = { version = "0.4.1", optional = true }
4343
fugit = "0.3.7"
4444
fugit-timer = "0.1.3"
45+
# rtic1
4546
rtic-monotonic = { version = "1.0", optional = true }
4647
systick-monotonic = { version = "1.0", optional = true }
48+
cortex-m-rtic = { version = "1.1.4", features = ["test-critical-section"], optional = true }
49+
# rtic2
50+
rtic-time = { version = "1.3", optional = true }
51+
rtic-monotonics = { version = "1.5", features = ["cortex-m-systick"], optional = true }
52+
rtic = { version = "2.0.1", features = ["thumbv7-backend"], optional = true }
53+
4754
enumflags2 = "0.7.8"
4855
embedded-storage = "0.3"
4956
vcell = "0.1.3"
@@ -81,7 +88,6 @@ embedded-graphics = "0.7.1"
8188
usb-device = "0.3.1"
8289
usbd-serial = "0.2.0"
8390
micromath = "2"
84-
cortex-m-rtic = { version = "1.1.4", features = ["test-critical-section"] }
8591
dwt-systick-monotonic = "1.1"
8692
st7789 = "0.7.0"
8793
rtt-target = { version = "0.4.0" }
@@ -259,8 +265,13 @@ gpio-f469 = [
259265
"usart3", "uart4", "uart5", "uart7", "uart8",
260266
]
261267

262-
## Support monotonic timers that can be used by [RTIC framework](https://crates.io/crates/cortex-m-rtic)
263-
rtic = ["dep:rtic-monotonic", "dep:systick-monotonic"]
268+
## Support monotonic timers and other stuff that can be used by [RTICv1 framework](https://crates.io/crates/cortex-m-rtic)
269+
rtic1 = ["dep:rtic-monotonic", "dep:systick-monotonic", "cortex-m-rtic"]
270+
271+
## Support monotonic timers and other stuff that can be used by [RTICv2 framework](https://crates.io/crates/rtic)
272+
##
273+
## Requires nightly rust compiler
274+
rtic2 = ["dep:rtic-time", "dep:rtic-monotonics", "dep:rtic"]
264275

265276
## Implementation of `defmt::Format` for public enums and structures. See [defmt](https://crates.io/crates/defmt)
266277
defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3"]
@@ -438,43 +449,47 @@ required-features = ["stm32f411"]
438449

439450
[[example]]
440451
name = "rtic-adc-dma"
441-
required-features = ["rtic"] # stm32f401
452+
required-features = ["rtic1"] # stm32f401
442453

443454
[[example]]
444455
name = "rtic-button"
445-
required-features = ["stm32f411", "rtic"] # stm32f411
456+
required-features = ["stm32f411", "rtic1"] # stm32f411
446457

447458
[[example]]
448459
name = "rtic-i2s-audio-in-out"
449-
required-features = ["stm32f411", "i2s", "rtic"]
460+
required-features = ["stm32f411", "i2s", "rtic1"]
450461

451462
[[example]]
452463
name = "rtic-dual-i2s-audio-in-out"
453-
required-features = ["stm32f411", "i2s", "rtic"]
464+
required-features = ["stm32f411", "i2s", "rtic1"]
454465

455466
[[example]]
456467
name = "rtic-serial-dma-rx-idle"
457-
required-features = ["stm32f411", "rtic"]
468+
required-features = ["stm32f411", "rtic1"]
458469

459470
[[example]]
460471
name = "rtic-spi-slave-dma"
461-
required-features = ["stm32f411", "rtic"]
472+
required-features = ["stm32f411", "rtic1"]
462473

463474
[[example]]
464475
name = "rtic-tick"
465-
required-features = ["tim2", "rtic"]
476+
required-features = ["tim2", "rtic1"]
466477

467478
[[example]]
468479
name = "rtic-usart-shell"
469-
required-features = ["stm32f411", "rtic"] # stm32f411
480+
required-features = ["stm32f411", "rtic1"] # stm32f411
470481

471482
[[example]]
472483
name = "rtic-usart-shell-ssd1306"
473-
required-features = ["stm32f411", "rtic"] # stm32f411
484+
required-features = ["stm32f411", "rtic1"] # stm32f411
474485

475486
[[example]]
476487
name = "rtic-usb-cdc-echo"
477-
required-features = ["stm32f411", "rtic", "otg-fs", "usb_fs"] # stm32f411
488+
required-features = ["stm32f411", "rtic1", "otg-fs", "usb_fs"] # stm32f411
489+
490+
[[example]]
491+
name = "rtic2-systick"
492+
required-features = ["rtic2"]
478493

479494
[[example]]
480495
name = "sd"

examples/rtic2-systick.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#![no_main]
2+
#![no_std]
3+
#![feature(type_alias_impl_trait)]
4+
5+
use defmt_rtt as _;
6+
use panic_probe as _;
7+
use rtic::app;
8+
use rtic_monotonics::systick::*;
9+
use stm32f4xx_hal::{
10+
gpio::{Output, PC13},
11+
pac,
12+
prelude::*,
13+
};
14+
15+
#[app(device = pac, dispatchers = [USART1], peripherals = true)]
16+
mod app {
17+
use super::*;
18+
19+
#[shared]
20+
struct Shared {}
21+
22+
#[local]
23+
struct Local {
24+
led: PC13<Output>,
25+
}
26+
27+
#[init]
28+
fn init(ctx: init::Context) -> (Shared, Local) {
29+
let rcc = ctx.device.RCC.constrain();
30+
let freq = 48.MHz();
31+
let _clocks = rcc.cfgr.sysclk(freq).freeze();
32+
33+
// Initialize the systick interrupt & obtain the token to prove that we did
34+
let systick_mono_token = rtic_monotonics::create_systick_token!();
35+
Systick::start(ctx.core.SYST, freq.to_Hz(), systick_mono_token);
36+
37+
let gpioc = ctx.device.GPIOC.split();
38+
let led = gpioc.pc13.into_push_pull_output();
39+
defmt::info!("Start");
40+
41+
tick::spawn().ok();
42+
(Shared {}, Local { led })
43+
}
44+
45+
#[task(local = [led, count: u32 = 0])]
46+
async fn tick(ctx: tick::Context) {
47+
loop {
48+
ctx.local.led.toggle();
49+
*ctx.local.count += 1;
50+
defmt::info!("Tick {}", *ctx.local.count);
51+
Systick::delay(500.millis()).await;
52+
}
53+
}
54+
}

src/prelude.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ pub use crate::serial::TxListen as _stm32f4xx_hal_serial_TxListen;
7676
pub use crate::spi::SpiExt as _stm32f4xx_hal_spi_SpiExt;
7777
pub use crate::syscfg::SysCfgExt as _stm32f4xx_hal_syscfg_SysCfgExt;
7878
pub use crate::time::U32Ext as _stm32f4xx_hal_time_U32Ext;
79-
#[cfg(feature = "rtic")]
79+
#[cfg(feature = "rtic1")]
8080
pub use crate::timer::MonoTimer64Ext as _;
81-
#[cfg(feature = "rtic")]
81+
#[cfg(feature = "rtic1")]
8282
pub use crate::timer::MonoTimerExt as _;
8383
pub use crate::timer::PwmExt as _stm32f4xx_hal_timer_PwmExt;
84-
#[cfg(feature = "rtic")]
84+
#[cfg(feature = "rtic1")]
8585
pub use crate::timer::SysMonoTimerExt as _stm32f4xx_hal_timer_SysMonoTimerExt;
8686
pub use crate::timer::SysTimerExt as _stm32f4xx_hal_timer_SysCounterExt;
8787
pub use crate::timer::TimerExt as _stm32f4xx_hal_timer_TimerExt;

src/timer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub use pwm::*;
2626
pub mod pwm_input;
2727
#[cfg(not(feature = "gpio-f410"))]
2828
pub use pwm_input::PwmInput;
29-
#[cfg(feature = "rtic")]
29+
#[cfg(feature = "rtic1")]
3030
pub mod monotonic;
31-
#[cfg(feature = "rtic")]
31+
#[cfg(feature = "rtic1")]
3232
pub use monotonic::*;
3333

3434
mod hal_02;

tools/check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def main():
2828

2929
crate_info = cargo_meta["packages"][0]
3030

31-
features = ["{},usb_fs,can,i2s,fsmc_lcd,rtic,defmt".format(x)
31+
features = ["{},usb_fs,can,i2s,fsmc_lcd,rtic1,defmt".format(x)
3232
for x in crate_info["features"].keys()
3333
if x.startswith("stm32f4")]
3434

0 commit comments

Comments
 (0)