Let sector computation be shared across families

This commit is contained in:
Rasmus Melchior Jacobsen
2023-03-30 08:32:36 +02:00
parent e3c4e00be0
commit e7129371d0
10 changed files with 208 additions and 199 deletions

View File

@ -10,6 +10,7 @@ pub use crate::_generated::flash_regions::*;
pub use crate::pac::{FLASH_BASE, FLASH_SIZE, WRITE_SIZE};
pub struct FlashRegion {
pub bank: FlashBank,
pub base: u32,
pub size: u32,
pub erase_size: u32,
@ -19,15 +20,27 @@ pub struct FlashRegion {
#[derive(Debug, PartialEq)]
pub struct FlashSector {
pub index: u8,
pub bank: FlashBank,
pub index_in_bank: u8,
pub start: u32,
pub size: u32,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FlashBank {
Bank1 = 0,
Bank2 = 1,
Otp,
}
impl FlashRegion {
pub const fn end(&self) -> u32 {
self.base + self.size
}
pub const fn sectors(&self) -> u8 {
(self.size / self.erase_size) as u8
}
}
#[cfg_attr(any(flash_l0, flash_l1, flash_l4, flash_wl, flash_wb), path = "l.rs")]