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

@ -3,11 +3,11 @@ use core::ptr::write_volatile;
use atomic_polyfill::{fence, Ordering};
use super::{FlashRegion, FLASH_SIZE, WRITE_SIZE};
use super::{FlashRegion, FlashSector, BANK1, FLASH_SIZE, 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;
const SECOND_BANK_OFFSET: usize = 0x0010_0000;
const fn is_dual_bank() -> bool {
@ -78,10 +78,6 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
res.unwrap()
}
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> {
let start_sector = (start_address - super::FLASH_BASE as u32) / ERASE_SIZE as u32;
let end_sector = (end_address - super::FLASH_BASE as u32) / ERASE_SIZE as u32;
@ -194,3 +190,13 @@ unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> 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,
}
}