From 43a6abed5e6c01d8ae1c062f54313395a47f04b5 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 14:37:10 +0200 Subject: [PATCH 1/6] Remove unnecesarily heavy and practically unused cargo-generate --- Cargo.toml | 3 +-- README.md | 19 +++---------------- cargo-generate.toml | 2 -- run-steps.sh | 21 ++++++++++++++++----- src/bin/minimal.rs | 2 +- 5 files changed, 21 insertions(+), 26 deletions(-) delete mode 100644 cargo-generate.toml diff --git a/Cargo.toml b/Cargo.toml index 1453647..d813729 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] # TODO fix `authors` and `name` if you didn't use `cargo-generate` -authors = ["{{authors}}"] -name = "{{project-name}}" +name = "test-app" edition = "2021" version = "0.1.0" diff --git a/README.md b/README.md index a460e18..e70ef25 100644 --- a/README.md +++ b/README.md @@ -25,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/rtic-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. Let's walk through them together now. diff --git a/cargo-generate.toml b/cargo-generate.toml deleted file mode 100644 index 0cd15b6..0000000 --- a/cargo-generate.toml +++ /dev/null @@ -1,2 +0,0 @@ -[template] -ignore = ["README.md", "run-steps.sh"] diff --git a/run-steps.sh b/run-steps.sh index 1fd8ae7..7e077bf 100755 --- a/run-steps.sh +++ b/run-steps.sh @@ -4,14 +4,27 @@ set -ex 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 cargo-generate sd +cargo install flip-link sd echo "Cleaning up old project" rm -rf "$project" echo "Creating new project" -cargo generate -p . --name "$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 @@ -32,6 +45,4 @@ sd -s 'FreeInterrupt1, ...' 'SWI0_EGU0' src/bin/minimal.rs cargo bbr minimal cd .. -echo "Cleaning up" -mv Cargo.toml.tmp Cargo.toml -mv .cargo/config.toml.tmp .cargo/config.toml \ No newline at end of file +cleanup \ No newline at end of file diff --git a/src/bin/minimal.rs b/src/bin/minimal.rs index 364d2b0..6ca39b0 100644 --- a/src/bin/minimal.rs +++ b/src/bin/minimal.rs @@ -2,7 +2,7 @@ #![no_std] #![feature(type_alias_impl_trait)] -use {{crate_name}} as _; // global logger + panicking-behavior + memory layout +use test_app as _; // global logger + panicking-behavior + memory layout #[rtic::app( device = some_hal::pac, // TODO: Replace `some_hal::pac` with the path to the PAC From 30bbca68e8fc259d414f552b13bed9b29ae9222e Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 14:41:44 +0200 Subject: [PATCH 2/6] Clean up todo format and clarify usage of dispatchers --- Cargo.toml | 4 ++-- README.md | 13 ++++++++----- src/bin/minimal.rs | 8 ++++++-- src/lib.rs | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d813729..d3c6724 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,9 @@ cortex-m = { version = "0.7", features = ["critical-section-single-core"] } 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 select the correct rtic backend +# TODO(4) Select the correct rtic backend rtic = { version = "2.0.0-alpha.1", features = [ "$RTIC_BACKEND" ] } -# TODO enter your HAL here +# 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-alpha.2", features = [ "cortex-m-systick" ]} diff --git a/README.md b/README.md index e70ef25..dffff68 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ $ cargo install probe-run $ git clone https://github.com/rtic-rs/app-template test-app ``` -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. +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. @@ -78,8 +78,8 @@ In `Cargo.toml`, activate the correct `rtic` backend for your target by replacin ```diff # Cargo.toml --rtic = { version = "2.0.0-alhpa.1", features = [ "$RTIC_BACKEND" ] } -+rtic = { version = "2.0.0-alhpa.1", features = [ "thumbv7-backend" ] } +-rtic = { version = "2.0.0-alpha.1", features = [ "$RTIC_BACKEND" ] } ++rtic = { version = "2.0.0-alpha.1", features = [ "thumbv7-backend" ] } ``` #### 5. Add a HAL as a dependency @@ -117,8 +117,11 @@ In `src/bin/minimal.rs`, edit the `rtic::app` macro into a valid form. ``` diff \#[rtic::app( -- device = some_hal::pac, // TODO: Replace `some_hal::pac` with the path to the PAC -- dispatchers = [FreeInterrupt1, ...] // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used +- // 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] )] diff --git a/src/bin/minimal.rs b/src/bin/minimal.rs index 6ca39b0..0b9075f 100644 --- a/src/bin/minimal.rs +++ b/src/bin/minimal.rs @@ -4,9 +4,13 @@ use test_app as _; // global logger + panicking-behavior + memory layout +// TODO(7) Configure the `rtic::app` macro #[rtic::app( - device = some_hal::pac, // TODO: Replace `some_hal::pac` with the path to the PAC - dispatchers = [FreeInterrupt1, ...] // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used + // 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 diff --git a/src/lib.rs b/src/lib.rs index ac69537..a7e24e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use defmt_brtt as _; // global logger -// TODO adjust HAL import +// TODO(6) Import your HAL // use some_hal as _; // memory layout use panic_probe as _; From 28f71302918a8ab583884fdf56b464a087a04aec Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 14:44:51 +0200 Subject: [PATCH 3/6] Clean up the steps --- run-steps.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run-steps.sh b/run-steps.sh index 7e077bf..b9ca746 100755 --- a/run-steps.sh +++ b/run-steps.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -ex +set -e project="test-app" @@ -35,10 +35,10 @@ cd "$project" echo "Performing steps" sd -s -- '--chip $CHIP' '--chip nRF52840_xxAA' .cargo/config.toml -sd -s '# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)' 'target = "thumbv7em-none-eabihf"' .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 _; // memory layout' 'use nrf52840_hal as _;' src/lib.rs +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 From 39eaa23d3b4a5e3d3928e44dff9d610124641121 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 14:49:44 +0200 Subject: [PATCH 4/6] Clean up diffs and remove "running from git" steps --- README.md | 66 ++++++---------------------------------------------- run-steps.sh | 2 +- src/lib.rs | 5 ++-- 3 files changed, 11 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index dffff68..08f7120 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ If, for example, you have a nRF52840 Development Kit from one of [our workshops] [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 nRF52840_xxAA" @@ -90,8 +90,8 @@ 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.16.0" @@ -106,8 +106,8 @@ You will need to not just specify the `rp-hal` HAL, but a BSP (board support cra 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 ``` @@ -116,6 +116,7 @@ Now that you have selected a HAL, fix the HAL import in `src/lib.rs` 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, @@ -165,62 +166,9 @@ If you're running out of memory (`flip-link` bails with an overflow error), you $ DEFMT_BRTT_BUFFER_SIZE=64 cargo rb hello ``` -#### (10. 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", - ] -} -``` - [RA docs]: https://rust-analyzer.github.io/manual.html#configuration [rust-analyzer]: https://rust-analyzer.github.io/ -## 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/run-steps.sh b/run-steps.sh index b9ca746..8ba7e33 100755 --- a/run-steps.sh +++ b/run-steps.sh @@ -38,7 +38,7 @@ 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 '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 diff --git a/src/lib.rs b/src/lib.rs index a7e24e0..1ee2910 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,11 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use defmt_brtt as _; // global logger -// TODO(6) Import your HAL -// use some_hal as _; // memory layout 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] From fbead895bc11e1d264d1e42bde7962baa98e9bee Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 14:51:57 +0200 Subject: [PATCH 5/6] Rename run-steps.sh to ci.sh --- .github/workflows/build.yaml | 2 +- run-steps.sh => ci.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename run-steps.sh => ci.sh (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4521c5d..332bc71 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -29,4 +29,4 @@ jobs: - name: Run steps run: | - ./run-steps.sh + ./ci.sh diff --git a/run-steps.sh b/ci.sh similarity index 100% rename from run-steps.sh rename to ci.sh From 31c3b27ae81f6c0403edc2ab04b294c3dc557e7a Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 14:55:35 +0200 Subject: [PATCH 6/6] This shouldn't be commented out either --- Cargo.toml | 2 +- README.md | 2 +- ci.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3c6724..9ea878c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } # TODO(4) Select the correct rtic backend rtic = { version = "2.0.0-alpha.1", features = [ "$RTIC_BACKEND" ] } # TODO(5) Add hal as dependency -# some-hal = "1.2.3" +some-hal = "1.2.3" # TODO add a monotonic if you use scheduling # rtic-monotonics = { version = "1.0.0-alpha.2", features = [ "cortex-m-systick" ]} diff --git a/README.md b/README.md index 08f7120..3ac7602 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ For the nRF52840 you'll want to use the [`nrf52840-hal`]. ```diff # Cargo.toml [dependencies] --# some-hal = "1.2.3" +-some-hal = "1.2.3" +nrf52840-hal = "0.16.0" ``` diff --git a/ci.sh b/ci.sh index 8ba7e33..21dcd42 100755 --- a/ci.sh +++ b/ci.sh @@ -37,7 +37,7 @@ 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 '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