Expose get_sector in favor of is_eraseable_range
This commit is contained in:
@ -3,11 +3,11 @@ use core::ptr::write_volatile;
|
||||
|
||||
use atomic_polyfill::{fence, Ordering};
|
||||
|
||||
use super::{FlashRegion, BANK1, WRITE_SIZE};
|
||||
use super::{FlashRegion, FlashSector, BANK1, WRITE_SIZE};
|
||||
use crate::flash::Error;
|
||||
use crate::pac;
|
||||
|
||||
const ERASE_SIZE: usize = BANK1::ERASE_SIZE;
|
||||
const ERASE_SIZE: usize = BANK1::SETTINGS.erase_size;
|
||||
|
||||
pub(crate) unsafe fn lock() {
|
||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||
@ -41,10 +41,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) {
|
||||
pac::FLASH.cr().modify(|w| {
|
||||
@ -107,3 +103,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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user