diff options
| author | Ulf Lilleengen <[email protected]> | 2022-04-28 10:38:25 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-04-28 10:38:25 +0200 |
| commit | bd237a1f96680f2cdf411ef2ca80beaa6b09cc6a (patch) | |
| tree | 0eb34a0258b7b99a0988b3bfa1729b1aa448396e /embassy-boot/stm32/src/lib.rs | |
| parent | ba46df6825f35e0c3beb90f28b61f3dbe46e005e (diff) | |
Allow using separate page sizes for state and dfu
* Less generics on bootloader. Keep PAGE_SIZE as a common multiple of
DFU and ACTIVE page sizes.
* Document restriction
* Add unit tests for different page sizes
Diffstat (limited to 'embassy-boot/stm32/src/lib.rs')
| -rw-r--r-- | embassy-boot/stm32/src/lib.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs index 68220780c..82e32a97d 100644 --- a/embassy-boot/stm32/src/lib.rs +++ b/embassy-boot/stm32/src/lib.rs | |||
| @@ -1,17 +1,21 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![feature(generic_associated_types)] | 2 | #![feature(generic_associated_types)] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | #![allow(incomplete_features)] | ||
| 5 | #![feature(generic_const_exprs)] | ||
| 4 | 6 | ||
| 5 | mod fmt; | 7 | mod fmt; |
| 6 | 8 | ||
| 7 | pub use embassy_boot::{FirmwareUpdater, FlashProvider, Partition, SingleFlashProvider, State}; | 9 | pub use embassy_boot::{ |
| 8 | use embassy_stm32::flash::{ERASE_SIZE, ERASE_VALUE, WRITE_SIZE}; | 10 | FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State, |
| 11 | }; | ||
| 12 | use embedded_storage::nor_flash::NorFlash; | ||
| 9 | 13 | ||
| 10 | pub struct BootLoader { | 14 | pub struct BootLoader<const PAGE_SIZE: usize> { |
| 11 | boot: embassy_boot::BootLoader<ERASE_SIZE, WRITE_SIZE, ERASE_VALUE>, | 15 | boot: embassy_boot::BootLoader<PAGE_SIZE>, |
| 12 | } | 16 | } |
| 13 | 17 | ||
| 14 | impl BootLoader { | 18 | impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> { |
| 15 | /// Create a new bootloader instance using parameters from linker script | 19 | /// Create a new bootloader instance using parameters from linker script |
| 16 | pub fn default() -> Self { | 20 | pub fn default() -> Self { |
| 17 | extern "C" { | 21 | extern "C" { |
| @@ -57,7 +61,11 @@ impl BootLoader { | |||
| 57 | } | 61 | } |
| 58 | 62 | ||
| 59 | /// Boots the application | 63 | /// Boots the application |
| 60 | pub fn prepare<F: FlashProvider>(&mut self, flash: &mut F) -> usize { | 64 | pub fn prepare<F: FlashProvider>(&mut self, flash: &mut F) -> usize |
| 65 | where | ||
| 66 | [(); <<F as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE]:, | ||
| 67 | [(); <<F as FlashProvider>::ACTIVE as FlashConfig>::FLASH::ERASE_SIZE]:, | ||
| 68 | { | ||
| 61 | match self.boot.prepare_boot(flash) { | 69 | match self.boot.prepare_boot(flash) { |
| 62 | Ok(_) => self.boot.boot_address(), | 70 | Ok(_) => self.boot.boot_address(), |
| 63 | Err(_) => panic!("boot prepare error!"), | 71 | Err(_) => panic!("boot prepare error!"), |
