diff options
Diffstat (limited to 'examples/boot/application/stm32wl/src/bin/a.rs')
| -rw-r--r-- | examples/boot/application/stm32wl/src/bin/a.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs new file mode 100644 index 000000000..dc1eb9bed --- /dev/null +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 7 | use embassy_boot_stm32::FirmwareUpdater; | ||
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | ||
| 9 | use embassy_stm32::exti::ExtiInput; | ||
| 10 | use embassy_stm32::flash::Flash; | ||
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use panic_reset as _; | ||
| 14 | |||
| 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async fn main(_s: embassy::executor::Spawner, p: Peripherals) { | ||
| 19 | let flash = Flash::unlock(p.FLASH); | ||
| 20 | let mut flash = BlockingAsync::new(flash); | ||
| 21 | |||
| 22 | let button = Input::new(p.PA0, Pull::Up); | ||
| 23 | let mut button = ExtiInput::new(button, p.EXTI0); | ||
| 24 | |||
| 25 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); | ||
| 26 | led.set_high(); | ||
| 27 | |||
| 28 | let mut updater = FirmwareUpdater::default(); | ||
| 29 | button.wait_for_falling_edge().await; | ||
| 30 | //defmt::info!("Starting update"); | ||
| 31 | let mut offset = 0; | ||
| 32 | for chunk in APP_B.chunks(2048) { | ||
| 33 | let mut buf: [u8; 2048] = [0; 2048]; | ||
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | ||
| 35 | // defmt::info!("Writing chunk at 0x{:x}", offset); | ||
| 36 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); | ||
| 37 | offset += chunk.len(); | ||
| 38 | } | ||
| 39 | updater.update(&mut flash).await.unwrap(); | ||
| 40 | //defmt::info!("Marked as updated"); | ||
| 41 | led.set_low(); | ||
| 42 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 43 | } | ||
