From 776be79f7bb10b09e795e2ea93bb795a653c9b4c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 24 Jun 2022 19:56:15 +0200 Subject: 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. --- examples/boot/application/nrf/src/bin/a.rs | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/boot/application/nrf/src/bin/a.rs (limited to 'examples/boot/application/nrf/src/bin/a.rs') 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 @@ +#![no_std] +#![no_main] +#![macro_use] +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +use embassy_boot_nrf::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; +use embassy_nrf::nvmc::Nvmc; +use embassy_nrf::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let mut button = Input::new(p.P0_11, Pull::Up); + let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); + //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); + //let mut button = Input::new(p.P1_02, Pull::Up); + + let nvmc = Nvmc::new(p.NVMC); + let mut nvmc = BlockingAsync::new(nvmc); + + let mut updater = FirmwareUpdater::default(); + loop { + led.set_low(); + button.wait_for_any_edge().await; + if button.is_low() { + let mut offset = 0; + for chunk in APP_B.chunks(4096) { + let mut buf: [u8; 4096] = [0; 4096]; + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut nvmc).await.unwrap(); + led.set_high(); + cortex_m::peripheral::SCB::sys_reset(); + } + } +} -- cgit