aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application/stm32l0/src/bin/a.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-06-19 23:30:51 +0200
committerUlf Lilleengen <[email protected]>2023-06-19 23:34:07 +0200
commit161d3ce05c812f7ee951b6265735187b4994037a (patch)
treec9e82c062ac089cf37cc175810a8a2041bddea0e /examples/boot/application/stm32l0/src/bin/a.rs
parent76659d9003104f8edd2472a36149565e4a55c0e6 (diff)
Add firmware updater examples to CI
CI was not building the a.rs application due to the requirement of b.bin having been built first. Add a feature flag to examples so that CI can build them including a dummy application. Update a.rs application examples so that they compile again.
Diffstat (limited to 'examples/boot/application/stm32l0/src/bin/a.rs')
-rw-r--r--examples/boot/application/stm32l0/src/bin/a.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs
index 4033ac590..ce80056e6 100644
--- a/examples/boot/application/stm32l0/src/bin/a.rs
+++ b/examples/boot/application/stm32l0/src/bin/a.rs
@@ -4,22 +4,26 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::{Flash, WRITE_SIZE}; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_sync::mutex::Mutex;
13use embassy_time::{Duration, Timer}; 14use embassy_time::{Duration, Timer};
14use panic_reset as _; 15use panic_reset as _;
15 16
17#[cfg(feature = "skip-include")]
18static APP_B: &[u8] = &[0, 1, 2, 3];
19#[cfg(not(feature = "skip-include"))]
16static APP_B: &[u8] = include_bytes!("../../b.bin"); 20static APP_B: &[u8] = include_bytes!("../../b.bin");
17 21
18#[embassy_executor::main] 22#[embassy_executor::main]
19async fn main(_spawner: Spawner) { 23async fn main(_spawner: Spawner) {
20 let p = embassy_stm32::init(Default::default()); 24 let p = embassy_stm32::init(Default::default());
21 let flash = Flash::new_blocking(p.FLASH); 25 let flash = Flash::new_blocking(p.FLASH);
22 let mut flash = BlockingAsync::new(flash); 26 let flash = Mutex::new(BlockingAsync::new(flash));
23 27
24 let button = Input::new(p.PB2, Pull::Up); 28 let button = Input::new(p.PB2, Pull::Up);
25 let mut button = ExtiInput::new(button, p.EXTI2); 29 let mut button = ExtiInput::new(button, p.EXTI2);
@@ -28,18 +32,19 @@ async fn main(_spawner: Spawner) {
28 32
29 led.set_high(); 33 led.set_high();
30 34
31 let mut updater = FirmwareUpdater::default(); 35 let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
36 let mut updater = FirmwareUpdater::new(config);
32 button.wait_for_falling_edge().await; 37 button.wait_for_falling_edge().await;
33 let mut offset = 0; 38 let mut offset = 0;
39 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
34 for chunk in APP_B.chunks(128) { 40 for chunk in APP_B.chunks(128) {
35 let mut buf: [u8; 128] = [0; 128]; 41 let mut buf: [u8; 128] = [0; 128];
36 buf[..chunk.len()].copy_from_slice(chunk); 42 buf[..chunk.len()].copy_from_slice(chunk);
37 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); 43 updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
38 offset += chunk.len(); 44 offset += chunk.len();
39 } 45 }
40 46
41 let mut magic = AlignedBuffer([0; WRITE_SIZE]); 47 updater.mark_updated(magic.as_mut()).await.unwrap();
42 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
43 led.set_low(); 48 led.set_low();
44 Timer::after(Duration::from_secs(1)).await; 49 Timer::after(Duration::from_secs(1)).await;
45 cortex_m::peripheral::SCB::sys_reset(); 50 cortex_m::peripheral::SCB::sys_reset();