aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application/stm32f7/src/bin/a.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/boot/application/stm32f7/src/bin/a.rs')
-rw-r--r--examples/boot/application/stm32f7/src/bin/a.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs
new file mode 100644
index 000000000..9c7921a1a
--- /dev/null
+++ b/examples/boot/application/stm32f7/src/bin/a.rs
@@ -0,0 +1,40 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _;
14
15static APP_B: &[u8] = include_bytes!("../../b.bin");
16
17#[embassy::main]
18async 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.PC13, Pull::Down);
23 let mut button = ExtiInput::new(button, p.EXTI13);
24
25 let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
26 led.set_high();
27
28 let mut updater = FirmwareUpdater::default();
29 button.wait_for_rising_edge().await;
30 let mut offset = 0;
31 let mut buf: [u8; 256 * 1024] = [0; 256 * 1024];
32 for chunk in APP_B.chunks(256 * 1024) {
33 buf[..chunk.len()].copy_from_slice(chunk);
34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
35 offset += chunk.len();
36 }
37 updater.update(&mut flash).await.unwrap();
38 led.set_low();
39 cortex_m::peripheral::SCB::sys_reset();
40}