diff options
| author | Ulf Lilleengen <[email protected]> | 2023-06-19 23:30:51 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2023-06-19 23:34:07 +0200 |
| commit | 161d3ce05c812f7ee951b6265735187b4994037a (patch) | |
| tree | c9e82c062ac089cf37cc175810a8a2041bddea0e /examples/boot/application | |
| parent | 76659d9003104f8edd2472a36149565e4a55c0e6 (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')
18 files changed, 78 insertions, 26 deletions
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index 5939a43b1..b98f73f39 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml | |||
| @@ -24,3 +24,4 @@ cortex-m-rt = "0.7.0" | |||
| 24 | [features] | 24 | [features] |
| 25 | ed25519-dalek = ["embassy-boot/ed25519-dalek"] | 25 | ed25519-dalek = ["embassy-boot/ed25519-dalek"] |
| 26 | ed25519-salty = ["embassy-boot/ed25519-salty"] | 26 | ed25519-salty = ["embassy-boot/ed25519-salty"] |
| 27 | skip-include = [] | ||
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 06c237781..021d77f3b 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -12,6 +12,9 @@ use embassy_nrf::wdt::{self, Watchdog}; | |||
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use panic_reset as _; | 13 | use panic_reset as _; |
| 14 | 14 | ||
| 15 | #[cfg(feature = "skip-include")] | ||
| 16 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 17 | #[cfg(not(feature = "skip-include"))] | ||
| 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 18 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 16 | 19 | ||
| 17 | #[embassy_executor::main] | 20 | #[embassy_executor::main] |
| @@ -55,13 +58,13 @@ async fn main(_spawner: Spawner) { | |||
| 55 | button.wait_for_any_edge().await; | 58 | button.wait_for_any_edge().await; |
| 56 | if button.is_low() { | 59 | if button.is_low() { |
| 57 | let mut offset = 0; | 60 | let mut offset = 0; |
| 61 | let mut magic = [0; 4]; | ||
| 58 | for chunk in APP_B.chunks(4096) { | 62 | for chunk in APP_B.chunks(4096) { |
| 59 | let mut buf: [u8; 4096] = [0; 4096]; | 63 | let mut buf: [u8; 4096] = [0; 4096]; |
| 60 | buf[..chunk.len()].copy_from_slice(chunk); | 64 | buf[..chunk.len()].copy_from_slice(chunk); |
| 61 | updater.write_firmware(offset, &buf).await.unwrap(); | 65 | updater.write_firmware(&mut magic, offset, &buf).await.unwrap(); |
| 62 | offset += chunk.len(); | 66 | offset += chunk.len(); |
| 63 | } | 67 | } |
| 64 | let mut magic = [0; 4]; | ||
| 65 | updater.mark_updated(&mut magic).await.unwrap(); | 68 | updater.mark_updated(&mut magic).await.unwrap(); |
| 66 | led.set_high(); | 69 | led.set_high(); |
| 67 | cortex_m::peripheral::SCB::sys_reset(); | 70 | cortex_m::peripheral::SCB::sys_reset(); |
diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index 4a2c5dd8f..007b6839c 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml | |||
| @@ -29,6 +29,7 @@ debug = [ | |||
| 29 | "embassy-boot-rp/defmt", | 29 | "embassy-boot-rp/defmt", |
| 30 | "panic-probe" | 30 | "panic-probe" |
| 31 | ] | 31 | ] |
| 32 | skip-include = [] | ||
| 32 | 33 | ||
| 33 | [profile.release] | 34 | [profile.release] |
| 34 | debug = true | 35 | debug = true |
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs index 69850069b..c8497494c 100644 --- a/examples/boot/application/rp/src/bin/a.rs +++ b/examples/boot/application/rp/src/bin/a.rs | |||
| @@ -18,7 +18,11 @@ use panic_probe as _; | |||
| 18 | #[cfg(feature = "panic-reset")] | 18 | #[cfg(feature = "panic-reset")] |
| 19 | use panic_reset as _; | 19 | use panic_reset as _; |
| 20 | 20 | ||
| 21 | #[cfg(feature = "skip-include")] | ||
| 22 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 23 | #[cfg(not(feature = "skip-include"))] | ||
| 21 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 24 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 25 | |||
| 22 | const FLASH_SIZE: usize = 2 * 1024 * 1024; | 26 | const FLASH_SIZE: usize = 2 * 1024 * 1024; |
| 23 | 27 | ||
| 24 | #[embassy_executor::main] | 28 | #[embassy_executor::main] |
| @@ -43,7 +47,7 @@ async fn main(_s: Spawner) { | |||
| 43 | let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); | 47 | let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); |
| 44 | defmt::info!("preparing update"); | 48 | defmt::info!("preparing update"); |
| 45 | let writer = updater | 49 | let writer = updater |
| 46 | .prepare_update() | 50 | .prepare_update(&mut buf.0[..1]) |
| 47 | .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) | 51 | .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) |
| 48 | .unwrap(); | 52 | .unwrap(); |
| 49 | defmt::info!("writer created, starting write"); | 53 | defmt::info!("writer created, starting write"); |
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index 24abd90d4..5b3faf8f8 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml | |||
| @@ -26,3 +26,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 26 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 27 | "embassy-boot-stm32/defmt", |
| 28 | ] | 28 | ] |
| 29 | skip-include = [] | ||
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index c94676f09..c0a11d699 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs | |||
| @@ -13,6 +13,9 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | |||
| 13 | use embassy_sync::mutex::Mutex; | 13 | use embassy_sync::mutex::Mutex; |
| 14 | use panic_reset as _; | 14 | use panic_reset as _; |
| 15 | 15 | ||
| 16 | #[cfg(feature = "skip-include")] | ||
| 17 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 18 | #[cfg(not(feature = "skip-include"))] | ||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 19 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 20 | ||
| 18 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| @@ -31,13 +34,13 @@ async fn main(_spawner: Spawner) { | |||
| 31 | let mut updater = FirmwareUpdater::new(config); | 34 | let mut updater = FirmwareUpdater::new(config); |
| 32 | button.wait_for_falling_edge().await; | 35 | button.wait_for_falling_edge().await; |
| 33 | let mut offset = 0; | 36 | let mut offset = 0; |
| 37 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 34 | for chunk in APP_B.chunks(2048) { | 38 | for chunk in APP_B.chunks(2048) { |
| 35 | let mut buf: [u8; 2048] = [0; 2048]; | 39 | let mut buf: [u8; 2048] = [0; 2048]; |
| 36 | buf[..chunk.len()].copy_from_slice(chunk); | 40 | buf[..chunk.len()].copy_from_slice(chunk); |
| 37 | updater.write_firmware(offset, &buf).await.unwrap(); | 41 | updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap(); |
| 38 | offset += chunk.len(); | 42 | offset += chunk.len(); |
| 39 | } | 43 | } |
| 40 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 41 | updater.mark_updated(magic.as_mut()).await.unwrap(); | 44 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 42 | led.set_low(); | 45 | led.set_low(); |
| 43 | cortex_m::peripheral::SCB::sys_reset(); | 46 | cortex_m::peripheral::SCB::sys_reset(); |
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index 529a01aad..b6a6f9cd8 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml | |||
| @@ -16,6 +16,7 @@ defmt = { version = "0.3", optional = true } | |||
| 16 | defmt-rtt = { version = "0.4", optional = true } | 16 | defmt-rtt = { version = "0.4", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 17 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 18 | embedded-hal = { version = "0.2.6" } |
| 19 | embedded-storage = "0.3.0" | ||
| 19 | 20 | ||
| 20 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 21 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 21 | cortex-m-rt = "0.7.0" | 22 | cortex-m-rt = "0.7.0" |
| @@ -26,3 +27,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 27 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 28 | "embassy-boot-stm32/defmt", |
| 28 | ] | 29 | ] |
| 30 | skip-include = [] | ||
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index fc2702c91..dea682a96 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::cell::RefCell; | ||
| 6 | |||
| 5 | #[cfg(feature = "defmt-rtt")] | 7 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 8 | use defmt_rtt::*; |
| 7 | use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; | 9 | use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; |
| @@ -9,8 +11,13 @@ use embassy_executor::Spawner; | |||
| 9 | use embassy_stm32::exti::ExtiInput; | 11 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 12 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 13 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | ||
| 15 | use embedded_storage::nor_flash::NorFlash; | ||
| 12 | use panic_reset as _; | 16 | use panic_reset as _; |
| 13 | 17 | ||
| 18 | #[cfg(feature = "skip-include")] | ||
| 19 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 20 | #[cfg(not(feature = "skip-include"))] | ||
| 14 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 21 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 15 | 22 | ||
| 16 | #[embassy_executor::main] | 23 | #[embassy_executor::main] |
| @@ -27,16 +34,16 @@ async fn main(_spawner: Spawner) { | |||
| 27 | 34 | ||
| 28 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 35 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); |
| 29 | let mut updater = BlockingFirmwareUpdater::new(config); | 36 | let mut updater = BlockingFirmwareUpdater::new(config); |
| 30 | let mut writer = updater.prepare_update().unwrap(); | 37 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 38 | let writer = updater.prepare_update(magic.as_mut()).unwrap(); | ||
| 31 | button.wait_for_rising_edge().await; | 39 | button.wait_for_rising_edge().await; |
| 32 | let mut offset = 0; | 40 | let mut offset = 0; |
| 33 | let mut buf = AlignedBuffer([0; 4096]); | 41 | let mut buf = AlignedBuffer([0; 4096]); |
| 34 | for chunk in APP_B.chunks(4096) { | 42 | for chunk in APP_B.chunks(4096) { |
| 35 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); | 43 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); |
| 36 | writer.write(offset, buf.as_ref()).unwrap(); | 44 | writer.write(offset, buf.as_ref()).unwrap(); |
| 37 | offset += chunk.len(); | 45 | offset += chunk.len() as u32; |
| 38 | } | 46 | } |
| 39 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 40 | updater.mark_updated(magic.as_mut()).unwrap(); | 47 | updater.mark_updated(magic.as_mut()).unwrap(); |
| 41 | led.set_low(); | 48 | led.set_low(); |
| 42 | cortex_m::peripheral::SCB::sys_reset(); | 49 | cortex_m::peripheral::SCB::sys_reset(); |
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index d7539a53f..0a7e19b1d 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml | |||
| @@ -16,6 +16,7 @@ defmt = { version = "0.3", optional = true } | |||
| 16 | defmt-rtt = { version = "0.4", optional = true } | 16 | defmt-rtt = { version = "0.4", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 17 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 18 | embedded-hal = { version = "0.2.6" } |
| 19 | embedded-storage = "0.3.0" | ||
| 19 | 20 | ||
| 20 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 21 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 21 | cortex-m-rt = "0.7.0" | 22 | cortex-m-rt = "0.7.0" |
| @@ -26,3 +27,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 27 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 28 | "embassy-boot-stm32/defmt", |
| 28 | ] | 29 | ] |
| 30 | skip-include = [] | ||
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index 1a54464d0..719176692 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::cell::RefCell; | ||
| 6 | |||
| 5 | #[cfg(feature = "defmt-rtt")] | 7 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 8 | use defmt_rtt::*; |
| 7 | use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; | 9 | use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; |
| @@ -9,8 +11,13 @@ use embassy_executor::Spawner; | |||
| 9 | use embassy_stm32::exti::ExtiInput; | 11 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 12 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 13 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | ||
| 15 | use embedded_storage::nor_flash::NorFlash; | ||
| 12 | use panic_reset as _; | 16 | use panic_reset as _; |
| 13 | 17 | ||
| 18 | #[cfg(feature = "skip-include")] | ||
| 19 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 20 | #[cfg(not(feature = "skip-include"))] | ||
| 14 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 21 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 15 | 22 | ||
| 16 | #[embassy_executor::main] | 23 | #[embassy_executor::main] |
| @@ -26,17 +33,17 @@ async fn main(_spawner: Spawner) { | |||
| 26 | led.set_high(); | 33 | led.set_high(); |
| 27 | 34 | ||
| 28 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 35 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); |
| 36 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 29 | let mut updater = BlockingFirmwareUpdater::new(config); | 37 | let mut updater = BlockingFirmwareUpdater::new(config); |
| 30 | let mut writer = updater.prepare_update().unwrap(); | 38 | let writer = updater.prepare_update(magic.as_mut()).unwrap(); |
| 31 | button.wait_for_rising_edge().await; | 39 | button.wait_for_rising_edge().await; |
| 32 | let mut offset = 0; | 40 | let mut offset = 0; |
| 33 | let mut buf = AlignedBuffer([0; 4096]); | 41 | let mut buf = AlignedBuffer([0; 4096]); |
| 34 | for chunk in APP_B.chunks(4096) { | 42 | for chunk in APP_B.chunks(4096) { |
| 35 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); | 43 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); |
| 36 | writer.write(offset, buf.as_ref()).unwrap(); | 44 | writer.write(offset, buf.as_ref()).unwrap(); |
| 37 | offset += chunk.len(); | 45 | offset += chunk.len() as u32; |
| 38 | } | 46 | } |
| 39 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 40 | updater.mark_updated(magic.as_mut()).unwrap(); | 47 | updater.mark_updated(magic.as_mut()).unwrap(); |
| 41 | led.set_low(); | 48 | led.set_low(); |
| 42 | cortex_m::peripheral::SCB::sys_reset(); | 49 | cortex_m::peripheral::SCB::sys_reset(); |
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index e90da259b..998df4dc0 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml | |||
| @@ -26,3 +26,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 26 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 27 | "embassy-boot-stm32/defmt", |
| 28 | ] | 28 | ] |
| 29 | skip-include = [] | ||
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")] |
| 6 | use defmt_rtt::*; | 6 | use defmt_rtt::*; |
| 7 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; | 7 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig}; |
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | ||
| 13 | use embassy_time::{Duration, Timer}; | 14 | use embassy_time::{Duration, Timer}; |
| 14 | use panic_reset as _; | 15 | use panic_reset as _; |
| 15 | 16 | ||
| 17 | #[cfg(feature = "skip-include")] | ||
| 18 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 19 | #[cfg(not(feature = "skip-include"))] | ||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 20 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 21 | ||
| 18 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 19 | async fn main(_spawner: Spawner) { | 23 | async 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(); |
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index 8ac0fac85..10b58c172 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml | |||
| @@ -26,3 +26,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 26 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 27 | "embassy-boot-stm32/defmt", |
| 28 | ] | 28 | ] |
| 29 | skip-include = [] | ||
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index 00ddda636..1e9bf3cb9 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs | |||
| @@ -10,9 +10,13 @@ use embassy_executor::Spawner; | |||
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | ||
| 13 | use embassy_time::{Duration, Timer}; | 14 | use embassy_time::{Duration, Timer}; |
| 14 | use panic_reset as _; | 15 | use panic_reset as _; |
| 15 | 16 | ||
| 17 | #[cfg(feature = "skip-include")] | ||
| 18 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 19 | #[cfg(not(feature = "skip-include"))] | ||
| 16 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 20 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 17 | 21 | ||
| 18 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| @@ -31,15 +35,15 @@ async fn main(_spawner: Spawner) { | |||
| 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 35 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); |
| 32 | let mut updater = FirmwareUpdater::new(config); | 36 | let mut updater = FirmwareUpdater::new(config); |
| 33 | button.wait_for_falling_edge().await; | 37 | button.wait_for_falling_edge().await; |
| 38 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 34 | let mut offset = 0; | 39 | let mut offset = 0; |
| 35 | for chunk in APP_B.chunks(128) { | 40 | for chunk in APP_B.chunks(128) { |
| 36 | let mut buf: [u8; 128] = [0; 128]; | 41 | let mut buf: [u8; 128] = [0; 128]; |
| 37 | buf[..chunk.len()].copy_from_slice(chunk); | 42 | buf[..chunk.len()].copy_from_slice(chunk); |
| 38 | updater.write_firmware(offset, &buf).await.unwrap(); | 43 | updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap(); |
| 39 | offset += chunk.len(); | 44 | offset += chunk.len(); |
| 40 | } | 45 | } |
| 41 | 46 | ||
| 42 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 43 | updater.mark_updated(magic.as_mut()).await.unwrap(); | 47 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 44 | led.set_low(); | 48 | led.set_low(); |
| 45 | Timer::after(Duration::from_secs(1)).await; | 49 | Timer::after(Duration::from_secs(1)).await; |
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index ec79acdeb..713a6527e 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml | |||
| @@ -26,3 +26,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 26 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 27 | "embassy-boot-stm32/defmt", |
| 28 | ] | 28 | ] |
| 29 | skip-include = [] | ||
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index 54579e4ac..a514ab5be 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs | |||
| @@ -10,8 +10,12 @@ use embassy_executor::Spawner; | |||
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | ||
| 13 | use panic_reset as _; | 14 | use panic_reset as _; |
| 14 | 15 | ||
| 16 | #[cfg(feature = "skip-include")] | ||
| 17 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 18 | #[cfg(not(feature = "skip-include"))] | ||
| 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 19 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 16 | 20 | ||
| 17 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| @@ -29,15 +33,15 @@ async fn main(_spawner: Spawner) { | |||
| 29 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); |
| 30 | let mut updater = FirmwareUpdater::new(config); | 34 | let mut updater = FirmwareUpdater::new(config); |
| 31 | button.wait_for_falling_edge().await; | 35 | button.wait_for_falling_edge().await; |
| 36 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 32 | let mut offset = 0; | 37 | let mut offset = 0; |
| 33 | for chunk in APP_B.chunks(2048) { | 38 | for chunk in APP_B.chunks(2048) { |
| 34 | let mut buf: [u8; 2048] = [0; 2048]; | 39 | let mut buf: [u8; 2048] = [0; 2048]; |
| 35 | buf[..chunk.len()].copy_from_slice(chunk); | 40 | buf[..chunk.len()].copy_from_slice(chunk); |
| 36 | updater.write_firmware(offset, &buf).await.unwrap(); | 41 | updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap(); |
| 37 | offset += chunk.len(); | 42 | offset += chunk.len(); |
| 38 | } | 43 | } |
| 39 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 44 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 40 | updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); | ||
| 41 | led.set_low(); | 45 | led.set_low(); |
| 42 | cortex_m::peripheral::SCB::sys_reset(); | 46 | cortex_m::peripheral::SCB::sys_reset(); |
| 43 | } | 47 | } |
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index dfaece6cf..4c8bbd73f 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml | |||
| @@ -26,3 +26,4 @@ defmt = [ | |||
| 26 | "embassy-stm32/defmt", | 26 | "embassy-stm32/defmt", |
| 27 | "embassy-boot-stm32/defmt", | 27 | "embassy-boot-stm32/defmt", |
| 28 | ] | 28 | ] |
| 29 | skip-include = [] | ||
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index 0c6fa05f9..52a197a5c 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -4,21 +4,25 @@ | |||
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 5 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 6 | use defmt_rtt::*; |
| 7 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; | 7 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig}; |
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | 8 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | ||
| 13 | use panic_reset as _; | 14 | use panic_reset as _; |
| 14 | 15 | ||
| 16 | #[cfg(feature = "skip-include")] | ||
| 17 | static APP_B: &[u8] = &[0, 1, 2, 3]; | ||
| 18 | #[cfg(not(feature = "skip-include"))] | ||
| 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 19 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 16 | 20 | ||
| 17 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 22 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_stm32::init(Default::default()); | 23 | let p = embassy_stm32::init(Default::default()); |
| 20 | let flash = Flash::new_blocking(p.FLASH); | 24 | let flash = Flash::new_blocking(p.FLASH); |
| 21 | let mut flash = Mutex::new(BlockingAsync::new(flash)); | 25 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 22 | 26 | ||
| 23 | let button = Input::new(p.PA0, Pull::Up); | 27 | let button = Input::new(p.PA0, Pull::Up); |
| 24 | let mut button = ExtiInput::new(button, p.EXTI0); | 28 | let mut button = ExtiInput::new(button, p.EXTI0); |
| @@ -30,15 +34,15 @@ async fn main(_spawner: Spawner) { | |||
| 30 | let mut updater = FirmwareUpdater::new(config); | 34 | let mut updater = FirmwareUpdater::new(config); |
| 31 | button.wait_for_falling_edge().await; | 35 | button.wait_for_falling_edge().await; |
| 32 | //defmt::info!("Starting update"); | 36 | //defmt::info!("Starting update"); |
| 37 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 33 | let mut offset = 0; | 38 | let mut offset = 0; |
| 34 | for chunk in APP_B.chunks(2048) { | 39 | for chunk in APP_B.chunks(2048) { |
| 35 | let mut buf: [u8; 2048] = [0; 2048]; | 40 | let mut buf: [u8; 2048] = [0; 2048]; |
| 36 | buf[..chunk.len()].copy_from_slice(chunk); | 41 | buf[..chunk.len()].copy_from_slice(chunk); |
| 37 | // defmt::info!("Writing chunk at 0x{:x}", offset); | 42 | // defmt::info!("Writing chunk at 0x{:x}", offset); |
| 38 | updater.write_firmware(offset, &buf).await.unwrap(); | 43 | updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap(); |
| 39 | offset += chunk.len(); | 44 | offset += chunk.len(); |
| 40 | } | 45 | } |
| 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 42 | updater.mark_updated(magic.as_mut()).await.unwrap(); | 46 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 43 | //defmt::info!("Marked as updated"); | 47 | //defmt::info!("Marked as updated"); |
| 44 | led.set_low(); | 48 | led.set_low(); |
