diff options
| author | Ulf Lilleengen <[email protected]> | 2022-06-24 19:56:15 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-06-24 19:56:15 +0200 |
| commit | 776be79f7bb10b09e795e2ea93bb795a653c9b4c (patch) | |
| tree | 269046d330ee503c84049bb8fc47baf0297ecb80 /examples/boot/application/stm32f7/src | |
| parent | 84628d36cf743193cbf0e7d47ef1cfa9fb590890 (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/stm32f7/src')
| -rw-r--r-- | examples/boot/application/stm32f7/src/bin/a.rs | 40 | ||||
| -rw-r--r-- | examples/boot/application/stm32f7/src/bin/b.rs | 26 |
2 files changed, 66 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")] | ||
| 6 | use defmt_rtt::*; | ||
| 7 | use embassy_boot_stm32::FirmwareUpdater; | ||
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | ||
| 9 | use embassy_stm32::exti::ExtiInput; | ||
| 10 | use embassy_stm32::flash::Flash; | ||
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use panic_reset as _; | ||
| 14 | |||
| 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async 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 | } | ||
diff --git a/examples/boot/application/stm32f7/src/bin/b.rs b/examples/boot/application/stm32f7/src/bin/b.rs new file mode 100644 index 000000000..aa05bbcdd --- /dev/null +++ b/examples/boot/application/stm32f7/src/bin/b.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[cfg(feature = "defmt-rtt")] | ||
| 6 | use defmt_rtt::*; | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy::time::{Duration, Timer}; | ||
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 10 | use embassy_stm32::Peripherals; | ||
| 11 | use panic_reset as _; | ||
| 12 | |||
| 13 | #[embassy::main] | ||
| 14 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 15 | Timer::after(Duration::from_millis(300)).await; | ||
| 16 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); | ||
| 17 | led.set_high(); | ||
| 18 | |||
| 19 | loop { | ||
| 20 | led.set_high(); | ||
| 21 | Timer::after(Duration::from_millis(500)).await; | ||
| 22 | |||
| 23 | led.set_low(); | ||
| 24 | Timer::after(Duration::from_millis(500)).await; | ||
| 25 | } | ||
| 26 | } | ||
