diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 14:03:31 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 14:03:31 +0200 |
| commit | 36e00caf4dc70905b735531c0d5634addd026954 (patch) | |
| tree | 01d3bbb3b7f1ab522f9a1fc651f48197ce355927 /examples/boot/application/stm32h7/src/bin | |
| parent | c2aca45b8d3785007da20ce007d6a6e352fac1a0 (diff) | |
Align examples
Diffstat (limited to 'examples/boot/application/stm32h7/src/bin')
| -rw-r--r-- | examples/boot/application/stm32h7/src/bin/a.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index 202220223..e5f94310c 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 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, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| @@ -16,7 +16,8 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 16 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 17 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 18 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 19 | let mut flash = Flash::new_blocking(p.FLASH); | 19 | let flash = Flash::new_blocking(p.FLASH); |
| 20 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 20 | 21 | ||
| 21 | let button = Input::new(p.PC13, Pull::Down); | 22 | let button = Input::new(p.PC13, Pull::Down); |
| 22 | let mut button = ExtiInput::new(button, p.EXTI13); | 23 | let mut button = ExtiInput::new(button, p.EXTI13); |
| @@ -24,21 +25,21 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 25 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 25 | led.set_high(); | 26 | led.set_high(); |
| 26 | 27 | ||
| 27 | let mut updater = FirmwareUpdater::default(); | 28 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); |
| 28 | 29 | let mut updater = BlockingFirmwareUpdater::new(config); | |
| 29 | let mut writer = updater.prepare_update_blocking(&mut flash).unwrap(); | 30 | let mut writer = updater.prepare_update().unwrap(); |
| 30 | button.wait_for_rising_edge().await; | 31 | button.wait_for_rising_edge().await; |
| 31 | let mut offset = 0; | 32 | let mut offset = 0; |
| 32 | let mut buf = AlignedBuffer([0; 4096]); | 33 | let mut buf = AlignedBuffer([0; 4096]); |
| 33 | for chunk in APP_B.chunks(4096) { | 34 | for chunk in APP_B.chunks(4096) { |
| 34 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); | 35 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); |
| 35 | writer | 36 | writer |
| 36 | .write_block_blocking(offset, buf.as_ref(), &mut flash, 4096) | 37 | .write(offset, buf.as_ref()) |
| 37 | .unwrap(); | 38 | .unwrap(); |
| 38 | offset += chunk.len(); | 39 | offset += chunk.len(); |
| 39 | } | 40 | } |
| 40 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 41 | updater.mark_updated_blocking(&mut flash, magic.as_mut()).unwrap(); | 42 | updater.mark_updated(magic.as_mut()).unwrap(); |
| 42 | led.set_low(); | 43 | led.set_low(); |
| 43 | cortex_m::peripheral::SCB::sys_reset(); | 44 | cortex_m::peripheral::SCB::sys_reset(); |
| 44 | } | 45 | } |
