diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index c7d12e13..7959cca0 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -255,6 +255,14 @@ fn main() { ]; }); + let max_erase_size = flash_memory_regions + .iter() + .map(|region| region.settings.as_ref().unwrap().erase_size) + .max() + .unwrap(); + + g.extend(quote! { pub const MAX_ERASE_SIZE: u32 = #max_erase_size }); + g.extend(quote! { pub mod flash_regions { #flash_regions } }); // ======== diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 95fe2612..6d7f5597 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs @@ -2,7 +2,7 @@ use atomic_polyfill::{fence, Ordering}; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; -use super::{family, Error, FlashLayout, FlashRegion, FlashSector, FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; +use super::{family, Error, FlashLayout, FlashRegion, FlashSector, FLASH_BASE, FLASH_SIZE, MAX_ERASE_SIZE, WRITE_SIZE}; use crate::flash::FlashBank; use crate::Peripheral; @@ -179,8 +179,8 @@ impl embedded_storage::nor_flash::ReadNorFlash for Flash<'_> { } impl embedded_storage::nor_flash::NorFlash for Flash<'_> { - const WRITE_SIZE: usize = 8; - const ERASE_SIZE: usize = 2048; + const WRITE_SIZE: usize = WRITE_SIZE; + const ERASE_SIZE: usize = MAX_ERASE_SIZE; fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { self.blocking_write(offset, bytes) diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 231ff1f9..7d5596b1 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -7,6 +7,7 @@ mod common; pub use common::*; pub use crate::_generated::flash_regions::*; +pub use crate::_generated::MAX_ERASE_SIZE; pub use crate::pac::{FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; #[derive(Debug)]