From 095f5ef279b58da0e3b63559b4f1a039538673c9 Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 18 Apr 2023 15:49:33 +0200 Subject: [PATCH] Add MAX_ERASE_SIZE const in build script, and use it in flash-wide implementation of embedded-storage traits --- embassy-stm32/build.rs | 8 ++++++++ embassy-stm32/src/flash/common.rs | 6 +++--- embassy-stm32/src/flash/mod.rs | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) 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)]