Skip to content

Commit ba9cf5f

Browse files
authored
Merge pull request alexmoon#28 from plaes/nrf52832-examples
Add target-specific feature flags for examples (ie nrf52832, nrf52840)
2 parents 3702af9 + 3862f0d commit ba9cf5f

File tree

8 files changed

+51
-16
lines changed

8 files changed

+51
-16
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
22
runner = "probe-rs run --chip nRF52840_xxAA"
3+
#runner = "probe-rs run --chip nRF52832_xxAA"
34

45
[build]
56
# Pick ONE of these compilation targets

ci.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -euxo pipefail
44

55
export RUSTFLAGS=-Dwarnings
66

7-
cargo clippy -p nrf-sdc-examples
7+
cargo clippy -p nrf-sdc-examples --features nrf52832
8+
cargo clippy -p nrf-sdc-examples --features nrf52840
89

910
cargo clippy -p nrf-mpsl-sys
1011
cargo clippy -p nrf-mpsl-sys --features fem-simple-gpio
@@ -15,7 +16,7 @@ cargo clippy -p nrf-mpsl --features nrf52805
1516
cargo clippy -p nrf-mpsl --features nrf52810
1617
cargo clippy -p nrf-mpsl --features nrf52811
1718
cargo clippy -p nrf-mpsl --features nrf52820
18-
# cargo clippy -p nrf-mpsl --features nrf52832
19+
cargo clippy -p nrf-mpsl --features nrf52832
1920
cargo clippy -p nrf-mpsl --features nrf52833
2021
cargo clippy -p nrf-mpsl --features nrf52840
2122
cargo clippy -p nrf-mpsl --features nrf52840,defmt
@@ -33,7 +34,7 @@ cargo clippy -p nrf-sdc --features nrf52805,peripheral,central
3334
cargo clippy -p nrf-sdc --features nrf52810,peripheral,central
3435
cargo clippy -p nrf-sdc --features nrf52811,peripheral,central
3536
cargo clippy -p nrf-sdc --features nrf52820,peripheral,central
36-
# cargo clippy -p nrf-sdc --features nrf52832,peripheral,central
37+
cargo clippy -p nrf-sdc --features nrf52832,peripheral,central
3738
cargo clippy -p nrf-sdc --features nrf52833,peripheral,central
3839
cargo clippy -p nrf-sdc --features nrf52840,peripheral
3940
cargo clippy -p nrf-sdc --features nrf52840,central

examples/Cargo.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ publish = false
1010
name = "adv-simple"
1111

1212
[dependencies]
13-
nrf-sdc = { version = "0.1.0", path = "../nrf-sdc", features = ["defmt", "nrf52840", "peripheral"] }
13+
nrf-sdc = { version = "0.1.0", path = "../nrf-sdc", features = ["defmt", "peripheral"] }
1414
nrf-mpsl = { version = "0.1.0", path = "../nrf-mpsl", features = ["defmt", "critical-section-impl"] }
1515
bt-hci = { version = "0.1.0", default-features = false }
1616

