diff --git a/.cargo/config.toml b/.cargo/config.toml index 24903bd..b637e96 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,16 +5,18 @@ rustflags = [ "-C", "linker=flip-link", "-C", "link-arg=-Tlink.x", "-C", "link-arg=-Tdefmt.x", + # "-C", "target-cpu=cortex-m7", # For Cortex M7 instructions/pipelining + # "-C", "target-feature=+fp64", # For Cortex M7 double precision FPU # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 - "-C", "link-arg=--nmagic", + # "-C", "link-arg=--nmagic", ] [build] # TODO(3) Adjust the compilation target. # (`thumbv6m-*` is compatible with all ARM Cortex-M chips but using the right # target improves performance) -target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ +# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ # target = "thumbv7m-none-eabi" # Cortex-M3 # target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) # target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) @@ -22,3 +24,4 @@ target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ [alias] rb = "run --bin" rrb = "run --release --bin" +bbr = "build --release --bin" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..570eefb --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,33 @@ +name: Build +on: + merge_group: + pull_request: + push: + branches: + - main + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: Build the project according to the steps + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install rust nightly + run: | + rustup override set nightly + + - name: Configure rust target + run: | + rustup target add thumbv7em-none-eabihf + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + + - name: Run steps + run: | + ./ci.sh diff --git a/.gitignore b/.gitignore index 96ef6c0..869df07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /target -Cargo.lock +Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 2e19b68..4738659 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,29 +1,20 @@ [package] -# TODO(1) fix `authors` and `name` if you didn't use `cargo-generate` -authors = ["{{authors}}"] -name = "{{project-name}}" +# TODO fix `authors` and `name` if you didn't use `cargo-generate` +name = "test-app" edition = "2021" version = "0.1.0" -[lib] -harness = false - -# needed for each integration test -[[test]] -name = "integration" -harness = false - [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"] } -cortex-m-rt = "0.7" -defmt = "0.3" -defmt-rtt = "0.4" +defmt = { version = "0.3", features = ["encoding-rzcobs"] } +defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] } panic-probe = { version = "0.3", features = ["print-defmt"] } -# TODO(4) enter your HAL here -# some-hal = "1.2.3" - -[dev-dependencies] -defmt-test = "0.3" +# TODO(4) Select the correct rtic backend +rtic = { version = "2.0.0", features = [ "$RTIC_BACKEND" ] } +# TODO(5) Add hal as dependency +some-hal = "1.2.3" +# TODO add a monotonic if you use scheduling +# rtic-monotonics = { version = "1.0.0", features = [ "cortex-m-systick" ]} # cargo build/run [profile.dev] @@ -31,8 +22,8 @@ codegen-units = 1 debug = 2 debug-assertions = true # <- incremental = false -opt-level = 'z' # <- -overflow-checks = true # <- +opt-level = "s" # <- +overflow-checks = true # <- # cargo test [profile.test] @@ -40,8 +31,8 @@ codegen-units = 1 debug = 2 debug-assertions = true # <- incremental = false -opt-level = 3 # <- -overflow-checks = true # <- +opt-level = "s" # <- +overflow-checks = true # <- # cargo build/run --release [profile.release] @@ -50,8 +41,8 @@ debug = 2 debug-assertions = false # <- incremental = false lto = 'fat' -opt-level = 3 # <- -overflow-checks = false # <- +opt-level = "s" # <- +overflow-checks = false # <- # cargo test --release [profile.bench] @@ -60,8 +51,8 @@ debug = 2 debug-assertions = false # <- incremental = false lto = 'fat' -opt-level = 3 # <- -overflow-checks = false # <- +opt-level = "s" # <- +overflow-checks = false # <- # uncomment this to switch from the crates.io version of defmt to its git version # check app-template's README for instructions diff --git a/README.md b/README.md index d96db64..ba7df73 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 @@ -21,28 +25,15 @@ $ # make sure to install v0.2.0 or later $ cargo install probe-run ``` -#### 3. [`cargo-generate`]: - -``` console -$ cargo install cargo-generate -``` - -[`cargo-generate`]: https://crates.io/crates/cargo-generate - -> *Note:* You can also just clone this repository instead of using `cargo-generate`, but this involves additional manual adjustments. - ## Setup -#### 1. Initialize the project template +#### 1. Clone the project template ``` console -$ cargo generate \ - --git https://github.com/knurling-rs/app-template \ - --branch main \ - --name my-app +$ git clone https://github.com/rtic-rs/app-template test-app ``` -If you look into your new `my-app` folder, you'll find that there are a few `TODO`s in the files marking the properties you need to set. +If you look into your new `test-app` folder, you'll find that there are a few `TODO`s in the files marking the properties you need to set. The todo's are formatted as `TODO(n)`, where `n` is the number of the step in which the TODO is explained. Let's walk through them together now. @@ -50,14 +41,14 @@ Let's walk through them together now. Pick a chip from `probe-run --list-chips` and enter it into `.cargo/config.toml`. -If, for example, you have a nRF52840 Development Kit from one of [our workshops], replace `{{chip}}` with `nRF52840_xxAA`. +If, for example, you have a nRF52840 Development Kit from one of [our workshops], replace `$CHIP` with `nRF52840_xxAA`. [our workshops]: https://github.com/ferrous-systems/embedded-trainings-2020 -``` diff - # .cargo/config.toml +```diff +# .cargo/config.toml [target.'cfg(all(target_arch = "arm", target_os = "none"))'] --runner = "probe-run --chip {{chip}}" +-runner = "probe-run --chip $CHIP" +runner = "probe-run --chip nRF52840_xxAA" ``` @@ -68,7 +59,7 @@ In `.cargo/config.toml`, pick the right compilation target for your board. ``` diff # .cargo/config.toml [build] --target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ +-# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ -# target = "thumbv7m-none-eabi" # Cortex-M3 -# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) -# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) @@ -78,10 +69,20 @@ In `.cargo/config.toml`, pick the right compilation target for your board. Add the target with `rustup`. ``` console -$ rustup target add thumbv7em-none-eabihf +$ rustup +nightly target add thumbv7em-none-eabihf +``` + +#### 4. Activate the correct `rtic` backend + +In `Cargo.toml`, activate the correct `rtic` backend for your target by replacing `$RTIC_BACKEND` with one of `thumbv6-backend`, `thumbv7-backend`, `thumbv8base-backend`, or `thumbv8main-backend`, depending on the target you are compiling for. + +```diff +# Cargo.toml +-rtic = { version = "2.0.0", features = [ "$RTIC_BACKEND" ] } ++rtic = { version = "2.0.0", features = [ "thumbv7-backend" ] } ``` -#### 4. Add a HAL as a dependency +#### 5. Add a HAL as a dependency In `Cargo.toml`, list the Hardware Abstraction Layer (HAL) for your board as a dependency. @@ -89,28 +90,45 @@ For the nRF52840 you'll want to use the [`nrf52840-hal`]. [`nrf52840-hal`]: https://crates.io/crates/nrf52840-hal -``` diff - # Cargo.toml +```diff +# Cargo.toml [dependencies] --# some-hal = "1.2.3" -+nrf52840-hal = "0.14.0" +-some-hal = "1.2.3" ++nrf52840-hal = "0.16.0" ``` ⚠️ Note for RP2040 users ⚠️ You will need to not just specify the `rp-hal` HAL, but a BSP (board support crate) which includes a second stage bootloader. Please find a list of available BSPs [here](https://github.com/rp-rs/rp-hal-boards#packages). -#### 5. Import your HAL +#### 6. Import your HAL Now that you have selected a HAL, fix the HAL import in `src/lib.rs` ``` diff - // my-app/src/lib.rs --// use some_hal as _; // memory layout +# my-app/src/lib.rs +-use some_hal as _; // memory layout +use nrf52840_hal as _; // memory layout ``` -#### (6. Get a linker script) +#### 7. Configure the `rtic::app` macro. + +In `src/bin/minimal.rs`, edit the `rtic::app` macro into a valid form. + +``` diff +# my-app/src/bin/minimal.rs +\#[rtic::app( +- // TODO: Replace `some_hal::pac` with the path to the PAC +- device = some_hal::pac, +- // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used +- // You can usually find the names of the interrupt vectors in the some_hal::pac::interrupt enum. +- dispatchers = [FreeInterrupt1, ...] ++ device = nrf52840_hal::pac, ++ dispatchers = [SWI0_EGU0] +)] +``` + +#### (8. Get a linker script) Some HAL crates require that you manually copy over a file called `memory.x` from the HAL to the root of your project. For nrf52840-hal, this is done automatically so no action is needed. For other HAL crates, you can get it from your local Cargo folder, the default location is under: @@ -121,16 +139,16 @@ Some HAL crates require that you manually copy over a file called `memory.x` fro Not all HALs provide a `memory.x` file, you may need to write it yourself. Check the documentation for the HAL you are using. -#### 7. Run! +#### 9. Run! 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` -$ cargo rb hello +$ DEFMT_LOG=trace cargo rb minimal Finished dev [optimized + debuginfo] target(s) in 0.03s flashing program .. DONE @@ -142,97 +160,15 @@ $ echo $? 0 ``` -If you're running out of memory (`flip-link` bails with an overflow error), you can decrease the size of the device memory buffer by setting the `DEFMT_RTT_BUFFER_SIZE` environment variable. The default value is 1024 bytes, and powers of two should be used for optimal performance: +If you're running out of memory (`flip-link` bails with an overflow error), you can decrease the size of the device memory buffer by setting the `DEFMT_BRTT_BUFFER_SIZE` environment variable. The default value is 1024 bytes, and powers of two should be used for optimal performance: ``` console -$ DEFMT_RTT_BUFFER_SIZE=64 cargo rb hello -``` - -#### (8. Set `rust-analyzer.linkedProjects`) - -If you are using [rust-analyzer] with VS Code for IDE-like features you can add following configuration to your `.vscode/settings.json` to make it work transparently across workspaces. Find the details of this option in the [RA docs]. - -```json -{ - "rust-analyzer.linkedProjects": [ - "Cargo.toml", - "firmware/Cargo.toml", - ] -} +$ DEFMT_BRTT_BUFFER_SIZE=64 cargo rb minimal ``` [RA docs]: https://rust-analyzer.github.io/manual.html#configuration [rust-analyzer]: https://rust-analyzer.github.io/ -## Running tests - -The template comes configured for running unit tests and integration tests on the target. - -Unit tests reside in the library crate and can test private API; the initial set of unit tests are in `src/lib.rs`. -`cargo test --lib` will run those unit tests. - -``` console -$ cargo test --lib -(1/1) running `it_works`... -└─ app::unit_tests::__defmt_test_entry @ src/lib.rs:33 -all tests passed! -└─ app::unit_tests::__defmt_test_entry @ src/lib.rs:28 -``` - -Integration tests reside in the `tests` directory; the initial set of integration tests are in `tests/integration.rs`. -`cargo test --test integration` will run those integration tests. -Note that the argument of the `--test` flag must match the name of the test file in the `tests` directory. - -``` console -$ cargo test --test integration -(1/1) running `it_works`... -└─ integration::tests::__defmt_test_entry @ tests/integration.rs:13 -all tests passed! -└─ integration::tests::__defmt_test_entry @ tests/integration.rs:8 -``` - -Note that to add a new test file to the `tests` directory you also need to add a new `[[test]]` section to `Cargo.toml`. - -## Trying out the git version of defmt - -This template is configured to use the latest crates.io release (the "stable" release) of the `defmt` framework. -To use the git version (the "development" version) of `defmt` follow these steps: - -1. Install the *git* version of `probe-run` - -``` console -$ cargo install --git https://github.com/knurling-rs/probe-run --branch main -``` - -2. Check which defmt version `probe-run` supports - -``` console -$ probe-run --version -0.2.0 (aa585f2 2021-02-22) -supported defmt version: 60c6447f8ecbc4ff023378ba6905bcd0de1e679f -``` - -In the example output, the supported version is `60c6447f8ecbc4ff023378ba6905bcd0de1e679f` - -3. Switch defmt dependencies to git: uncomment the last part of the root `Cargo.toml` and enter the hash reported by `probe-run --version`: - -``` diff --# [patch.crates-io] --# 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`" } -+[patch.crates-io] -+defmt = { git = "https://github.com/knurling-rs/defmt", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" } -+defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" } -+defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" } -+panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "60c6447f8ecbc4ff023378ba6905bcd0de1e679f" } -``` - -You are now using the git version of `defmt`! - -**NOTE** there may have been breaking changes between the crates.io version and the git version; you'll need to fix those in the source code. - ## Support `app-template` is part of the [Knurling] project, [Ferrous Systems]' effort at diff --git a/cargo-generate.toml b/cargo-generate.toml deleted file mode 100644 index 0c72b6c..0000000 --- a/cargo-generate.toml +++ /dev/null @@ -1,2 +0,0 @@ -[template] -exclude = ["README.md"] diff --git a/ci.sh b/ci.sh new file mode 100755 index 0000000..21dcd42 --- /dev/null +++ b/ci.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +set -e + +project="test-app" + +cleanup() { + echo "Cleaning up" + mv Cargo.toml.tmp Cargo.toml + mv .cargo/config.toml.tmp .cargo/config.toml +} + +if [ "$1" = "cleanup" ]; then + cleanup + exit 1 +fi + +echo "Installing necessary tools" +cargo install flip-link sd + +echo "Cleaning up old project" +rm -rf "$project" + +echo "Creating new project" +# cargo generate -p . --name "$project" +mkdir -p "$project" +cp -r Cargo.toml LICENSE-* src/ rust-toolchain.toml .cargo/ "$project" + +echo "Storing current config so that the child project will compile." +mv Cargo.toml Cargo.toml.tmp +mv .cargo/config.toml .cargo/config.toml.tmp + +cd "$project" + +echo "Performing steps" + +sd -s -- '--chip $CHIP' '--chip nRF52840_xxAA' .cargo/config.toml +sd -s '# target = "thumbv7em-none-eabihf"' 'target = "thumbv7em-none-eabihf"' .cargo/config.toml +sd -s '$RTIC_BACKEND' 'thumbv7-backend' Cargo.toml +sd -s 'some-hal = "1.2.3"' 'nrf52840-hal = "0.16.0"' Cargo.toml +sd -s 'use some_hal as _;' 'use nrf52840_hal as _;' src/lib.rs +sd -s 'some_hal::pac' 'nrf52840_hal::pac' src/bin/minimal.rs +sd -s 'FreeInterrupt1, ...' 'SWI0_EGU0' src/bin/minimal.rs + +cargo bbr minimal + +cd .. +cleanup \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..e5e52db --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] \ No newline at end of file diff --git a/src/bin/bitfield.rs b/src/bin/bitfield.rs deleted file mode 100644 index 1e41fcb..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::println!("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 08ef2fc..0000000 --- a/src/bin/format.rs +++ /dev/null @@ -1,29 +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::println!("s={:?}", s); - let x = 42; - defmt::println!("x={=u8}", x); - - {{crate_name}}::exit() -} diff --git a/src/bin/hello.rs b/src/bin/hello.rs deleted file mode 100644 index d67bae6..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::println!("Hello, world!"); - - {{crate_name}}::exit() -} diff --git a/src/bin/levels.rs b/src/bin/levels.rs deleted file mode 100644 index 612d2a4..0000000 --- a/src/bin/levels.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_main] -#![no_std] - -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout - -#[cortex_m_rt::entry] -fn main() -> ! { - // try setting the DEFMT_LOG environment variable - // e.g. `export DEFMT_LOG=info` or `DEFMT_LOG=trace cargo rb levels` - 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..ca09ad5 --- /dev/null +++ b/src/bin/minimal.rs @@ -0,0 +1,65 @@ +#![no_main] +#![no_std] +#![feature(type_alias_impl_trait)] + +use test_app as _; // global logger + panicking-behavior + memory layout + +// TODO(7) Configure the `rtic::app` macro +#[rtic::app( + // TODO: Replace `some_hal::pac` with the path to the PAC + device = some_hal::pac, + // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used + // You can usually find the names of the interrupt vectors in the some_hal::pac::interrupt enum. + dispatchers = [FreeInterrupt1, ...] +)] +mod app { + // 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) { + defmt::info!("init"); + + // TODO setup monotonic if used + // let sysclk = { /* clock setup + returning sysclk as an u32 */ }; + // let token = rtic_monotonics::create_systick_token!(); + // rtic_monotonics::systick::Systick::new(cx.core.SYST, sysclk, token); + + + task1::spawn().ok(); + + ( + Shared { + // Initialization of shared resources go here + }, + Local { + // Initialization of local resources go here + }, + ) + } + + // Optional idle, can be removed if not needed. + #[idle] + fn idle(_: idle::Context) -> ! { + defmt::info!("idle"); + + loop { + continue; + } + } + + // TODO: Add tasks + #[task(priority = 1)] + async 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 75ad68e..0000000 --- a/src/bin/overflow.rs +++ /dev/null @@ -1,28 +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 { - // waste stack space to trigger a stack overflow - let mut buffer = [0u8; 16 * 1024]; - // estimate of the Stack Pointer register - let sp = buffer.as_mut_ptr(); - defmt::println!("ack(m={=u32}, n={=u32}, SP={:x})", m, n, sp); - - if m == 0 { - n + 1 - } else { - 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 587fdc1..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::println!("main"); - - defmt::panic!() -} diff --git a/src/lib.rs b/src/lib.rs index 2aef086..1ee2910 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,14 @@ #![no_main] #![no_std] -use defmt_rtt as _; // global logger - -// TODO(5) adjust HAL import -// use some_hal as _; // memory layout +use core::sync::atomic::{AtomicUsize, Ordering}; +use defmt_brtt as _; // global logger use panic_probe as _; +// TODO(6) Import your HAL +use some_hal as _; // memory layout + // same panicking *behavior* as `panic-probe` but doesn't print a panic message // this prevents the panic message being printed *twice* when `defmt::panic` is invoked #[defmt::panic_handler] @@ -15,23 +16,17 @@ fn panic() -> ! { cortex_m::asm::udf() } +static COUNT: AtomicUsize = AtomicUsize::new(0); +defmt::timestamp!("{=usize}", { + // NOTE(no-CAS) `timestamps` runs with interrupts disabled + let n = COUNT.load(Ordering::Relaxed); + COUNT.store(n + 1, Ordering::Relaxed); + n +}); + /// Terminates the application and makes `probe-run` exit with exit-code = 0 pub fn exit() -> ! { loop { cortex_m::asm::bkpt(); } } - -// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used -// once within a crate. the module can be in any file but there can only be at most -// one `#[tests]` module in this library crate -#[cfg(test)] -#[defmt_test::tests] -mod unit_tests { - use defmt::assert; - - #[test] - fn it_works() { - assert!(true) - } -} diff --git a/tests/integration.rs b/tests/integration.rs deleted file mode 100644 index 149ab9c..0000000 --- a/tests/integration.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![no_std] -#![no_main] - -use {{crate_name}} as _; // memory layout + panic handler - -// See https://crates.io/crates/defmt-test/0.3.0 for more documentation (e.g. about the 'state' -// feature) -#[defmt_test::tests] -mod tests { - use defmt::assert; - - #[test] - fn it_works() { - assert!(true) - } -}