Expose get_sector in favor of is_eraseable_range

This commit is contained in:
Rasmus Melchior Jacobsen
2023-03-29 12:49:13 +02:00
parent 4ee3d15519
commit 69944675a3
7 changed files with 81 additions and 57 deletions

View File

@ -2,11 +2,11 @@ use core::ptr::write_volatile;
use atomic_polyfill::{fence, Ordering};
use super::{FlashRegion, WRITE_SIZE};
use super::{FlashRegion, FlashSector, BANK1, WRITE_SIZE};
use crate::flash::Error;
use crate::pac;
const ERASE_SIZE: usize = super::BANK1::ERASE_SIZE;
const ERASE_SIZE: usize = BANK1::SETTINGS.erase_size;
pub(crate) unsafe fn lock() {
#[cfg(any(flash_wl, flash_wb, flash_l4))]
@ -62,10 +62,6 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
blocking_wait_ready()
}
pub(crate) fn is_eraseable_range(start_address: u32, end_address: u32) -> bool {
start_address % ERASE_SIZE as u32 == 0 && end_address % ERASE_SIZE as u32 == 0
}
pub(crate) unsafe fn blocking_erase(start_address: u32, end_address: u32) -> Result<(), Error> {
for page in (start_address..end_address).step_by(ERASE_SIZE) {
#[cfg(any(flash_l0, flash_l1))]
@ -191,3 +187,13 @@ unsafe fn blocking_wait_ready() -> Result<(), Error> {
}
}
}
pub(crate) fn get_sector(address: u32) -> FlashSector {
let sector_size = BANK1::SETTINGS.erase_size as u32;
let index = address / sector_size;
FlashSector {
index: index as u8,
start: BANK1::SETTINGS.base as u32 + index * sector_size,
size: sector_size,
}
}