1717
embassy-executor = { version = "0.6", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers", "executor-interrupt"] }
1818
embassy-time = { version = "0.3", features = ["defmt", "defmt-timestamp-uptime"] }
19-
embassy-nrf = { version = "0.2.0", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
19+
embassy-nrf = { version = "0.2.0", features = ["defmt", "time-driver-rtc1", "gpiote", "unstable-pac"] }
2020
embassy-sync = { version = "0.6.0", features = ["defmt"] }
2121

2222
defmt = "0.3"
@@ -28,3 +28,14 @@ cortex-m = { version = "0.7.6" }
2828
cortex-m-rt = "0.7.0"
2929
panic-probe = { version = "0.3", features = ["print-defmt"] }
3030
static_cell = "2"
31+
32+
[features]
33+
nrf52832 = [
34+
"nrf-sdc/nrf52832",
35+
"embassy-nrf/nrf52832",
36+
]
37+
38+
nrf52840 = [
39+
"nrf-sdc/nrf52840",
40+
"embassy-nrf/nrf52840",
41+
]

examples/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ use std::fs::File;
1313
use std::io::Write;
1414
use std::path::PathBuf;
1515

16+
fn linker_data() -> &'static [u8] {
17+
#[cfg(feature = "nrf52832")]
18+
return include_bytes!("memory-nrf52832.x");
19+
#[cfg(feature = "nrf52840")]
20+
return include_bytes!("memory-nrf52840.x");
21+
}
22+
1623
fn main() {
1724
// Put `memory.x` in our output directory and ensure it's
1825
// on the linker search path.
1926
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
2027
File::create(out.join("memory.x"))
2128
.unwrap()
22-
.write_all(include_bytes!("memory.x"))
29+
.write_all(linker_data())
2330
.unwrap();
2431
println!("cargo:rustc-link-search={}", out.display());
2532

examples/memory-nrf52832.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MEMORY
2+
{
3+
/* NOTE 1 K = 1 KiBi = 1024 bytes */
4+
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
5+
RAM : ORIGIN = 0x20000000, LENGTH = 64K
6+
}
File renamed without changes.

examples/src/bin/flash.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ async fn mpsl_task(mpsl: &'static MultiprotocolServiceLayer<'static>) -> ! {
2323
mpsl.run().await
2424
}
2525

26+
const PAGE_SIZE: usize = 4096;
27+
28+
#[cfg(feature = "nrf52832")]
29+
const ERASE_START: u32 = 0x60000;
30+
31+
#[cfg(feature = "nrf52840")]
32+
const ERASE_START: u32 = 0x80000;
33+
34+
const ERASE_STOP: u32 = ERASE_START + 0x2000;
35+
2636
#[embassy_executor::main]
2737
async fn main(spawner: Spawner) {
2838
let p = embassy_nrf::init(Default::default());
@@ -60,11 +70,11 @@ async fn main(spawner: Spawner) {
6070
pin_mut!(f);
6171

6272
info!("starting erase");
63-
unwrap!(f.as_mut().erase(0x80000, 0x82000).await);
73+
unwrap!(f.as_mut().erase(ERASE_START, ERASE_STOP).await);
6474
info!("erased!");
6575

66-
let mut buf = [0; 4096];
67-
for offset in (0x80000..0x82000).step_by(4096) {
76+
let mut buf = [0; PAGE_SIZE];
77+
for offset in (ERASE_START..ERASE_STOP).step_by(PAGE_SIZE) {
6878
info!("starting read");
6979
unwrap!(f.as_mut().read(offset, &mut buf));
7080
info!("read done!");
@@ -76,12 +86,12 @@ async fn main(spawner: Spawner) {
7686
info!("matched!");
7787

7888
info!("starting write");
79-
for offset in (0x80000..0x82000).step_by(4) {
89+
for offset in (ERASE_START..ERASE_STOP).step_by(4) {
8090
unwrap!(f.as_mut().write(offset, &[1, 2, 3, 4]).await);
8191
}
8292
info!("write done!");
8393

84-
for offset in (0x80000..0x82000).step_by(4) {
94+
for offset in (ERASE_START..ERASE_STOP).step_by(4) {
8595
let mut buf = [0; 4];
8696
info!("starting read");
8797
unwrap!(f.as_mut().read(offset, &mut buf));

nrf-mpsl/src/flash.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,11 @@ impl FlashOp {
404404
}
405405

406406
// No partial erase for this chip, just do one page at a time
407-
#[allow(unused_variables)]
408407
#[cfg(feature = "nrf52832")]
409408
fn erase<F: Fn() -> u32>(
410-
get_time: F,
411-
slot_duration_us: u32,
412-
elapsed: &mut u32,
409+
_get_time: F,
410+
_slot_duration_us: u32,
411+
_elapsed: &mut u32,
413412
address: &mut u32,
414413
to: u32,
415414
) -> core::ops::ControlFlow<()> {
@@ -421,7 +420,7 @@ impl FlashOp {
421420
p.config.write(|w| w.wen().ren());
422421
*address += PAGE_SIZE as u32;
423422
if *address >= to {
424-
return ControlFlow::Break(());
423+
ControlFlow::Break(())
425424
} else {
426425
ControlFlow::Continue(())
427426
}

0 commit comments

Comments
 (0)