stm32: Add async flash write/erase to f4
This commit is contained in:
@ -17,6 +17,10 @@ pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn lock() {
|
||||
pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true));
|
||||
if is_dual_bank() {
|
||||
@ -33,13 +37,13 @@ pub(crate) unsafe fn unlock() {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn begin_write() {
|
||||
pub(crate) unsafe fn enable_blocking_write() {
|
||||
assert_eq!(0, WRITE_SIZE % 4);
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn end_write() {}
|
||||
pub(crate) unsafe fn disable_blocking_write() {}
|
||||
|
||||
pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
|
||||
pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
|
||||
// We cannot have the write setup sequence in begin_write as it depends on the address
|
||||
let bank = if start_address < BANK1_REGION.end() {
|
||||
pac::FLASH.bank(0)
|
||||
@ -60,7 +64,7 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
|
||||
write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap()));
|
||||
address += val.len() as u32;
|
||||
|
||||
res = Some(blocking_wait_ready(bank));
|
||||
res = Some(wait_ready_blocking(bank));
|
||||
bank.sr().modify(|w| {
|
||||
if w.eop() {
|
||||
w.set_eop(true);
|
||||
@ -80,7 +84,7 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE])
|
||||
res.unwrap()
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> {
|
||||
pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> {
|
||||
let bank = pac::FLASH.bank(sector.bank as usize);
|
||||
bank.cr().modify(|w| {
|
||||
w.set_ser(true);
|
||||
@ -91,12 +95,9 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E
|
||||
w.set_start(true);
|
||||
});
|
||||
|
||||
let ret: Result<(), Error> = blocking_wait_ready(bank);
|
||||
|
||||
let ret: Result<(), Error> = wait_ready_blocking(bank);
|
||||
bank.cr().modify(|w| w.set_ser(false));
|
||||
|
||||
bank_clear_all_err(bank);
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
@ -141,7 +142,7 @@ unsafe fn bank_clear_all_err(bank: pac::flash::Bank) {
|
||||
});
|
||||
}
|
||||
|
||||
unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> Result<(), Error> {
|
||||
unsafe fn wait_ready_blocking(bank: pac::flash::Bank) -> Result<(), Error> {
|
||||
loop {
|
||||
let sr = bank.sr().read();
|
||||
|
||||
|
Reference in New Issue
Block a user