Merge pull request #1 from datdenkikniet/v2
Update to v2 + merge main repo
This commit is contained in:
+8
-10
@@ -2,22 +2,20 @@
|
|||||||
# TODO fix `authors` and `name` if you didn't use `cargo-generate`
|
# TODO fix `authors` and `name` if you didn't use `cargo-generate`
|
||||||
authors = ["{{authors}}"]
|
authors = ["{{authors}}"]
|
||||||
name = "{{project-name}}"
|
name = "{{project-name}}"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[workspace]
|
|
||||||
members = ["testsuite"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
defmt = "0.3.0"
|
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||||
defmt-rtt = "0.3.0"
|
defmt = "0.3"
|
||||||
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
defmt-brtt = "0.1"
|
||||||
cortex-m-rtic = "1.1"
|
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||||
cortex-m = "0.7"
|
# TODO select the correct rtic backend
|
||||||
|
rtic = { version = "2.0.0-alpha.1", features = [ "correct-rtic-backend" ] }
|
||||||
# TODO enter your HAL here
|
# TODO enter your HAL here
|
||||||
# some-hal = "1.2.3"
|
# some-hal = "1.2.3"
|
||||||
# TODO add a monotonic if you use scheduling
|
# 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
|
# cargo build/run
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|||||||
@@ -82,10 +82,20 @@ In `.cargo/config.toml`, pick the right compilation target for your board.
|
|||||||
Add the target with `rustup`.
|
Add the target with `rustup`.
|
||||||
|
|
||||||
``` console
|
``` 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.
|
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
|
# Cargo.toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
-# some-hal = "1.2.3"
|
-# 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`
|
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
|
+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:
|
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.
|
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!
|
You are now all set to `cargo-run` your first `defmt`-powered application!
|
||||||
There are some examples in the `src/bin` directory.
|
There are some examples in the `src/bin` directory.
|
||||||
@@ -142,7 +169,13 @@ $ echo $?
|
|||||||
0
|
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].
|
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].
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "nightly"
|
||||||
|
components = [ "rust-src", "rustfmt", "llvm-tools-preview" ]
|
||||||
+8
-10
@@ -1,5 +1,6 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
|
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
|
dispatchers = [FreeInterrupt1, ...] // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used
|
||||||
)]
|
)]
|
||||||
mod app {
|
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 resources go here
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
@@ -25,12 +22,16 @@ mod app {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
defmt::info!("init");
|
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();
|
task1::spawn().ok();
|
||||||
|
|
||||||
// Setup the monotonic timer
|
|
||||||
(
|
(
|
||||||
Shared {
|
Shared {
|
||||||
// Initialization of shared resources go here
|
// Initialization of shared resources go here
|
||||||
@@ -38,9 +39,6 @@ mod app {
|
|||||||
Local {
|
Local {
|
||||||
// Initialization of local resources go here
|
// Initialization of local resources go here
|
||||||
},
|
},
|
||||||
init::Monotonics(
|
|
||||||
// Initialization of optional monotonic timers go here
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +54,7 @@ mod app {
|
|||||||
|
|
||||||
// TODO: Add tasks
|
// TODO: Add tasks
|
||||||
#[task]
|
#[task]
|
||||||
fn task1(_cx: task1::Context) {
|
async fn task1(_cx: task1::Context) {
|
||||||
defmt::info!("Hello from task1!");
|
defmt::info!("Hello from task1!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
use defmt_brtt as _; // global logger
|
||||||
|
|
||||||
use defmt_rtt as _; // global logger
|
|
||||||
|
|
||||||
// TODO adjust HAL import
|
// TODO adjust HAL import
|
||||||
// use some_hal as _; // memory layout
|
// use some_hal as _; // memory layout
|
||||||
|
|||||||
@@ -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"] }
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
#![cfg_attr(test, no_main)]
|
|
||||||
|
|
||||||
use {{crate_name}} as _; // memory layout + panic handler
|
|
||||||
|
|
||||||
#[defmt_test::tests]
|
|
||||||
mod tests {}
|
|
||||||
@@ -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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user