Skip to content

Commit

Permalink
Merge pull request #270 from BartMassey-upstream/mb2
Browse files Browse the repository at this point in the history
Add BBC micro:bit v2 support for examples
  • Loading branch information
alexmoon authored Aug 10, 2024
2 parents d5f023b + a52464a commit 9973f61
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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

Expand Down
5 changes: 3 additions & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..


Expand Down
3 changes: 3 additions & 0 deletions examples/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
10 changes: 10 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ 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",
"nrf-softdevice/s140",
"dep:nrf-softdevice-s140"
]

nrf52840-dk = ["nrf52840"]
nrf52832-dk = ["nrf52832"]
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"]}
Expand Down
5 changes: 3 additions & 2 deletions examples/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions examples/memory-nrf52833.x
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions examples/memory-nrf52840.x
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 8 additions & 3 deletions examples/src/bin/ble_peripheral_onoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ 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(any(feature = "nrf52840-dk", feature = "nrf52832-dk"))]
let (b1_pin, b2_pin) = (p.P0_11, p.P0_12);

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 {
Expand Down

0 comments on commit 9973f61

Please sign in to comment.