From f7fe537968891153b941a11e7c3729ddfb554b56 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 27 Jul 2024 12:35:33 -0700 Subject: [PATCH 1/4] added configuration for nrf52833 --- examples/Cargo.toml | 6 ++++++ examples/build.rs | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f99a634b..0a592886 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -23,6 +23,12 @@ nrf52832 = [ "nrf-softdevice/s132", "dep:nrf-softdevice-s132" ] +nrf52833 = [ + "embassy-nrf/nrf52833", + "nrf-softdevice/nrf52833", + "nrf-softdevice/s140", + "dep:nrf-softdevice-s140" +] nrf52840 = [ "embassy-nrf/nrf52840", "nrf-softdevice/nrf52840", diff --git a/examples/build.rs b/examples/build.rs index 2f848556..3e58a711 100644 --- a/examples/build.rs +++ b/examples/build.rs @@ -16,6 +16,8 @@ use std::path::PathBuf; fn linker_data() -> &'static [u8] { #[cfg(feature = "nrf52832")] return include_bytes!("memory-nrf52832.x"); + #[cfg(feature = "nrf52833")] + return include_bytes!("memory-nrf52833.x"); #[cfg(feature = "nrf52840")] return include_bytes!("memory-nrf52840.x"); @@ -24,9 +26,8 @@ fn linker_data() -> &'static [u8] { feature = "nrf52810", feature = "nrf52811", feature = "nrf52820", - feature = "nrf52833", ))] - panic!("Unable to build examples for currently selected chip due to missing chip-specific linker configuration (memory.x)"); + panic!("Unable to build examples for currently selected chip due to missing chip-specific linker configuration (memory.x)") } fn main() { From 0122485d9f71f67f9471cf3323ef7f4b946bf834 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 27 Jul 2024 13:51:44 -0700 Subject: [PATCH 2/4] updated examples to work with BBC micro:bit v2 --- README.md | 6 +++--- examples/.cargo/config.toml | 3 +++ examples/Cargo.toml | 3 +++ examples/memory-nrf52833.x | 7 +++++++ examples/src/bin/ble_peripheral_onoff.rs | 13 ++++++++++--- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 examples/memory-nrf52833.x diff --git a/README.md b/README.md index 5b031765..436996e1 100644 --- a/README.md +++ b/README.md @@ -73,15 +73,15 @@ Flashing the softdevice is required. It is NOT part of the built binary. You onl - As a debug client, if you are using - probe-rs: - Erase the flash with `probe-rs erase --chip nrf52840_xxAA` (You may have to supply additional `--allow-erase-all` argument). - - Flash the SoftDevice with `probe-rs download --verify --format hex --chip nRF52840_xxAA s140_nrf52_7.X.X_softdevice.hex` + - Flash the SoftDevice with `probe-rs download --verify --binary-format hex --chip nRF52840_xxAA s140_nrf52_7.X.X_softdevice.hex` - nrfjprog: - Flash the SoftDevice with `nrfjprog --family NRF52 --chiperase --verify --program s140_nrf52_7.0.1_softdevice.hex` To run an example, simply use `cargo run` from the `examples` folder: -- `cd examples && cargo run --bin ble_bas_peripheral --features nrf52840` +- `cd examples && cargo run --bin ble_bas_peripheral --features nrf52840-dk` -Examples can also built for nrf52832 chip targeting S132 softdevice. +Examples can also built for nrf52832 chip targeting S132 softdevice (feature flag `nrf52832`, board is unknown), or for nrf52833 targeting S140 softdevice on the BBC micro:bit v2 (feature flag `microbit-v2`). In these cases, edit `.cargo/config.toml` as needed. ## Configuring a SoftDevice diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml index d9250bd5..bfa8b809 100644 --- a/examples/.cargo/config.toml +++ b/examples/.cargo/config.toml @@ -1,4 +1,7 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# Pick ONE of these chip targets +#runner = "probe-rs run --chip nRF52832_xxAA" +#runner = "probe-rs run --chip nRF52833_xxAA" runner = "probe-rs run --chip nRF52840_xxAA" [build] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 0a592886..6415c7c7 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -36,6 +36,9 @@ nrf52840 = [ "dep:nrf-softdevice-s140" ] +nrf52840-dk = ["nrf52840"] +microbit-v2 = ["nrf52833"] + [dependencies] embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"]} embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime"]} diff --git a/examples/memory-nrf52833.x b/examples/memory-nrf52833.x new file mode 100644 index 00000000..540041c4 --- /dev/null +++ b/examples/memory-nrf52833.x @@ -0,0 +1,7 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + /* NRF52833 with Softdevice S140 7.3.0 */ + FLASH : ORIGIN = 0x00000000 + 156K, LENGTH = 512K - 156K + RAM : ORIGIN = 0x20000000 + 31K, LENGTH = 128K - 31K +} diff --git a/examples/src/bin/ble_peripheral_onoff.rs b/examples/src/bin/ble_peripheral_onoff.rs index 5595a1bf..cddef20e 100644 --- a/examples/src/bin/ble_peripheral_onoff.rs +++ b/examples/src/bin/ble_peripheral_onoff.rs @@ -121,10 +121,17 @@ async fn main(spawner: Spawner) { unwrap!(spawner.spawn(softdevice_task(sd))); info!("Bluetooth is OFF"); - info!("Press nrf52840-dk button 1 to enable, button 2 to disable"); + info!("Press button 1 to enable, button 2 to disable"); + #[cfg(feature = "microbit-v2")] + let (b1_pin, b2_pin) = (p.P0_14, p.P0_23); + #[cfg(feature = "nrf52840-dk")] + let (b1_pin, b2_pin) = (p.P0_11, p.P0_12); + #[cfg(not(any(feature = "nrf52840-dk", feature = "microbit-v2")))] + panic!("unsupported board"); + + let button1 = Input::new(b1_pin.degrade(), Pull::Up); + let button2 = Input::new(b2_pin.degrade(), Pull::Up); - let button1 = Input::new(p.P0_11.degrade(), Pull::Up); - let button2 = Input::new(p.P0_12.degrade(), Pull::Up); pin_mut!(button1); pin_mut!(button2); loop { From 91300c7ced6681fe5a62a573977271c782c55c83 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 27 Jul 2024 14:01:42 -0700 Subject: [PATCH 3/4] updated memory-nrf52840.x for nRF SoftDevice s140 7.3.0 --- examples/memory-nrf52840.x | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/memory-nrf52840.x b/examples/memory-nrf52840.x index 6c6b73b5..5b2c22b4 100644 --- a/examples/memory-nrf52840.x +++ b/examples/memory-nrf52840.x @@ -1,7 +1,7 @@ MEMORY { /* NOTE 1 K = 1 KiBi = 1024 bytes */ - /* NRF52840 with Softdevice S140 7.0.1 */ - FLASH : ORIGIN = 0x00027000, LENGTH = 868K - RAM : ORIGIN = 0x20020000, LENGTH = 128K + /* NRF52840 with Softdevice S140 7.3.0 */ + FLASH : ORIGIN = 0x00000000 + 156K, LENGTH = 1024K - 156K + RAM : ORIGIN = 0x20000000 + 31K, LENGTH = 256K - 31K } From a52464a72c637e0b21377f6dc3a1eb5a0f37fe19 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 27 Jul 2024 15:36:55 -0700 Subject: [PATCH 4/4] fixed ci after changes --- README.md | 2 +- ci.sh | 5 +++-- examples/Cargo.toml | 1 + examples/src/bin/ble_peripheral_onoff.rs | 4 +--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 436996e1..61afcfd9 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ To run an example, simply use `cargo run` from the `examples` folder: - `cd examples && cargo run --bin ble_bas_peripheral --features nrf52840-dk` -Examples can also built for nrf52832 chip targeting S132 softdevice (feature flag `nrf52832`, board is unknown), or for nrf52833 targeting S140 softdevice on the BBC micro:bit v2 (feature flag `microbit-v2`). In these cases, edit `.cargo/config.toml` as needed. +Examples can also built for nrf52832 development kit targeting S132 softdevice (feature flag `nrf52832-dk`), or for nrf52833 targeting S140 softdevice on the BBC micro:bit v2 (feature flag `microbit-v2`). In these cases, edit `.cargo/config.toml` as needed. ## Configuring a SoftDevice diff --git a/ci.sh b/ci.sh index 540fab10..8a72557c 100755 --- a/ci.sh +++ b/ci.sh @@ -6,8 +6,9 @@ set -euxo pipefail #=============== cd examples -cargo build --target thumbv7em-none-eabihf --features nrf52832 --bins -cargo build --target thumbv7em-none-eabihf --features nrf52840 --bins +cargo build --target thumbv7em-none-eabihf --features nrf52832-dk --bins +cargo build --target thumbv7em-none-eabihf --features microbit-v2 --bins +cargo build --target thumbv7em-none-eabihf --features nrf52840-dk --bins cd .. diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 6415c7c7..19717cbf 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -37,6 +37,7 @@ nrf52840 = [ ] nrf52840-dk = ["nrf52840"] +nrf52832-dk = ["nrf52832"] microbit-v2 = ["nrf52833"] [dependencies] diff --git a/examples/src/bin/ble_peripheral_onoff.rs b/examples/src/bin/ble_peripheral_onoff.rs index cddef20e..1bc8d483 100644 --- a/examples/src/bin/ble_peripheral_onoff.rs +++ b/examples/src/bin/ble_peripheral_onoff.rs @@ -124,10 +124,8 @@ async fn main(spawner: Spawner) { info!("Press button 1 to enable, button 2 to disable"); #[cfg(feature = "microbit-v2")] let (b1_pin, b2_pin) = (p.P0_14, p.P0_23); - #[cfg(feature = "nrf52840-dk")] + #[cfg(any(feature = "nrf52840-dk", feature = "nrf52832-dk"))] let (b1_pin, b2_pin) = (p.P0_11, p.P0_12); - #[cfg(not(any(feature = "nrf52840-dk", feature = "microbit-v2")))] - panic!("unsupported board"); let button1 = Input::new(b1_pin.degrade(), Pull::Up); let button2 = Input::new(b2_pin.degrade(), Pull::Up);