diff options
Diffstat (limited to 'examples/boot/application')
| -rw-r--r-- | examples/boot/application/nrf/README.md | 4 | ||||
| -rw-r--r-- | examples/boot/application/nrf/memory-bl.x | 2 | ||||
| -rw-r--r-- | examples/boot/application/nrf/memory.x | 2 | ||||
| -rw-r--r-- | examples/boot/application/nrf/src/bin/a.rs | 18 |
4 files changed, 24 insertions, 2 deletions
diff --git a/examples/boot/application/nrf/README.md b/examples/boot/application/nrf/README.md index 703377a20..a6719b505 100644 --- a/examples/boot/application/nrf/README.md +++ b/examples/boot/application/nrf/README.md | |||
| @@ -32,3 +32,7 @@ cargo objcopy --release --bin b -- -O binary b.bin | |||
| 32 | ``` | 32 | ``` |
| 33 | cargo flash --release --bin a --chip nRF52840_xxAA | 33 | cargo flash --release --bin a --chip nRF52840_xxAA |
| 34 | ``` | 34 | ``` |
| 35 | |||
| 36 | You should then see a solid LED. Pressing button 1 will cause the DFU to be loaded by the bootloader. Upon | ||
| 37 | successfully loading, you'll see the LED flash. After 5 seconds, because there is no petting of the watchdog, | ||
| 38 | you'll see the LED go solid again. This indicates that the bootloader has reverted the update. \ No newline at end of file | ||
diff --git a/examples/boot/application/nrf/memory-bl.x b/examples/boot/application/nrf/memory-bl.x index 8a32b905f..257d65644 100644 --- a/examples/boot/application/nrf/memory-bl.x +++ b/examples/boot/application/nrf/memory-bl.x | |||
| @@ -5,7 +5,7 @@ MEMORY | |||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K |
| 6 | ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K | 6 | ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x00017000, LENGTH = 68K | 7 | DFU : ORIGIN = 0x00017000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); | 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); |
diff --git a/examples/boot/application/nrf/memory.x b/examples/boot/application/nrf/memory.x index 3a54ca460..c6926e422 100644 --- a/examples/boot/application/nrf/memory.x +++ b/examples/boot/application/nrf/memory.x | |||
| @@ -5,7 +5,7 @@ MEMORY | |||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x00007000, LENGTH = 64K | 6 | FLASH : ORIGIN = 0x00007000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x00017000, LENGTH = 68K | 7 | DFU : ORIGIN = 0x00017000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); | 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE); |
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 7a404a914..83191f388 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -8,6 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; |
| 10 | use embassy_nrf::nvmc::Nvmc; | 10 | use embassy_nrf::nvmc::Nvmc; |
| 11 | use embassy_nrf::wdt::{self, Watchdog}; | ||
| 11 | use panic_reset as _; | 12 | use panic_reset as _; |
| 12 | 13 | ||
| 13 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 14 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| @@ -20,6 +21,23 @@ async fn main(_spawner: Spawner) { | |||
| 20 | //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); | 21 | //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); |
| 21 | //let mut button = Input::new(p.P1_02, Pull::Up); | 22 | //let mut button = Input::new(p.P1_02, Pull::Up); |
| 22 | 23 | ||
| 24 | // The following code block illustrates how to obtain a watchdog that is configured | ||
| 25 | // as per the existing watchdog. Ordinarily, we'd use the handle returned to "pet" the | ||
| 26 | // watchdog periodically. If we don't, and we're not going to for this example, then | ||
| 27 | // the watchdog will cause the device to reset as per its configured timeout in the bootloader. | ||
| 28 | // This helps is avoid a situation where new firmware might be bad and block our executor. | ||
| 29 | // If firmware is bad in this way then the bootloader will revert to any previous version. | ||
| 30 | let wdt_config = wdt::Config::try_new(&p.WDT).unwrap(); | ||
| 31 | let (_wdt, [_wdt_handle]) = match Watchdog::try_new(p.WDT, wdt_config) { | ||
| 32 | Ok(x) => x, | ||
| 33 | Err(_) => { | ||
| 34 | // Watchdog already active with the wrong number of handles, waiting for it to timeout... | ||
| 35 | loop { | ||
| 36 | cortex_m::asm::wfe(); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | }; | ||
| 40 | |||
| 23 | let nvmc = Nvmc::new(p.NVMC); | 41 | let nvmc = Nvmc::new(p.NVMC); |
| 24 | let mut nvmc = BlockingAsync::new(nvmc); | 42 | let mut nvmc = BlockingAsync::new(nvmc); |
| 25 | 43 | ||
