aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application/nrf/src/bin
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2023-07-17 21:31:43 -0400
committerQuentin Smith <[email protected]>2023-07-17 21:31:43 -0400
commit6f02403184eb7fb7990fb88fc9df9c4328a690a3 (patch)
tree748f510e190bb2724750507a6e69ed1a8e08cb20 /examples/boot/application/nrf/src/bin
parentd896f80405aa8963877049ed999e4aba25d6e2bb (diff)
parent6b5df4523aa1c4902f02e803450ae4b418e0e3ca (diff)
Merge remote-tracking branch 'origin/main' into nrf-pdm
Diffstat (limited to 'examples/boot/application/nrf/src/bin')
-rw-r--r--examples/boot/application/nrf/src/bin/a.rs41
-rw-r--r--examples/boot/application/nrf/src/bin/b.rs6
2 files changed, 39 insertions, 8 deletions
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs
index bd8fa3246..021d77f3b 100644
--- a/examples/boot/application/nrf/src/bin/a.rs
+++ b/examples/boot/application/nrf/src/bin/a.rs
@@ -1,42 +1,71 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#![macro_use] 3#![macro_use]
4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)] 4#![feature(type_alias_impl_trait)]
6 5
7use embassy_boot_nrf::FirmwareUpdater; 6use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig};
8use embassy_embedded_hal::adapter::BlockingAsync; 7use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 8use embassy_executor::Spawner;
10use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; 9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
11use embassy_nrf::nvmc::Nvmc; 10use embassy_nrf::nvmc::Nvmc;
11use embassy_nrf::wdt::{self, Watchdog};
12use embassy_sync::mutex::Mutex;
12use panic_reset as _; 13use panic_reset as _;
13 14
15#[cfg(feature = "skip-include")]
16static APP_B: &[u8] = &[0, 1, 2, 3];
17#[cfg(not(feature = "skip-include"))]
14static APP_B: &[u8] = include_bytes!("../../b.bin"); 18static APP_B: &[u8] = include_bytes!("../../b.bin");
15 19
16#[embassy_executor::main] 20#[embassy_executor::main]
17async fn main(_spawner: Spawner) { 21async fn main(_spawner: Spawner) {
18 let p = embassy_nrf::init(Default::default()); 22 let p = embassy_nrf::init(Default::default());
23
19 let mut button = Input::new(p.P0_11, Pull::Up); 24 let mut button = Input::new(p.P0_11, Pull::Up);
20 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 25 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
26
21 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); 27 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
22 //let mut button = Input::new(p.P1_02, Pull::Up); 28 //let mut button = Input::new(p.P1_02, Pull::Up);
23 29
30 // nRF91 DK
31 // let mut led = Output::new(p.P0_02, Level::Low, OutputDrive::Standard);
32 // let mut button = Input::new(p.P0_06, Pull::Up);
33
34 // The following code block illustrates how to obtain a watchdog that is configured
35 // as per the existing watchdog. Ordinarily, we'd use the handle returned to "pet" the
36 // watchdog periodically. If we don't, and we're not going to for this example, then
37 // the watchdog will cause the device to reset as per its configured timeout in the bootloader.
38 // This helps is avoid a situation where new firmware might be bad and block our executor.
39 // If firmware is bad in this way then the bootloader will revert to any previous version.
40 let wdt_config = wdt::Config::try_new(&p.WDT).unwrap();
41 let (_wdt, [_wdt_handle]) = match Watchdog::try_new(p.WDT, wdt_config) {
42 Ok(x) => x,
43 Err(_) => {
44 // Watchdog already active with the wrong number of handles, waiting for it to timeout...
45 loop {
46 cortex_m::asm::wfe();
47 }
48 }
49 };
50
24 let nvmc = Nvmc::new(p.NVMC); 51 let nvmc = Nvmc::new(p.NVMC);
25 let mut nvmc = BlockingAsync::new(nvmc); 52 let nvmc = Mutex::new(BlockingAsync::new(nvmc));
26 53
27 let mut updater = FirmwareUpdater::default(); 54 let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc);
55 let mut updater = FirmwareUpdater::new(config);
28 loop { 56 loop {
29 led.set_low(); 57 led.set_low();
30 button.wait_for_any_edge().await; 58 button.wait_for_any_edge().await;
31 if button.is_low() { 59 if button.is_low() {
32 let mut offset = 0; 60 let mut offset = 0;
61 let mut magic = [0; 4];
33 for chunk in APP_B.chunks(4096) { 62 for chunk in APP_B.chunks(4096) {
34 let mut buf: [u8; 4096] = [0; 4096]; 63 let mut buf: [u8; 4096] = [0; 4096];
35 buf[..chunk.len()].copy_from_slice(chunk); 64 buf[..chunk.len()].copy_from_slice(chunk);
36 updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); 65 updater.write_firmware(&mut magic, offset, &buf).await.unwrap();
37 offset += chunk.len(); 66 offset += chunk.len();
38 } 67 }
39 updater.update(&mut nvmc).await.unwrap(); 68 updater.mark_updated(&mut magic).await.unwrap();
40 led.set_high(); 69 led.set_high();
41 cortex_m::peripheral::SCB::sys_reset(); 70 cortex_m::peripheral::SCB::sys_reset();
42 } 71 }
diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs
index 5394bf0c7..15ebce5fa 100644
--- a/examples/boot/application/nrf/src/bin/b.rs
+++ b/examples/boot/application/nrf/src/bin/b.rs
@@ -1,7 +1,6 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#![macro_use] 3#![macro_use]
4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)] 4#![feature(type_alias_impl_trait)]
6 5
7use embassy_executor::Spawner; 6use embassy_executor::Spawner;
@@ -13,7 +12,10 @@ use panic_reset as _;
13async fn main(_spawner: Spawner) { 12async fn main(_spawner: Spawner) {
14 let p = embassy_nrf::init(Default::default()); 13 let p = embassy_nrf::init(Default::default());
15 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 14 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
16 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); 15 // let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
16
17 // nRF91 DK
18 // let mut led = Output::new(p.P0_02, Level::Low, OutputDrive::Standard);
17 19
18 loop { 20 loop {
19 led.set_high(); 21 led.set_high();