From ed2a87a262e0e8c091627c96ced981dd3a97a6a1 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 24 Jan 2022 12:54:09 +0100 Subject: Add embassy-boot Embassy-boot is a simple bootloader that works together with an application to provide firmware update capabilities with a minimal risk. The bootloader consists of a platform-independent part, which implements the swap algorithm, and a platform-dependent part (currently only for nRF) that provides addition functionality such as watchdog timers softdevice support. --- examples/boot/src/bin/a.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++ examples/boot/src/bin/b.rs | 26 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 examples/boot/src/bin/a.rs create mode 100644 examples/boot/src/bin/b.rs (limited to 'examples/boot/src') diff --git a/examples/boot/src/bin/a.rs b/examples/boot/src/bin/a.rs new file mode 100644 index 000000000..88880e688 --- /dev/null +++ b/examples/boot/src/bin/a.rs @@ -0,0 +1,49 @@ +#![no_std] +#![no_main] +#![macro_use] +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +use embassy_boot_nrf::updater; +use embassy_nrf::{ + gpio::{Input, Pull}, + gpio::{Level, Output, OutputDrive}, + nvmc::Nvmc, + Peripherals, +}; +use embassy_traits::adapter::BlockingAsync; +use embedded_hal::digital::v2::InputPin; +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); + + loop { + button.wait_for_any_edge().await; + if button.is_low().unwrap() { + let mut updater = updater::new(); + 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) + .await + .unwrap(); + offset += chunk.len(); + } + updater.mark_update(&mut nvmc).await.unwrap(); + led.set_high(); + cortex_m::peripheral::SCB::sys_reset(); + } + } +} diff --git a/examples/boot/src/bin/b.rs b/examples/boot/src/bin/b.rs new file mode 100644 index 000000000..18bb6330c --- /dev/null +++ b/examples/boot/src/bin/b.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] +#![macro_use] +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +use embassy::time::{Duration, Timer}; +use embassy_nrf::{ + gpio::{Level, Output, OutputDrive}, + Peripherals, +}; + +use panic_reset as _; + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); + //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(300)).await; + led.set_low(); + Timer::after(Duration::from_millis(300)).await; + } +} -- cgit