From 079d3a3089c275c649885270c40f45f96e1a659e Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Fri, 12 Jan 2024 14:25:22 +0300 Subject: [PATCH] rtic2 --- .github/workflows/ci.yml | 7 +++-- CHANGELOG.md | 1 + Cargo.toml | 43 +++++++++++++++++++++---------- examples/rtic2-systick.rs | 54 +++++++++++++++++++++++++++++++++++++++ src/prelude.rs | 6 ++--- src/timer.rs | 4 +-- tools/check.py | 2 +- 7 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 examples/rtic2-systick.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ac621f0..02479d57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,10 +40,13 @@ jobs: - stm32f479 rust: - stable + features: + - usb_fs,sdio-host,can,i2s,fsmc_lcd,rtic1 include: - rust: nightly mcu: stm32f479 experimental: true + features: usb_fs,sdio-host,can,i2s,fsmc_lcd,rtic2 steps: - uses: actions/checkout@v4 @@ -55,9 +58,9 @@ jobs: - name: Cache Dependencies uses: Swatinem/rust-cache@v2 with: - key: v0.18.0-${{ matrix.mcu }} + key: v0.19.0-${{ matrix.mcu }} - uses: actions-rs/cargo@v1 with: command: check - args: --features=${{ matrix.mcu }},usb_fs,sdio-host,can,i2s,fsmc_lcd,rtic --examples + args: --features=${{ matrix.mcu }},${{ matrix.features }} --examples diff --git a/CHANGELOG.md b/CHANGELOG.md index f769109c..eccf315f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - bump embedded-hal to `1.0` (no more RC!) - make `embedded-hal` `1.0` main implementation - add `embedded-hal-nb::serial` +- rename `rtic` feature to `rtic1`, add `rtic2` ## [v0.19.0] - 2023-12-11 diff --git a/Cargo.toml b/Cargo.toml index 5225fea1..4cf9e72a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ repository = "https://github.com/stm32-rs/stm32f4xx-hal" version = "0.19.0" [package.metadata.docs.rs] -features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd", "rtic", "defmt"] +features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd", "rtic1", "defmt"] targets = ["thumbv7em-none-eabihf"] [dependencies] @@ -42,8 +42,15 @@ void = { default-features = false, version = "1.0.2" } display-interface = { version = "0.4.1", optional = true } fugit = "0.3.7" fugit-timer = "0.1.3" +# rtic1 rtic-monotonic = { version = "1.0", optional = true } systick-monotonic = { version = "1.0", optional = true } +cortex-m-rtic = { version = "1.1.4", features = ["test-critical-section"], optional = true } +# rtic2 +rtic-time = { version = "1.3", optional = true } +rtic-monotonics = { version = "1.5", features = ["cortex-m-systick"], optional = true } +rtic = { version = "2.0.1", features = ["thumbv7-backend"], optional = true } + enumflags2 = "0.7.8" embedded-storage = "0.3" vcell = "0.1.3" @@ -81,7 +88,6 @@ embedded-graphics = "0.7.1" usb-device = "0.3.1" usbd-serial = "0.2.0" micromath = "2" -cortex-m-rtic = { version = "1.1.4", features = ["test-critical-section"] } dwt-systick-monotonic = "1.1" st7789 = "0.7.0" rtt-target = { version = "0.4.0" } @@ -259,8 +265,13 @@ gpio-f469 = [ "usart3", "uart4", "uart5", "uart7", "uart8", ] -## Support monotonic timers that can be used by [RTIC framework](https://crates.io/crates/cortex-m-rtic) -rtic = ["dep:rtic-monotonic", "dep:systick-monotonic"] +## Support monotonic timers and other stuff that can be used by [RTICv1 framework](https://crates.io/crates/cortex-m-rtic) +rtic1 = ["dep:rtic-monotonic", "dep:systick-monotonic", "cortex-m-rtic"] + +## Support monotonic timers and other stuff that can be used by [RTICv2 framework](https://crates.io/crates/rtic) +## +## Requires nightly rust compiler +rtic2 = ["dep:rtic-time", "dep:rtic-monotonics", "dep:rtic"] ## Implementation of `defmt::Format` for public enums and structures. See [defmt](https://crates.io/crates/defmt) defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3"] @@ -438,43 +449,47 @@ required-features = ["stm32f411"] [[example]] name = "rtic-adc-dma" -required-features = ["rtic"] # stm32f401 +required-features = ["rtic1"] # stm32f401 [[example]] name = "rtic-button" -required-features = ["stm32f411", "rtic"] # stm32f411 +required-features = ["stm32f411", "rtic1"] # stm32f411 [[example]] name = "rtic-i2s-audio-in-out" -required-features = ["stm32f411", "i2s", "rtic"] +required-features = ["stm32f411", "i2s", "rtic1"] [[example]] name = "rtic-dual-i2s-audio-in-out" -required-features = ["stm32f411", "i2s", "rtic"] +required-features = ["stm32f411", "i2s", "rtic1"] [[example]] name = "rtic-serial-dma-rx-idle" -required-features = ["stm32f411", "rtic"] +required-features = ["stm32f411", "rtic1"] [[example]] name = "rtic-spi-slave-dma" -required-features = ["stm32f411", "rtic"] +required-features = ["stm32f411", "rtic1"] [[example]] name = "rtic-tick" -required-features = ["tim2", "rtic"] +required-features = ["tim2", "rtic1"] [[example]] name = "rtic-usart-shell" -required-features = ["stm32f411", "rtic"] # stm32f411 +required-features = ["stm32f411", "rtic1"] # stm32f411 [[example]] name = "rtic-usart-shell-ssd1306" -required-features = ["stm32f411", "rtic"] # stm32f411 +required-features = ["stm32f411", "rtic1"] # stm32f411 [[example]] name = "rtic-usb-cdc-echo" -required-features = ["stm32f411", "rtic", "otg-fs", "usb_fs"] # stm32f411 +required-features = ["stm32f411", "rtic1", "otg-fs", "usb_fs"] # stm32f411 + +[[example]] +name = "rtic2-systick" +required-features = ["rtic2"] [[example]] name = "sd" diff --git a/examples/rtic2-systick.rs b/examples/rtic2-systick.rs new file mode 100644 index 00000000..ce095f9d --- /dev/null +++ b/examples/rtic2-systick.rs @@ -0,0 +1,54 @@ +#![no_main] +#![no_std] +#![feature(type_alias_impl_trait)] + +use defmt_rtt as _; +use panic_probe as _; +use rtic::app; +use rtic_monotonics::systick::*; +use stm32f4xx_hal::{ + gpio::{Output, PC13}, + pac, + prelude::*, +}; + +#[app(device = pac, dispatchers = [USART1], peripherals = true)] +mod app { + use super::*; + + #[shared] + struct Shared {} + + #[local] + struct Local { + led: PC13, + } + + #[init] + fn init(ctx: init::Context) -> (Shared, Local) { + let rcc = ctx.device.RCC.constrain(); + let freq = 48.MHz(); + let _clocks = rcc.cfgr.sysclk(freq).freeze(); + + // Initialize the systick interrupt & obtain the token to prove that we did + let systick_mono_token = rtic_monotonics::create_systick_token!(); + Systick::start(ctx.core.SYST, freq.to_Hz(), systick_mono_token); + + let gpioc = ctx.device.GPIOC.split(); + let led = gpioc.pc13.into_push_pull_output(); + defmt::info!("Start"); + + tick::spawn().ok(); + (Shared {}, Local { led }) + } + + #[task(local = [led, count: u32 = 0])] + async fn tick(ctx: tick::Context) { + loop { + ctx.local.led.toggle(); + *ctx.local.count += 1; + defmt::info!("Tick {}", *ctx.local.count); + Systick::delay(500.millis()).await; + } + } +} diff --git a/src/prelude.rs b/src/prelude.rs index 2fcbe47a..cb152915 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -76,12 +76,12 @@ pub use crate::serial::TxListen as _stm32f4xx_hal_serial_TxListen; pub use crate::spi::SpiExt as _stm32f4xx_hal_spi_SpiExt; pub use crate::syscfg::SysCfgExt as _stm32f4xx_hal_syscfg_SysCfgExt; pub use crate::time::U32Ext as _stm32f4xx_hal_time_U32Ext; -#[cfg(feature = "rtic")] +#[cfg(feature = "rtic1")] pub use crate::timer::MonoTimer64Ext as _; -#[cfg(feature = "rtic")] +#[cfg(feature = "rtic1")] pub use crate::timer::MonoTimerExt as _; pub use crate::timer::PwmExt as _stm32f4xx_hal_timer_PwmExt; -#[cfg(feature = "rtic")] +#[cfg(feature = "rtic1")] pub use crate::timer::SysMonoTimerExt as _stm32f4xx_hal_timer_SysMonoTimerExt; pub use crate::timer::SysTimerExt as _stm32f4xx_hal_timer_SysCounterExt; pub use crate::timer::TimerExt as _stm32f4xx_hal_timer_TimerExt; diff --git a/src/timer.rs b/src/timer.rs index 615f2867..5b1956d4 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -26,9 +26,9 @@ pub use pwm::*; pub mod pwm_input; #[cfg(not(feature = "gpio-f410"))] pub use pwm_input::PwmInput; -#[cfg(feature = "rtic")] +#[cfg(feature = "rtic1")] pub mod monotonic; -#[cfg(feature = "rtic")] +#[cfg(feature = "rtic1")] pub use monotonic::*; mod hal_02; diff --git a/tools/check.py b/tools/check.py index 7e45ea65..d5bf34bb 100755 --- a/tools/check.py +++ b/tools/check.py @@ -28,7 +28,7 @@ def main(): crate_info = cargo_meta["packages"][0] - features = ["{},usb_fs,can,i2s,fsmc_lcd,rtic,defmt".format(x) + features = ["{},usb_fs,can,i2s,fsmc_lcd,rtic1,defmt".format(x) for x in crate_info["features"].keys() if x.startswith("stm32f4")]