Update to v2

This commit is contained in:
datdenkikniet
2023-04-22 22:04:30 +02:00
parent fb03cda302
commit 1b3f6cc68f
4 changed files with 44 additions and 18 deletions
+3 -2
View File
@@ -12,12 +12,13 @@ members = ["testsuite"]
defmt = "0.3.0" defmt = "0.3.0"
defmt-rtt = "0.3.0" defmt-rtt = "0.3.0"
panic-probe = { version = "0.3.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
cortex-m-rtic = "1.1"
cortex-m = "0.7" 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]
+30 -7
View File
@@ -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,10 @@ 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 #### 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 +120,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 +144,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 +165,7 @@ $ echo $?
0 0
``` ```
#### (8. Set `rust-analyzer.linkedProjects`) #### (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].
+3
View File
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
components = [ "rust-src", "rustfmt", "llvm-tools-preview" ]
+8 -9
View File
@@ -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,9 +22,14 @@ 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 // Setup the monotonic timer
@@ -38,9 +40,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 +55,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!");
} }
} }