aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application/stm32wl/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'examples/boot/application/stm32wl/src/bin')
-rw-r--r--examples/boot/application/stm32wl/src/bin/a.rs43
-rw-r--r--examples/boot/application/stm32wl/src/bin/b.rs24
2 files changed, 67 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")]
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.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}
diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs
new file mode 100644
index 000000000..f2344bd53
--- /dev/null
+++ b/examples/boot/application/stm32wl/src/bin/b.rs
@@ -0,0 +1,24 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 let mut led = Output::new(p.PB15, Level::High, Speed::Low);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(500)).await;
20
21 led.set_low();
22 Timer::after(Duration::from_millis(500)).await;
23 }
24}