diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 14:03:31 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 14:03:31 +0200 |
| commit | 36e00caf4dc70905b735531c0d5634addd026954 (patch) | |
| tree | 01d3bbb3b7f1ab522f9a1fc651f48197ce355927 /examples | |
| parent | c2aca45b8d3785007da20ce007d6a6e352fac1a0 (diff) | |
Align examples
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/boot/application/nrf/src/bin/a.rs | 12 | ||||
| -rw-r--r-- | examples/boot/application/rp/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/application/rp/src/bin/a.rs | 19 | ||||
| -rw-r--r-- | examples/boot/application/stm32f3/src/bin/a.rs | 12 | ||||
| -rw-r--r-- | examples/boot/application/stm32f7/src/bin/a.rs | 14 | ||||
| -rw-r--r-- | examples/boot/application/stm32h7/src/bin/a.rs | 15 | ||||
| -rw-r--r-- | examples/boot/application/stm32l1/src/bin/a.rs | 11 | ||||
| -rw-r--r-- | examples/boot/application/stm32l4/src/bin/a.rs | 9 | ||||
| -rw-r--r-- | examples/boot/application/stm32wl/src/bin/a.rs | 9 | ||||
| -rw-r--r-- | examples/boot/bootloader/nrf/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/bootloader/nrf/src/main.rs | 21 | ||||
| -rw-r--r-- | examples/boot/bootloader/rp/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/bootloader/rp/src/main.rs | 16 | ||||
| -rw-r--r-- | examples/boot/bootloader/stm32/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/boot/bootloader/stm32/src/main.rs | 19 |
15 files changed, 99 insertions, 62 deletions
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 090a05b23..06c237781 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -3,12 +3,13 @@ | |||
| 3 | #![macro_use] | 3 | #![macro_use] |
| 4 | #![feature(type_alias_impl_trait)] | 4 | #![feature(type_alias_impl_trait)] |
| 5 | 5 | ||
| 6 | use embassy_boot_nrf::FirmwareUpdater; | 6 | use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig}; |
| 7 | use embassy_embedded_hal::adapter::BlockingAsync; | 7 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | 9 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; |
| 10 | use embassy_nrf::nvmc::Nvmc; | 10 | use embassy_nrf::nvmc::Nvmc; |
| 11 | use embassy_nrf::wdt::{self, Watchdog}; | 11 | use embassy_nrf::wdt::{self, Watchdog}; |
| 12 | use embassy_sync::mutex::Mutex; | ||
| 12 | use panic_reset as _; | 13 | use panic_reset as _; |
| 13 | 14 | ||
| 14 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 15 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| @@ -45,9 +46,10 @@ async fn main(_spawner: Spawner) { | |||
| 45 | }; | 46 | }; |
| 46 | 47 | ||
| 47 | let nvmc = Nvmc::new(p.NVMC); | 48 | let nvmc = Nvmc::new(p.NVMC); |
| 48 | let mut nvmc = BlockingAsync::new(nvmc); | 49 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); |
| 49 | 50 | ||
| 50 | let mut updater = FirmwareUpdater::default(); | 51 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc); |
| 52 | let mut updater = FirmwareUpdater::new(config); | ||
| 51 | loop { | 53 | loop { |
| 52 | led.set_low(); | 54 | led.set_low(); |
| 53 | button.wait_for_any_edge().await; | 55 | button.wait_for_any_edge().await; |
| @@ -56,11 +58,11 @@ async fn main(_spawner: Spawner) { | |||
| 56 | for chunk in APP_B.chunks(4096) { | 58 | for chunk in APP_B.chunks(4096) { |
| 57 | let mut buf: [u8; 4096] = [0; 4096]; | 59 | let mut buf: [u8; 4096] = [0; 4096]; |
| 58 | buf[..chunk.len()].copy_from_slice(chunk); | 60 | buf[..chunk.len()].copy_from_slice(chunk); |
| 59 | updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); | 61 | updater.write_firmware(offset, &buf).await.unwrap(); |
| 60 | offset += chunk.len(); | 62 | offset += chunk.len(); |
| 61 | } | 63 | } |
| 62 | let mut magic = [0; 4]; | 64 | let mut magic = [0; 4]; |
| 63 | updater.mark_updated(&mut nvmc, &mut magic).await.unwrap(); | 65 | updater.mark_updated(&mut magic).await.unwrap(); |
| 64 | led.set_high(); | 66 | led.set_high(); |
| 65 | cortex_m::peripheral::SCB::sys_reset(); | 67 | cortex_m::peripheral::SCB::sys_reset(); |
| 66 | } | 68 | } |
diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index 64c2b8925..4a2c5dd8f 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml | |||
| @@ -20,6 +20,7 @@ embedded-hal = { version = "0.2.6" } | |||
| 20 | 20 | ||
| 21 | 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"] } |
| 22 | cortex-m-rt = "0.7.0" | 22 | cortex-m-rt = "0.7.0" |
| 23 | embedded-storage = "0.3.0" | ||
| 23 | 24 | ||
| 24 | [features] | 25 | [features] |
| 25 | default = ["panic-reset"] | 26 | default = ["panic-reset"] |
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs index 47f1d16d8..3fa908b63 100644 --- a/examples/boot/application/rp/src/bin/a.rs +++ b/examples/boot/application/rp/src/bin/a.rs | |||
| @@ -9,6 +9,9 @@ use embassy_rp::flash::Flash; | |||
| 9 | use embassy_rp::gpio::{Level, Output}; | 9 | use embassy_rp::gpio::{Level, Output}; |
| 10 | use embassy_rp::watchdog::Watchdog; | 10 | use embassy_rp::watchdog::Watchdog; |
| 11 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::{Duration, Timer}; |
| 12 | use embassy_sync::blocking_mutex::Mutex; | ||
| 13 | use core::cell::RefCell; | ||
| 14 | use embedded_storage::nor_flash::NorFlash; | ||
| 12 | #[cfg(feature = "panic-probe")] | 15 | #[cfg(feature = "panic-probe")] |
| 13 | use panic_probe as _; | 16 | use panic_probe as _; |
| 14 | #[cfg(feature = "panic-reset")] | 17 | #[cfg(feature = "panic-reset")] |
| @@ -26,9 +29,11 @@ async fn main(_s: Spawner) { | |||
| 26 | let mut watchdog = Watchdog::new(p.WATCHDOG); | 29 | let mut watchdog = Watchdog::new(p.WATCHDOG); |
| 27 | watchdog.start(Duration::from_secs(8)); | 30 | watchdog.start(Duration::from_secs(8)); |
| 28 | 31 | ||
| 29 | let mut flash: Flash<_, FLASH_SIZE> = Flash::new_blocking(p.FLASH); | 32 | let flash: Flash<_, FLASH_SIZE> = Flash::new(p.FLASH); |
| 33 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 30 | 34 | ||
| 31 | let mut updater = FirmwareUpdater::default(); | 35 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); |
| 36 | let mut updater = BlockingFirmwareUpdater::new(config); | ||
| 32 | 37 | ||
| 33 | Timer::after(Duration::from_secs(5)).await; | 38 | Timer::after(Duration::from_secs(5)).await; |
| 34 | watchdog.feed(); | 39 | watchdog.feed(); |
| @@ -36,8 +41,8 @@ async fn main(_s: Spawner) { | |||
| 36 | let mut offset = 0; | 41 | let mut offset = 0; |
| 37 | let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); | 42 | let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); |
| 38 | defmt::info!("preparing update"); | 43 | defmt::info!("preparing update"); |
| 39 | let mut writer = updater | 44 | let writer = updater |
| 40 | .prepare_update_blocking(&mut flash) | 45 | .prepare_update() |
| 41 | .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) | 46 | .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) |
| 42 | .unwrap(); | 47 | .unwrap(); |
| 43 | defmt::info!("writer created, starting write"); | 48 | defmt::info!("writer created, starting write"); |
| @@ -45,13 +50,13 @@ async fn main(_s: Spawner) { | |||
| 45 | buf.0[..chunk.len()].copy_from_slice(chunk); | 50 | buf.0[..chunk.len()].copy_from_slice(chunk); |
| 46 | defmt::info!("writing block at offset {}", offset); | 51 | defmt::info!("writing block at offset {}", offset); |
| 47 | writer | 52 | writer |
| 48 | .write_block_blocking(offset, &buf.0[..], &mut flash, 256) | 53 | .write(offset, &buf.0[..]) |
| 49 | .unwrap(); | 54 | .unwrap(); |
| 50 | offset += chunk.len(); | 55 | offset += chunk.len() as u32; |
| 51 | } | 56 | } |
| 52 | watchdog.feed(); | 57 | watchdog.feed(); |
| 53 | defmt::info!("firmware written, marking update"); | 58 | defmt::info!("firmware written, marking update"); |
| 54 | updater.mark_updated_blocking(&mut flash, &mut buf.0[..1]).unwrap(); | 59 | updater.mark_updated(&mut buf.0[..1]).unwrap(); |
| 55 | Timer::after(Duration::from_secs(2)).await; | 60 | Timer::after(Duration::from_secs(2)).await; |
| 56 | led.set_low(); | 61 | led.set_low(); |
| 57 | defmt::info!("update marked, resetting"); | 62 | defmt::info!("update marked, resetting"); |
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index 5db1dbb57..6a5c276fd 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs | |||
| @@ -4,7 +4,8 @@ | |||
| 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_sync::mutex::Mutex; | ||
| 8 | use embassy_embedded_hal::adapter::BlockingAsync; | 9 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 9 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 11 | use embassy_stm32::exti::ExtiInput; |
| @@ -18,7 +19,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 18 | async fn main(_spawner: Spawner) { | 19 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_stm32::init(Default::default()); | 20 | let p = embassy_stm32::init(Default::default()); |
| 20 | let flash = Flash::new_blocking(p.FLASH); | 21 | let flash = Flash::new_blocking(p.FLASH); |
| 21 | let mut flash = BlockingAsync::new(flash); | 22 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 22 | 23 | ||
| 23 | let button = Input::new(p.PC13, Pull::Up); | 24 | let button = Input::new(p.PC13, Pull::Up); |
| 24 | let mut button = ExtiInput::new(button, p.EXTI13); | 25 | let mut button = ExtiInput::new(button, p.EXTI13); |
| @@ -26,17 +27,18 @@ async fn main(_spawner: Spawner) { | |||
| 26 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); | 27 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); |
| 27 | led.set_high(); | 28 | led.set_high(); |
| 28 | 29 | ||
| 29 | let mut updater = FirmwareUpdater::default(); | 30 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); |
| 31 | let mut updater = FirmwareUpdater::new(config); | ||
| 30 | button.wait_for_falling_edge().await; | 32 | button.wait_for_falling_edge().await; |
| 31 | let mut offset = 0; | 33 | let mut offset = 0; |
| 32 | for chunk in APP_B.chunks(2048) { | 34 | for chunk in APP_B.chunks(2048) { |
| 33 | let mut buf: [u8; 2048] = [0; 2048]; | 35 | let mut buf: [u8; 2048] = [0; 2048]; |
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | 36 | buf[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); | 37 | updater.write_firmware(offset, &buf).await.unwrap(); |
| 36 | offset += chunk.len(); | 38 | offset += chunk.len(); |
| 37 | } | 39 | } |
| 38 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 40 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 39 | updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); | 41 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 40 | led.set_low(); | 42 | led.set_low(); |
| 41 | cortex_m::peripheral::SCB::sys_reset(); | 43 | cortex_m::peripheral::SCB::sys_reset(); |
| 42 | } | 44 | } |
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index 5d586445c..530683cac 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 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, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| @@ -16,7 +16,8 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 16 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 17 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 18 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 19 | let mut flash = Flash::new_blocking(p.FLASH); | 19 | let flash = Flash::new_blocking(p.FLASH); |
| 20 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 20 | 21 | ||
| 21 | let button = Input::new(p.PC13, Pull::Down); | 22 | let button = Input::new(p.PC13, Pull::Down); |
| 22 | let mut button = ExtiInput::new(button, p.EXTI13); | 23 | let mut button = ExtiInput::new(button, p.EXTI13); |
| @@ -24,20 +25,21 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); | 25 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); |
| 25 | led.set_high(); | 26 | led.set_high(); |
| 26 | 27 | ||
| 27 | let mut updater = FirmwareUpdater::default(); | 28 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); |
| 28 | let mut writer = updater.prepare_update_blocking(&mut flash).unwrap(); | 29 | let mut updater = BlockingFirmwareUpdater::new(config); |
| 30 | let mut writer = updater.prepare_update().unwrap(); | ||
| 29 | button.wait_for_rising_edge().await; | 31 | button.wait_for_rising_edge().await; |
| 30 | let mut offset = 0; | 32 | let mut offset = 0; |
| 31 | let mut buf = AlignedBuffer([0; 4096]); | 33 | let mut buf = AlignedBuffer([0; 4096]); |
| 32 | for chunk in APP_B.chunks(4096) { | 34 | for chunk in APP_B.chunks(4096) { |
| 33 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); | 35 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); |
| 34 | writer | 36 | writer |
| 35 | .write_block_blocking(offset, buf.as_ref(), &mut flash, chunk.len()) | 37 | .write(offset, buf.as_ref()) |
| 36 | .unwrap(); | 38 | .unwrap(); |
| 37 | offset += chunk.len(); | 39 | offset += chunk.len(); |
| 38 | } | 40 | } |
| 39 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 40 | updater.mark_updated_blocking(&mut flash, magic.as_mut()).unwrap(); | 42 | updater.mark_updated(magic.as_mut()).unwrap(); |
| 41 | led.set_low(); | 43 | led.set_low(); |
| 42 | cortex_m::peripheral::SCB::sys_reset(); | 44 | cortex_m::peripheral::SCB::sys_reset(); |
| 43 | } | 45 | } |
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index 202220223..e5f94310c 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 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, BlockingFirmwareUpdater, FirmwareUpdaterConfig}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| @@ -16,7 +16,8 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 16 | #[embassy_executor::main] | 16 | #[embassy_executor::main] |
| 17 | async fn main(_spawner: Spawner) { | 17 | async fn main(_spawner: Spawner) { |
| 18 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 19 | let mut flash = Flash::new_blocking(p.FLASH); | 19 | let flash = Flash::new_blocking(p.FLASH); |
| 20 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 20 | 21 | ||
| 21 | let button = Input::new(p.PC13, Pull::Down); | 22 | let button = Input::new(p.PC13, Pull::Down); |
| 22 | let mut button = ExtiInput::new(button, p.EXTI13); | 23 | let mut button = ExtiInput::new(button, p.EXTI13); |
| @@ -24,21 +25,21 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 25 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 25 | led.set_high(); | 26 | led.set_high(); |
| 26 | 27 | ||
| 27 | let mut updater = FirmwareUpdater::default(); | 28 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); |
| 28 | 29 | let mut updater = BlockingFirmwareUpdater::new(config); | |
| 29 | let mut writer = updater.prepare_update_blocking(&mut flash).unwrap(); | 30 | let mut writer = updater.prepare_update().unwrap(); |
| 30 | button.wait_for_rising_edge().await; | 31 | button.wait_for_rising_edge().await; |
| 31 | let mut offset = 0; | 32 | let mut offset = 0; |
| 32 | let mut buf = AlignedBuffer([0; 4096]); | 33 | let mut buf = AlignedBuffer([0; 4096]); |
| 33 | for chunk in APP_B.chunks(4096) { | 34 | for chunk in APP_B.chunks(4096) { |
| 34 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); | 35 | buf.as_mut()[..chunk.len()].copy_from_slice(chunk); |
| 35 | writer | 36 | writer |
| 36 | .write_block_blocking(offset, buf.as_ref(), &mut flash, 4096) | 37 | .write(offset, buf.as_ref()) |
| 37 | .unwrap(); | 38 | .unwrap(); |
| 38 | offset += chunk.len(); | 39 | offset += chunk.len(); |
| 39 | } | 40 | } |
| 40 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 41 | updater.mark_updated_blocking(&mut flash, magic.as_mut()).unwrap(); | 42 | updater.mark_updated(magic.as_mut()).unwrap(); |
| 42 | led.set_low(); | 43 | led.set_low(); |
| 43 | cortex_m::peripheral::SCB::sys_reset(); | 44 | cortex_m::peripheral::SCB::sys_reset(); |
| 44 | } | 45 | } |
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index 4033ac590..00ddda636 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 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; |
| @@ -19,7 +19,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 19 | async fn main(_spawner: Spawner) { | 19 | async fn main(_spawner: Spawner) { |
| 20 | let p = embassy_stm32::init(Default::default()); | 20 | let p = embassy_stm32::init(Default::default()); |
| 21 | let flash = Flash::new_blocking(p.FLASH); | 21 | let flash = Flash::new_blocking(p.FLASH); |
| 22 | let mut flash = BlockingAsync::new(flash); | 22 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 23 | 23 | ||
| 24 | let button = Input::new(p.PB2, Pull::Up); | 24 | let button = Input::new(p.PB2, Pull::Up); |
| 25 | let mut button = ExtiInput::new(button, p.EXTI2); | 25 | let mut button = ExtiInput::new(button, p.EXTI2); |
| @@ -28,18 +28,19 @@ async fn main(_spawner: Spawner) { | |||
| 28 | 28 | ||
| 29 | led.set_high(); | 29 | led.set_high(); |
| 30 | 30 | ||
| 31 | let mut updater = FirmwareUpdater::default(); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); |
| 32 | let mut updater = FirmwareUpdater::new(config); | ||
| 32 | button.wait_for_falling_edge().await; | 33 | button.wait_for_falling_edge().await; |
| 33 | let mut offset = 0; | 34 | let mut offset = 0; |
| 34 | for chunk in APP_B.chunks(128) { | 35 | for chunk in APP_B.chunks(128) { |
| 35 | let mut buf: [u8; 128] = [0; 128]; | 36 | let mut buf: [u8; 128] = [0; 128]; |
| 36 | buf[..chunk.len()].copy_from_slice(chunk); | 37 | buf[..chunk.len()].copy_from_slice(chunk); |
| 37 | updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); | 38 | updater.write_firmware(offset, &buf).await.unwrap(); |
| 38 | offset += chunk.len(); | 39 | offset += chunk.len(); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 42 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 42 | updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); | 43 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 43 | led.set_low(); | 44 | led.set_low(); |
| 44 | Timer::after(Duration::from_secs(1)).await; | 45 | Timer::after(Duration::from_secs(1)).await; |
| 45 | cortex_m::peripheral::SCB::sys_reset(); | 46 | cortex_m::peripheral::SCB::sys_reset(); |
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index 141d82afd..54579e4ac 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 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; |
| @@ -18,7 +18,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 18 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_stm32::init(Default::default()); | 19 | let p = embassy_stm32::init(Default::default()); |
| 20 | let flash = Flash::new_blocking(p.FLASH); | 20 | let flash = Flash::new_blocking(p.FLASH); |
| 21 | let mut flash = BlockingAsync::new(flash); | 21 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 22 | 22 | ||
| 23 | let button = Input::new(p.PC13, Pull::Up); | 23 | let button = Input::new(p.PC13, Pull::Up); |
| 24 | let mut button = ExtiInput::new(button, p.EXTI13); | 24 | let mut button = ExtiInput::new(button, p.EXTI13); |
| @@ -26,13 +26,14 @@ async fn main(_spawner: Spawner) { | |||
| 26 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 26 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 27 | led.set_high(); | 27 | led.set_high(); |
| 28 | 28 | ||
| 29 | let mut updater = FirmwareUpdater::default(); | 29 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); |
| 30 | let mut updater = FirmwareUpdater::new(config); | ||
| 30 | button.wait_for_falling_edge().await; | 31 | button.wait_for_falling_edge().await; |
| 31 | let mut offset = 0; | 32 | let mut offset = 0; |
| 32 | for chunk in APP_B.chunks(2048) { | 33 | for chunk in APP_B.chunks(2048) { |
| 33 | let mut buf: [u8; 2048] = [0; 2048]; | 34 | let mut buf: [u8; 2048] = [0; 2048]; |
| 34 | buf[..chunk.len()].copy_from_slice(chunk); | 35 | buf[..chunk.len()].copy_from_slice(chunk); |
| 35 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); | 36 | updater.write_firmware(offset, &buf).await.unwrap(); |
| 36 | offset += chunk.len(); | 37 | offset += chunk.len(); |
| 37 | } | 38 | } |
| 38 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 39 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index 5f48dbe51..0c6fa05f9 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -18,7 +18,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin"); | |||
| 18 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_stm32::init(Default::default()); | 19 | let p = embassy_stm32::init(Default::default()); |
| 20 | let flash = Flash::new_blocking(p.FLASH); | 20 | let flash = Flash::new_blocking(p.FLASH); |
| 21 | let mut flash = BlockingAsync::new(flash); | 21 | let mut flash = Mutex::new(BlockingAsync::new(flash)); |
| 22 | 22 | ||
| 23 | let button = Input::new(p.PA0, Pull::Up); | 23 | let button = Input::new(p.PA0, Pull::Up); |
| 24 | let mut button = ExtiInput::new(button, p.EXTI0); | 24 | let mut button = ExtiInput::new(button, p.EXTI0); |
| @@ -26,7 +26,8 @@ async fn main(_spawner: Spawner) { | |||
| 26 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); | 26 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); |
| 27 | led.set_high(); | 27 | led.set_high(); |
| 28 | 28 | ||
| 29 | let mut updater = FirmwareUpdater::default(); | 29 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); |
| 30 | let mut updater = FirmwareUpdater::new(config); | ||
| 30 | button.wait_for_falling_edge().await; | 31 | button.wait_for_falling_edge().await; |
| 31 | //defmt::info!("Starting update"); | 32 | //defmt::info!("Starting update"); |
| 32 | let mut offset = 0; | 33 | let mut offset = 0; |
| @@ -34,11 +35,11 @@ async fn main(_spawner: Spawner) { | |||
| 34 | let mut buf: [u8; 2048] = [0; 2048]; | 35 | let mut buf: [u8; 2048] = [0; 2048]; |
| 35 | buf[..chunk.len()].copy_from_slice(chunk); | 36 | buf[..chunk.len()].copy_from_slice(chunk); |
| 36 | // defmt::info!("Writing chunk at 0x{:x}", offset); | 37 | // defmt::info!("Writing chunk at 0x{:x}", offset); |
| 37 | updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); | 38 | updater.write_firmware(offset, &buf).await.unwrap(); |
| 38 | offset += chunk.len(); | 39 | offset += chunk.len(); |
| 39 | } | 40 | } |
| 40 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 41 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 41 | updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); | 42 | updater.mark_updated(magic.as_mut()).await.unwrap(); |
| 42 | //defmt::info!("Marked as updated"); | 43 | //defmt::info!("Marked as updated"); |
| 43 | led.set_low(); | 44 | led.set_low(); |
| 44 | cortex_m::peripheral::SCB::sys_reset(); | 45 | cortex_m::peripheral::SCB::sys_reset(); |
diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index 8c2fb4c5f..40656f359 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml | |||
| @@ -12,6 +12,7 @@ defmt-rtt = { version = "0.4", optional = true } | |||
| 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = ["nightly"] } | 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = ["nightly"] } |
| 13 | embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" } | 13 | embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { path = "../../../../embassy-sync" } | ||
| 15 | cortex-m-rt = { version = "0.7" } | 16 | cortex-m-rt = { version = "0.7" } |
| 16 | cfg-if = "1.0.0" | 17 | cfg-if = "1.0.0" |
| 17 | 18 | ||
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs index 8818a23b8..72c95c02a 100644 --- a/examples/boot/bootloader/nrf/src/main.rs +++ b/examples/boot/bootloader/nrf/src/main.rs | |||
| @@ -1,12 +1,15 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 4 | use cortex_m_rt::{entry, exception}; | 6 | use cortex_m_rt::{entry, exception}; |
| 5 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 6 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 7 | use embassy_boot_nrf::*; | 9 | use embassy_boot_nrf::*; |
| 8 | use embassy_nrf::nvmc::Nvmc; | 10 | use embassy_nrf::nvmc::Nvmc; |
| 9 | use embassy_nrf::wdt; | 11 | use embassy_nrf::wdt; |
| 12 | use embassy_sync::blocking_mutex::Mutex; | ||
| 10 | 13 | ||
| 11 | #[entry] | 14 | #[entry] |
| 12 | fn main() -> ! { | 15 | fn main() -> ! { |
| @@ -20,19 +23,21 @@ fn main() -> ! { | |||
| 20 | } | 23 | } |
| 21 | */ | 24 | */ |
| 22 | 25 | ||
| 23 | let mut bl = BootLoader::default(); | ||
| 24 | |||
| 25 | let mut wdt_config = wdt::Config::default(); | 26 | let mut wdt_config = wdt::Config::default(); |
| 26 | wdt_config.timeout_ticks = 32768 * 5; // timeout seconds | 27 | wdt_config.timeout_ticks = 32768 * 5; // timeout seconds |
| 27 | wdt_config.run_during_sleep = true; | 28 | wdt_config.run_during_sleep = true; |
| 28 | wdt_config.run_during_debug_halt = false; | 29 | wdt_config.run_during_debug_halt = false; |
| 29 | 30 | ||
| 30 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::new(WatchdogFlash::start( | 31 | let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config); |
| 31 | Nvmc::new(p.NVMC), | 32 | let flash = Mutex::new(RefCell::new(flash)); |
| 32 | p.WDT, | 33 | |
| 33 | wdt_config, | 34 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); |
| 34 | )))); | 35 | let active_offset = config.active.offset(); |
| 35 | unsafe { bl.load(start) } | 36 | let mut bl: BootLoader<_, _, _> = BootLoader::new(config); |
| 37 | |||
| 38 | bl.prepare(); | ||
| 39 | |||
| 40 | unsafe { bl.load(active_offset) } | ||
| 36 | } | 41 | } |
| 37 | 42 | ||
| 38 | #[no_mangle] | 43 | #[no_mangle] |
diff --git a/examples/boot/bootloader/rp/Cargo.toml b/examples/boot/bootloader/rp/Cargo.toml index bf9226993..8d60f18be 100644 --- a/examples/boot/bootloader/rp/Cargo.toml +++ b/examples/boot/bootloader/rp/Cargo.toml | |||
| @@ -11,6 +11,7 @@ defmt-rtt = { version = "0.4", optional = true } | |||
| 11 | 11 | ||
| 12 | embassy-rp = { path = "../../../../embassy-rp", features = ["nightly"] } | 12 | embassy-rp = { path = "../../../../embassy-rp", features = ["nightly"] } |
| 13 | embassy-boot-rp = { path = "../../../../embassy-boot/rp" } | 13 | embassy-boot-rp = { path = "../../../../embassy-boot/rp" } |
| 14 | embassy-sync = { path = "../../../../embassy-sync" } | ||
| 14 | embassy-time = { path = "../../../../embassy-time", features = ["nightly"] } | 15 | embassy-time = { path = "../../../../embassy-time", features = ["nightly"] } |
| 15 | 16 | ||
| 16 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 17 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
diff --git a/examples/boot/bootloader/rp/src/main.rs b/examples/boot/bootloader/rp/src/main.rs index 8129591fa..6a81db804 100644 --- a/examples/boot/bootloader/rp/src/main.rs +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 4 | use cortex_m_rt::{entry, exception}; | 6 | use cortex_m_rt::{entry, exception}; |
| 5 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 6 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 7 | use embassy_boot_rp::*; | 9 | use embassy_boot_rp::*; |
| 10 | use embassy_sync::blocking_mutex::Mutex; | ||
| 8 | use embassy_time::Duration; | 11 | use embassy_time::Duration; |
| 9 | 12 | ||
| 10 | const FLASH_SIZE: usize = 2 * 1024 * 1024; | 13 | const FLASH_SIZE: usize = 2 * 1024 * 1024; |
| @@ -21,13 +24,16 @@ fn main() -> ! { | |||
| 21 | } | 24 | } |
| 22 | */ | 25 | */ |
| 23 | 26 | ||
| 24 | let mut bl: BootLoader = BootLoader::default(); | ||
| 25 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); | 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); |
| 26 | let mut flash = BootFlash::new(flash); | 28 | let flash = Mutex::new(RefCell::new(flash)); |
| 27 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); | 29 | |
| 28 | core::mem::drop(flash); | 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); |
| 31 | let active_offset = config.active.offset(); | ||
| 32 | let mut bl: BootLoader<_, _, _> = BootLoader::new(config); | ||
| 33 | |||
| 34 | bl.prepare(); | ||
| 29 | 35 | ||
| 30 | unsafe { bl.load(start) } | 36 | unsafe { bl.load(embassy_rp::flash::FLASH_BASE as u32 + active_offset) } |
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | #[no_mangle] | 39 | #[no_mangle] |
diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index fbc80b34c..6436f2fee 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml | |||
| @@ -12,6 +12,7 @@ defmt-rtt = { version = "0.4", optional = true } | |||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = ["nightly"] } | 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = ["nightly"] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } | 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { path = "../../../../embassy-sync" } | ||
| 15 | cortex-m-rt = { version = "0.7" } | 16 | cortex-m-rt = { version = "0.7" } |
| 16 | embedded-storage = "0.3.0" | 17 | embedded-storage = "0.3.0" |
| 17 | embedded-storage-async = "0.4.0" | 18 | embedded-storage-async = "0.4.0" |
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index f81fdbc5f..262eed200 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs | |||
| @@ -1,11 +1,14 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 4 | use cortex_m_rt::{entry, exception}; | 6 | use cortex_m_rt::{entry, exception}; |
| 5 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 6 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 7 | use embassy_boot_stm32::*; | 9 | use embassy_boot_stm32::*; |
| 8 | use embassy_stm32::flash::Flash; | 10 | use embassy_stm32::flash::{Flash, BANK1_REGION}; |
| 11 | use embassy_sync::blocking_mutex::Mutex; | ||
| 9 | 12 | ||
| 10 | #[entry] | 13 | #[entry] |
| 11 | fn main() -> ! { | 14 | fn main() -> ! { |
| @@ -19,12 +22,16 @@ fn main() -> ! { | |||
| 19 | } | 22 | } |
| 20 | */ | 23 | */ |
| 21 | 24 | ||
| 22 | let mut bl: BootLoader<2048> = BootLoader::default(); | ||
| 23 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); |
| 24 | let mut flash = BootFlash::new(layout.bank1_region); | 26 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); |
| 25 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); | 27 | |
| 26 | core::mem::drop(flash); | 28 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); |
| 27 | unsafe { bl.load(start) } | 29 | let active_offset = config.active.offset(); |
| 30 | let mut bl: BootLoader<_, _, _, 2048> = BootLoader::new(config); | ||
| 31 | |||
| 32 | bl.prepare(); | ||
| 33 | |||
| 34 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | ||
| 28 | } | 35 | } |
| 29 | 36 | ||
| 30 | #[no_mangle] | 37 | #[no_mangle] |
