diff options
| author | Ulf Lilleengen <[email protected]> | 2022-06-24 19:56:15 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-06-24 19:56:15 +0200 |
| commit | 776be79f7bb10b09e795e2ea93bb795a653c9b4c (patch) | |
| tree | 269046d330ee503c84049bb8fc47baf0297ecb80 /examples/boot/application/nrf/src | |
| parent | 84628d36cf743193cbf0e7d47ef1cfa9fb590890 (diff) | |
Move bootloader main to examples
This should remove some confusion around embassy-boot-* being a library
vs. a binary. The binary is now an example bootloader instead.
Diffstat (limited to 'examples/boot/application/nrf/src')
| -rw-r--r-- | examples/boot/application/nrf/src/bin/a.rs | 43 | ||||
| -rw-r--r-- | examples/boot/application/nrf/src/bin/b.rs | 23 |
2 files changed, 66 insertions, 0 deletions
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs new file mode 100644 index 000000000..0b9715e49 --- /dev/null +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![macro_use] | ||
| 4 | #![feature(generic_associated_types)] | ||
| 5 | #![feature(type_alias_impl_trait)] | ||
| 6 | |||
| 7 | use embassy_boot_nrf::FirmwareUpdater; | ||
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | ||
| 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | ||
| 10 | use embassy_nrf::nvmc::Nvmc; | ||
| 11 | use embassy_nrf::Peripherals; | ||
| 12 | use panic_reset as _; | ||
| 13 | |||
| 14 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 15 | |||
| 16 | #[embassy::main] | ||
| 17 | async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | ||
| 18 | let mut button = Input::new(p.P0_11, Pull::Up); | ||
| 19 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | ||
| 20 | //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); | ||
| 21 | //let mut button = Input::new(p.P1_02, Pull::Up); | ||
| 22 | |||
| 23 | let nvmc = Nvmc::new(p.NVMC); | ||
| 24 | let mut nvmc = BlockingAsync::new(nvmc); | ||
| 25 | |||
| 26 | let mut updater = FirmwareUpdater::default(); | ||
| 27 | loop { | ||
| 28 | led.set_low(); | ||
| 29 | button.wait_for_any_edge().await; | ||
| 30 | if button.is_low() { | ||
| 31 | let mut offset = 0; | ||
| 32 | for chunk in APP_B.chunks(4096) { | ||
| 33 | let mut buf: [u8; 4096] = [0; 4096]; | ||
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | ||
| 35 | updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); | ||
| 36 | offset += chunk.len(); | ||
| 37 | } | ||
| 38 | updater.update(&mut nvmc).await.unwrap(); | ||
| 39 | led.set_high(); | ||
| 40 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs new file mode 100644 index 000000000..a06c20f8b --- /dev/null +++ b/examples/boot/application/nrf/src/bin/b.rs | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![macro_use] | ||
| 4 | #![feature(generic_associated_types)] | ||
| 5 | #![feature(type_alias_impl_trait)] | ||
| 6 | |||
| 7 | use embassy::time::{Duration, Timer}; | ||
| 8 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 9 | use embassy_nrf::Peripherals; | ||
| 10 | use panic_reset as _; | ||
| 11 | |||
| 12 | #[embassy::main] | ||
| 13 | async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | ||
| 14 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | ||
| 15 | //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); | ||
| 16 | |||
| 17 | loop { | ||
| 18 | led.set_high(); | ||
| 19 | Timer::after(Duration::from_millis(300)).await; | ||
| 20 | led.set_low(); | ||
| 21 | Timer::after(Duration::from_millis(300)).await; | ||
| 22 | } | ||
| 23 | } | ||
