diff options
Diffstat (limited to 'examples/boot/application/rp/src')
| -rw-r--r-- | examples/boot/application/rp/src/bin/a.rs | 52 | ||||
| -rw-r--r-- | examples/boot/application/rp/src/bin/b.rs | 23 |
2 files changed, 75 insertions, 0 deletions
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs new file mode 100644 index 000000000..3736c9141 --- /dev/null +++ b/examples/boot/application/rp/src/bin/a.rs | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt_rtt as _; | ||
| 6 | use embassy_boot_rp::*; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_rp::flash::Flash; | ||
| 9 | use embassy_rp::gpio::{Level, Output}; | ||
| 10 | use embassy_time::{Duration, Timer}; | ||
| 11 | #[cfg(feature = "panic-probe")] | ||
| 12 | use panic_probe as _; | ||
| 13 | #[cfg(feature = "panic-reset")] | ||
| 14 | use panic_reset as _; | ||
| 15 | |||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 17 | const FLASH_SIZE: usize = 2 * 1024 * 1024; | ||
| 18 | |||
| 19 | #[embassy_executor::main] | ||
| 20 | async fn main(_s: Spawner) { | ||
| 21 | let p = embassy_rp::init(Default::default()); | ||
| 22 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 23 | |||
| 24 | let mut flash: Flash<_, FLASH_SIZE> = Flash::new(p.FLASH); | ||
| 25 | |||
| 26 | let mut updater = FirmwareUpdater::default(); | ||
| 27 | |||
| 28 | Timer::after(Duration::from_secs(5)).await; | ||
| 29 | led.set_high(); | ||
| 30 | let mut offset = 0; | ||
| 31 | let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); | ||
| 32 | defmt::info!("preparing update"); | ||
| 33 | let mut writer = updater | ||
| 34 | .prepare_update_blocking(&mut flash) | ||
| 35 | .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) | ||
| 36 | .unwrap(); | ||
| 37 | defmt::info!("writer created, starting write"); | ||
| 38 | for chunk in APP_B.chunks(4096) { | ||
| 39 | buf.0[..chunk.len()].copy_from_slice(chunk); | ||
| 40 | defmt::info!("writing block at offset {}", offset); | ||
| 41 | writer | ||
| 42 | .write_block_blocking(offset, &buf.0[..], &mut flash, 256) | ||
| 43 | .unwrap(); | ||
| 44 | offset += chunk.len(); | ||
| 45 | } | ||
| 46 | defmt::info!("firmware written, marking update"); | ||
| 47 | updater.mark_updated_blocking(&mut flash, &mut buf.0[..1]).unwrap(); | ||
| 48 | Timer::after(Duration::from_secs(2)).await; | ||
| 49 | led.set_low(); | ||
| 50 | defmt::info!("update marked, resetting"); | ||
| 51 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 52 | } | ||
diff --git a/examples/boot/application/rp/src/bin/b.rs b/examples/boot/application/rp/src/bin/b.rs new file mode 100644 index 000000000..47dec329c --- /dev/null +++ b/examples/boot/application/rp/src/bin/b.rs | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_rp::gpio; | ||
| 7 | use embassy_time::{Duration, Timer}; | ||
| 8 | use gpio::{Level, Output}; | ||
| 9 | use {defmt_rtt as _, panic_reset as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_s: Spawner) { | ||
| 13 | let p = embassy_rp::init(Default::default()); | ||
| 14 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 15 | |||
| 16 | loop { | ||
| 17 | led.set_high(); | ||
| 18 | Timer::after(Duration::from_millis(100)).await; | ||
| 19 | |||
| 20 | led.set_low(); | ||
| 21 | Timer::after(Duration::from_millis(100)).await; | ||
| 22 | } | ||
| 23 | } | ||
