diff options
| author | Ulf Lilleengen <[email protected]> | 2022-09-26 20:33:24 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-09-26 20:36:57 +0200 |
| commit | 5bf6564e95be4fa4240a08a4f524e9cf4bfee2bb (patch) | |
| tree | 74a8a35342a77025c0a30408afacf5158ff67a28 /examples/boot/application/stm32h7/src/bin | |
| parent | 049c31613b89f6c0f5771cacdf7c6f837c89fe38 (diff) | |
Use firmware writer in stm32{f7, h7} example app
The new FirmwareWriter is useful in particular for these architectures
due to the large erase sector size.
Diffstat (limited to 'examples/boot/application/stm32h7/src/bin')
| -rw-r--r-- | examples/boot/application/stm32h7/src/bin/a.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index f5a8fdb61..0fe598a5d 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #[cfg(feature = "defmt-rtt")] | 5 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 6 | use defmt_rtt::*; |
| 7 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; | 7 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; |
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | ||
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| @@ -17,8 +16,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 17 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 20 | let flash = Flash::unlock(p.FLASH); | 19 | let mut flash = Flash::unlock(p.FLASH); |
| 21 | let mut flash = BlockingAsync::new(flash); | ||
| 22 | 20 | ||
| 23 | let button = Input::new(p.PC13, Pull::Down); | 21 | let button = Input::new(p.PC13, Pull::Down); |
| 24 | let mut button = ExtiInput::new(button, p.EXTI13); | 22 | let mut button = ExtiInput::new(button, p.EXTI13); |
| @@ -27,19 +25,20 @@ async fn main(_spawner: Spawner) { | |||
| 27 | led.set_high(); | 25 | led.set_high(); |
| 28 | 26 | ||
| 29 | let mut updater = FirmwareUpdater::default(); | 27 | let mut updater = FirmwareUpdater::default(); |
| 28 | |||
| 29 | let mut writer = updater.prepare_update_blocking(&mut flash).unwrap(); | ||
| 30 | button.wait_for_rising_edge().await; | 30 | button.wait_for_rising_edge().await; |
| 31 | let mut offset = 0; | 31 | let mut offset = 0; |
| 32 | let mut buf = AlignedBuffer([0; 128 * 1024]); | 32 | let mut buf = AlignedBuffer([0; 4096]); |
| 33 | for chunk in APP_B.chunks(128 * 1024) { | 33 | for chunk in APP_B.chunks(4096) { |
| 34 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); | 34 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater | 35 | writer |
| 36 | .write_firmware(offset, buf.as_ref(), &mut flash, 2048) | 36 | .write_block_blocking(offset, buf.as_ref(), &mut flash, 4096) |
| 37 | .await | ||
| 38 | .unwrap(); | 37 | .unwrap(); |
| 39 | offset += chunk.len(); | 38 | offset += chunk.len(); |
| 40 | } | 39 | } |
| 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 40 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 42 | updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); | 41 | updater.mark_updated_blocking(&mut flash, magic.as_mut()).unwrap(); |
| 43 | led.set_low(); | 42 | led.set_low(); |
| 44 | cortex_m::peripheral::SCB::sys_reset(); | 43 | cortex_m::peripheral::SCB::sys_reset(); |
| 45 | } | 44 | } |
