aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application/stm32l1/src/bin/a.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-06-24 19:56:15 +0200
committerUlf Lilleengen <[email protected]>2022-06-24 19:56:15 +0200
commit776be79f7bb10b09e795e2ea93bb795a653c9b4c (patch)
tree269046d330ee503c84049bb8fc47baf0297ecb80 /examples/boot/application/stm32l1/src/bin/a.rs
parent84628d36cf743193cbf0e7d47ef1cfa9fb590890 (diff)
Move bootloader main to examples
This should remove some confusion around embassy-boot-* being a library vs. a binary. The binary is now an example bootloader instead.
Diffstat (limited to 'examples/boot/application/stm32l1/src/bin/a.rs')
-rw-r--r--examples/boot/application/stm32l1/src/bin/a.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs
new file mode 100644
index 000000000..ce620347b
--- /dev/null
+++ b/examples/boot/application/stm32l1/src/bin/a.rs
@@ -0,0 +1,44 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::time::{Duration, Timer};
8use embassy_boot_stm32::FirmwareUpdater;
9use embassy_embedded_hal::adapter::BlockingAsync;
10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::Peripherals;
14use panic_reset as _;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin");
17
18#[embassy::main]
19async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
20 let flash = Flash::unlock(p.FLASH);
21 let mut flash = BlockingAsync::new(flash);
22
23 let button = Input::new(p.PB2, Pull::Up);
24 let mut button = ExtiInput::new(button, p.EXTI2);
25
26 let mut led = Output::new(p.PB5, Level::Low, Speed::Low);
27
28 led.set_high();
29
30 let mut updater = FirmwareUpdater::default();
31 button.wait_for_falling_edge().await;
32 let mut offset = 0;
33 for chunk in APP_B.chunks(128) {
34 let mut buf: [u8; 128] = [0; 128];
35 buf[..chunk.len()].copy_from_slice(chunk);
36 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap();
37 offset += chunk.len();
38 }
39
40 updater.update(&mut flash).await.unwrap();
41 led.set_low();
42 Timer::after(Duration::from_secs(1)).await;
43 cortex_m::peripheral::SCB::sys_reset();
44}