From 83262e5942c8d308d782af0e91e39c36daf70327 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Fri, 20 Aug 2021 14:54:03 +0200 Subject: [PATCH] Specialized for RTIC --- Cargo.toml | 11 ++++---- README.md | 10 +++++--- src/bin/bitfield.rs | 13 ---------- src/bin/format.rs | 26 ------------------- src/bin/hello.rs | 11 -------- src/bin/levels.rs | 15 ----------- src/bin/minimal.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/overflow.rs | 25 ------------------ src/bin/panic.rs | 11 -------- 9 files changed, 75 insertions(+), 109 deletions(-) delete mode 100644 src/bin/bitfield.rs delete mode 100644 src/bin/format.rs delete mode 100644 src/bin/hello.rs delete mode 100644 src/bin/levels.rs create mode 100644 src/bin/minimal.rs delete mode 100644 src/bin/overflow.rs delete mode 100644 src/bin/panic.rs diff --git a/Cargo.toml b/Cargo.toml index fe68fa8..83221e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ cortex-m-rt = "0.6.13" defmt = "0.2.0" defmt-rtt = "0.2.0" panic-probe = { version = "0.2.0", features = ["print-defmt"] } +cortex-m-rtic = "0.6.0-alpha.5" # TODO(4) enter your HAL here # some-hal = "1.2.3" @@ -38,7 +39,7 @@ codegen-units = 1 debug = 2 debug-assertions = true # <- incremental = false -opt-level = 3 # <- +opt-level = "s" # <- overflow-checks = true # <- # cargo test @@ -47,7 +48,7 @@ codegen-units = 1 debug = 2 debug-assertions = true # <- incremental = false -opt-level = 3 # <- +opt-level = "s" # <- overflow-checks = true # <- # cargo build/run --release @@ -57,7 +58,7 @@ debug = 2 debug-assertions = false # <- incremental = false lto = 'fat' -opt-level = 3 # <- +opt-level = "s" # <- overflow-checks = false # <- # cargo test --release @@ -67,7 +68,7 @@ debug = 2 debug-assertions = false # <- incremental = false lto = 'fat' -opt-level = 3 # <- +opt-level = "s" # <- overflow-checks = false # <- # uncomment this to switch from the crates.io version of defmt to its git version @@ -76,4 +77,4 @@ overflow-checks = false # <- # defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" } # defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" } # defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" } -# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" } \ No newline at end of file +# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" } diff --git a/README.md b/README.md index 8dae452..ccefb77 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ # `app-template` > Quickly set up a [`probe-run`] + [`defmt`] + [`flip-link`] embedded project +> running on the [`RTIC`] scheduler [`probe-run`]: https://crates.io/crates/probe-run [`defmt`]: https://github.com/knurling-rs/defmt [`flip-link`]: https://github.com/knurling-rs/flip-link +[`RTIC`]: https://rtic.rs/ + +Based on https://github.com/knurling-rs/app-template ## Dependencies @@ -37,7 +41,7 @@ $ cargo install cargo-generate ``` console $ cargo generate \ - --git https://github.com/knurling-rs/app-template \ + --git https://github.com/rtic-rs/app-template \ --branch main \ --name my-app ``` @@ -122,7 +126,7 @@ Not all HALs provide a `memory.x` file, you may need to write it yourself. Check You are now all set to `cargo-run` your first `defmt`-powered application! There are some examples in the `src/bin` directory. -Start by `cargo run`-ning `my-app/src/bin/hello.rs`: +Start by `cargo run`-ning `my-app/src/bin/minimal.rs`: ``` console $ # `rb` is an alias for `run --bin` @@ -148,7 +152,7 @@ If you are using [rust-analyzer] with VS Code for IDE-like features you can add "Cargo.toml", "firmware/Cargo.toml", ] -} +} ``` [RA docs]: https://rust-analyzer.github.io/manual.html#configuration diff --git a/src/bin/bitfield.rs b/src/bin/bitfield.rs deleted file mode 100644 index d9889b1..0000000 --- a/src/bin/bitfield.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout - -#[cortex_m_rt::entry] -fn main() -> ! { - // value of the FREQUENCY register (nRF52840 device; RADIO peripheral) - let frequency: u32 = 276; - defmt::debug!("FREQUENCY: {0=0..7}, MAP: {0=8..9}", frequency); - - {{crate_name}}::exit() -} diff --git a/src/bin/format.rs b/src/bin/format.rs deleted file mode 100644 index 30476f6..0000000 --- a/src/bin/format.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout -use defmt::Format; // <- derive attribute - -#[derive(Format)] -struct S1 { - x: u8, - y: T, -} - -#[derive(Format)] -struct S2 { - z: u8, -} - -#[cortex_m_rt::entry] -fn main() -> ! { - let s = S1 { x: 42, y: S2 { z: 43 } }; - defmt::info!("s={:?}", s); - let x = 42; - defmt::info!("x={=u8}", x); - - {{crate_name}}::exit() -} diff --git a/src/bin/hello.rs b/src/bin/hello.rs deleted file mode 100644 index 4a39f24..0000000 --- a/src/bin/hello.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout - -#[cortex_m_rt::entry] -fn main() -> ! { - defmt::info!("Hello, world!"); - - {{crate_name}}::exit() -} diff --git a/src/bin/levels.rs b/src/bin/levels.rs deleted file mode 100644 index a944130..0000000 --- a/src/bin/levels.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout - -#[cortex_m_rt::entry] -fn main() -> ! { - defmt::info!("info"); - defmt::trace!("trace"); - defmt::warn!("warn"); - defmt::debug!("debug"); - defmt::error!("error"); - - {{crate_name}}::exit() -} diff --git a/src/bin/minimal.rs b/src/bin/minimal.rs new file mode 100644 index 0000000..e9988ee --- /dev/null +++ b/src/bin/minimal.rs @@ -0,0 +1,62 @@ +#![no_main] +#![no_std] + +use {{crate_name}} as _; // global logger + panicking-behavior + memory layout + +// TODO: Replace `some_hal::pac` with the path to the PAC +#[rtic::app(device = some_hal::pac)] +mod app { + // TODO: Add a monotonic if scheduling will be used + // #[monotonic(binds = SysTick, default = true)] + // type DwtMono = DwtSystick<80_000_000>; + + // Shared resources go here + #[shared] + struct Shared { + // TODO: Add resources + } + + // Local resources go here + #[local] + struct Local { + // TODO: Add resources + } + + #[init] + fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + defmt::info!("init"); + + task1::spawn().ok(); + + // Setup the monotonic timer + ( + Shared { + // Initialization of shared resources go here + }, + Local { + // Initialization of local resources go here + }, + init::Monotonics( + // Initialization of optional monotonic timers go here + ), + ) + } + + // Optional idle, can be removed if not needed. + // Note that removing this will put the MCU to sleep when no task is running, and this + // generally breaks RTT based printing. + #[idle] + fn idle(_: idle::Context) -> ! { + defmt::info!("idle"); + + loop { + continue; + } + } + + // TODO: Add tasks + #[task] + fn task1(_cx: task1::Context) { + defmt::info!("Hello from task1!"); + } +} diff --git a/src/bin/overflow.rs b/src/bin/overflow.rs deleted file mode 100644 index 4e85b95..0000000 --- a/src/bin/overflow.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout - -#[cortex_m_rt::entry] -fn main() -> ! { - ack(10, 10); - {{crate_name}}::exit() -} - -fn ack(m: u32, n: u32) -> u32 { - defmt::info!("ack(m={=u32}, n={=u32})", m, n); - let mut big = [2; 512]; - if m == 0 { - n + 1 - } else { - big[100] += 1; - if n == 0 { - ack(m - 1, 1) - } else { - ack(m - 1, ack(m, n - 1)) - } - } -} diff --git a/src/bin/panic.rs b/src/bin/panic.rs deleted file mode 100644 index de9298f..0000000 --- a/src/bin/panic.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout - -#[cortex_m_rt::entry] -fn main() -> ! { - defmt::info!("main"); - - defmt::panic!() -}