From b0b2355c7789f58a647e904936e90de15b531df5 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 10:22:28 +0200 Subject: [PATCH 1/9] Also fix this version... --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4022e31..b7dc81e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ rtic = { version = "2.0.0-alpha.1", features = [ "correct-rtic-backend" ] } # TODO enter your HAL here # some-hal = "1.2.3" # TODO add a monotonic if you use scheduling -# rtic-monotonics = { version = "2.0.0-alpha.1", features = [ "cortex-m-systick" ]} +# rtic-monotonics = { version = "1.0.0-alpha.2", features = [ "cortex-m-systick" ]} # cargo build/run [profile.dev] From 6d3fa4ebafb5781431303f142eb5f4cf1eadf09f Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 10:33:08 +0200 Subject: [PATCH 2/9] Improve docs here --- src/bin/minimal.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/minimal.rs b/src/bin/minimal.rs index 5420464..2bb00ca 100644 --- a/src/bin/minimal.rs +++ b/src/bin/minimal.rs @@ -26,8 +26,9 @@ mod app { defmt::info!("init"); // TODO setup monotonic if used - // let token = systick_monotonics::create_systick_token!(); - // rtic_monotonics::Systick::new(cx.core.SYST, sysclk, token); + // let sysclk = /* clock setup + returning sysclk */ + // let token = rtic_monotonics::create_systick_token!(); + // rtic_monotonics::systick::Systick::new(cx.core.SYST, sysclk, token); task1::spawn().ok(); From 3352f0cf87456c07c0e4e8646672aed8ed89a069 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 10:35:52 +0200 Subject: [PATCH 3/9] Switch back to defmt_rtt till brtt is fixed --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b7dc81e..f08a6e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ version = "0.1.0" [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"] } defmt = "0.3" -defmt-brtt = "0.1" +defmt-rtt = "0.4" panic-probe = { version = "0.3", features = ["print-defmt"] } # TODO select the correct rtic backend rtic = { version = "2.0.0-alpha.1", features = [ "correct-rtic-backend" ] } diff --git a/src/lib.rs b/src/lib.rs index ac69537..ab66632 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ #![no_std] use core::sync::atomic::{AtomicUsize, Ordering}; -use defmt_brtt as _; // global logger +use defmt_rtt as _; // global logger // TODO adjust HAL import // use some_hal as _; // memory layout From 5b2d65c29f10930f5f639eb5c92548fda59815c3 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 10:58:57 +0200 Subject: [PATCH 4/9] With a comment --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f08a6e0..74f566e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,9 @@ version = "0.1.0" cortex-m = { version = "0.7", features = ["critical-section-single-core"] } defmt = "0.3" defmt-rtt = "0.4" +# Use the logger below instead if you also want to use +# non-RTT transports. +# defmt-brtt = "0.1" panic-probe = { version = "0.3", features = ["print-defmt"] } # TODO select the correct rtic backend rtic = { version = "2.0.0-alpha.1", features = [ "correct-rtic-backend" ] } From b8d8591112c97b852c642769cddcc18819eaa386 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 11:00:18 +0200 Subject: [PATCH 5/9] Make this more descriptive --- src/bin/minimal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/minimal.rs b/src/bin/minimal.rs index 2bb00ca..364d2b0 100644 --- a/src/bin/minimal.rs +++ b/src/bin/minimal.rs @@ -26,7 +26,7 @@ mod app { defmt::info!("init"); // TODO setup monotonic if used - // let sysclk = /* clock setup + returning sysclk */ + // 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); From b969f75371ed5cdcb1afc66ff47a8697ae5b0b22 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 11:03:04 +0200 Subject: [PATCH 6/9] Actually just use defmt-brtt without default features --- Cargo.toml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 74f566e..b92b3d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,8 @@ version = "0.1.0" [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"] } -defmt = "0.3" -defmt-rtt = "0.4" -# Use the logger below instead if you also want to use -# non-RTT transports. -# defmt-brtt = "0.1" +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 rtic = { version = "2.0.0-alpha.1", features = [ "correct-rtic-backend" ] } From 59721a0da9b2a8803445546aedfdae8d71f19a71 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 11:23:21 +0200 Subject: [PATCH 7/9] Also re-rename this --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ab66632..ac69537 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ #![no_std] use core::sync::atomic::{AtomicUsize, Ordering}; -use defmt_rtt as _; // global logger +use defmt_brtt as _; // global logger // TODO adjust HAL import // use some_hal as _; // memory layout From 6f2fbf49b976085918d240b21e7b8b3999259f93 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 13:12:38 +0200 Subject: [PATCH 8/9] Ignore instead of exclude --- cargo-generate.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cargo-generate.toml b/cargo-generate.toml index 0c72b6c..1120324 100644 --- a/cargo-generate.toml +++ b/cargo-generate.toml @@ -1,2 +1,2 @@ [template] -exclude = ["README.md"] +ignore = ["README.md"] From 27d65b82e05cc6104caca9618adc14d882a08c10 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Mon, 1 May 2023 13:35:14 +0200 Subject: [PATCH 9/9] Add CI and fix the rest of the readme --- .cargo/config.toml | 3 ++- .github/workflows/build.yaml | 32 +++++++++++++++++++++++++++++++ .gitignore | 2 +- Cargo.toml | 4 ++-- README.md | 10 +++++----- cargo-generate.toml | 2 +- run-steps.sh | 37 ++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100755 run-steps.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index 24903bd..8c78999 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -14,7 +14,7 @@ rustflags = [ # 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 +22,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..505dfdb --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,32 @@ +name: Build +on: + pull_request: + push: + branches: + - master + +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: | + ./run-steps.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 b92b3d0..1453647 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,11 @@ version = "0.1.0" [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"] } -defmt = { version = "0.3", features = ["encoding-rzcobs"] +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 -rtic = { version = "2.0.0-alpha.1", features = [ "correct-rtic-backend" ] } +rtic = { version = "2.0.0-alpha.1", features = [ "$RTIC_BACKEND" ] } # TODO enter your HAL here # some-hal = "1.2.3" # TODO add a monotonic if you use scheduling diff --git a/README.md b/README.md index 2f27981..a460e18 100644 --- a/README.md +++ b/README.md @@ -54,14 +54,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 [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" ``` @@ -72,7 +72,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) @@ -87,11 +87,11 @@ $ 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 `correct-rtic-backend` with one of `thumbv6-backend`, `thumbv7-backend`, `thumbv8base-backend`, or `thumbv8main-backend`, depending on the target you are compiling for. +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-alhpa.1", features = [ "correct-rtic-backend" ] } +-rtic = { version = "2.0.0-alhpa.1", features = [ "$RTIC_BACKEND" ] } +rtic = { version = "2.0.0-alhpa.1", features = [ "thumbv7-backend" ] } ``` diff --git a/cargo-generate.toml b/cargo-generate.toml index 1120324..0cd15b6 100644 --- a/cargo-generate.toml +++ b/cargo-generate.toml @@ -1,2 +1,2 @@ [template] -ignore = ["README.md"] +ignore = ["README.md", "run-steps.sh"] diff --git a/run-steps.sh b/run-steps.sh new file mode 100755 index 0000000..32e79ab --- /dev/null +++ b/run-steps.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +set -ex + +project="test-app" + +echo "Installing necessary tools" +cargo install flip-link cargo-generate sd probe-run + +echo "Cleaning up old project" +rm -rf "$project" + +echo "Creating new project" +cargo generate -p . --name "$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" # Cortex-M4F and Cortex-M7F (with FPU)' '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 'some_hal::pac' 'nrf52840_hal::pac' src/bin/minimal.rs +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