Specialized for RTIC

This commit is contained in:
Emil Fresk
2021-09-21 11:39:45 +02:00
parent 265b7f2878
commit 83262e5942
9 changed files with 75 additions and 109 deletions
+6 -5
View File
@@ -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`" }
# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
+7 -3
View File
@@ -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
-13
View File
@@ -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()
}
-26
View File
@@ -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<T> {
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()
}
-11
View File
@@ -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()
}
-15
View File
@@ -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()
}
+62
View File
@@ -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!");
}
}
-25
View File
@@ -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))
}
}
}
-11
View File
@@ -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!()
}