diff --git a/Cargo.toml b/Cargo.toml index b3b7132..4022e31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,22 +2,20 @@ # TODO fix `authors` and `name` if you didn't use `cargo-generate` authors = ["{{authors}}"] name = "{{project-name}}" -edition = "2018" +edition = "2021" version = "0.1.0" -[workspace] -members = ["testsuite"] - [dependencies] -defmt = "0.3.0" -defmt-rtt = "0.3.0" -panic-probe = { version = "0.3.0", features = ["print-defmt"] } -cortex-m-rtic = "1.1" -cortex-m = "0.7" +cortex-m = { version = "0.7", features = ["critical-section-single-core"] } +defmt = "0.3" +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" ] } # TODO enter your HAL here # some-hal = "1.2.3" # TODO add a monotonic if you use scheduling -# some-monotonic = "1.2.3" +# rtic-monotonics = { version = "2.0.0-alpha.1", features = [ "cortex-m-systick" ]} # cargo build/run [profile.dev] diff --git a/README.md b/README.md index ccefb77..c9e43ca 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,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. Add a HAL as a dependency +#### 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. + +```diff +# Cargo.toml +-rtic = { version = "2.0.0-alhpa.1", features = [ "correct-rtic-backend" ] } ++rtic = { version = "2.0.0-alhpa.1", features = [ "thumbv7-backend" ] } +``` + +#### 5. Add a HAL as a dependency In `Cargo.toml`, list the Hardware Abstraction Layer (HAL) for your board as a dependency. @@ -97,10 +107,14 @@ For the nRF52840 you'll want to use the [`nrf52840-hal`]. # Cargo.toml [dependencies] -# some-hal = "1.2.3" -+nrf52840-hal = "0.12.0" ++nrf52840-hal = "0.16.0" ``` -#### 5. Import your HAL +⚠️ 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). + +#### 6. Import your HAL Now that you have selected a HAL, fix the HAL import in `src/lib.rs` @@ -110,7 +124,20 @@ Now that you have selected a HAL, fix the HAL import in `src/lib.rs` +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 +\#[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 ++ 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,7 +148,7 @@ 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. @@ -142,7 +169,13 @@ $ echo $? 0 ``` -#### (8. Set `rust-analyzer.linkedProjects`) +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_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]. 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/minimal.rs b/src/bin/minimal.rs index 24fb599..5420464 100644 --- a/src/bin/minimal.rs +++ b/src/bin/minimal.rs @@ -1,5 +1,6 @@ #![no_main] #![no_std] +#![feature(type_alias_impl_trait)] use {{crate_name}} as _; // global logger + panicking-behavior + memory layout @@ -8,10 +9,6 @@ use {{crate_name}} as _; // global logger + panicking-behavior + memory layout dispatchers = [FreeInterrupt1, ...] // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used )] 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 { @@ -25,12 +22,16 @@ mod app { } #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { defmt::info!("init"); + // TODO setup monotonic if used + // let token = systick_monotonics::create_systick_token!(); + // rtic_monotonics::Systick::new(cx.core.SYST, sysclk, token); + + task1::spawn().ok(); - // Setup the monotonic timer ( Shared { // Initialization of shared resources go here @@ -38,9 +39,6 @@ mod app { Local { // Initialization of local resources go here }, - init::Monotonics( - // Initialization of optional monotonic timers go here - ), ) } @@ -56,7 +54,7 @@ mod app { // TODO: Add tasks #[task] - fn task1(_cx: task1::Context) { + async fn task1(_cx: task1::Context) { defmt::info!("Hello from task1!"); } } diff --git a/src/lib.rs b/src/lib.rs index f181f6a..a5ecdad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,7 @@ +#![no_main] #![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 diff --git a/testsuite/Cargo.toml b/testsuite/Cargo.toml deleted file mode 100644 index 06834a5..0000000 --- a/testsuite/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -# TODO fix `authors` if you didn't use `cargo-generate` -authors = ["{{authors}}"] -name = "testsuite" -publish = false -edition = "2021" -version = "0.1.0" - -[lib] -harness = false - -[[test]] -name = "test" -harness = false - -[dependencies] -{{project-name}} = { path = ".." } -cortex-m = "0.7" -cortex-m-rt = "0.7" -defmt = "0.3.0" -defmt-rtt = "0.3.0" -defmt-test = "0.3.0" -panic-probe = { version = "0.3.0", features = ["print-defmt"] } - diff --git a/testsuite/src/lib.rs b/testsuite/src/lib.rs deleted file mode 100644 index d4dd9ce..0000000 --- a/testsuite/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![no_std] -#![cfg_attr(test, no_main)] - -use {{crate_name}} as _; // memory layout + panic handler - -#[defmt_test::tests] -mod tests {} diff --git a/testsuite/tests/test.rs b/testsuite/tests/test.rs deleted file mode 100644 index b26f3bf..0000000 --- a/testsuite/tests/test.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![no_std] -#![no_main] - -use {{crate_name}} as _; // memory layout + panic handler - -// See https://crates.io/crates/defmt-test/0.1.0 for more documentation (e.g. about the 'state' -// feature) -#[defmt_test::tests] -mod tests { - use defmt::{assert, assert_eq}; - - #[test] - fn assert_true() { - assert!(true) - } - - #[test] - fn assert_eq() { - assert_eq!(24, 42, "TODO: write actual tests") - } -}