diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index 74c54ff33..de53f6c8f 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs @@ -4,7 +4,7 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::mutex::Mutex; use super::{ - ensure_sector_aligned, family, get_sector, read_blocking, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE, + blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE, MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE, }; @@ -112,7 +112,7 @@ foreach_flash_region! { ($type_name:ident, $write_size:literal, $erase_size:literal) => { impl crate::_generated::flash_regions::$type_name<'_, Async> { pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { - read_blocking(self.0.base, self.0.size, offset, bytes) + blocking_read(self.0.base, self.0.size, offset, bytes) } pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 8ae72ebcb..54c8d6812 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs @@ -54,12 +54,12 @@ impl<'d, MODE> Flash<'d, MODE> { } pub fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { - read_blocking(FLASH_BASE as u32, FLASH_SIZE as u32, offset, bytes) + blocking_read(FLASH_BASE as u32, FLASH_SIZE as u32, offset, bytes) } - pub fn write_blocking(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { + pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { unsafe { - write_blocking( + blocking_write( FLASH_BASE as u32, FLASH_SIZE as u32, offset, @@ -69,8 +69,8 @@ impl<'d, MODE> Flash<'d, MODE> { } } - pub fn erase_blocking(&mut self, from: u32, to: u32) -> Result<(), Error> { - unsafe { erase_blocking(FLASH_BASE as u32, from, to, erase_sector_unlocked) } + pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { + unsafe { blocking_erase(FLASH_BASE as u32, from, to, erase_sector_unlocked) } } } @@ -83,7 +83,7 @@ impl interrupt::Handler for InterruptHandler { } } -pub(super) fn read_blocking(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { +pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { if offset + bytes.len() as u32 > size { return Err(Error::Size); } @@ -97,7 +97,7 @@ pub(super) fn read_blocking(base: u32, size: u32, offset: u32, bytes: &mut [u8]) Ok(()) } -pub(super) unsafe fn write_blocking( +pub(super) unsafe fn blocking_write( base: u32, size: u32, offset: u32, @@ -135,14 +135,14 @@ pub(super) unsafe fn write_chunk_unlocked(address: u32, chunk: &[u8]) -> Result< family::lock(); }); - family::write_blocking(address, chunk.try_into().unwrap()) + family::blocking_write(address, chunk.try_into().unwrap()) } pub(super) unsafe fn write_chunk_with_critical_section(address: u32, chunk: &[u8]) -> Result<(), Error> { critical_section::with(|_| write_chunk_unlocked(address, chunk)) } -pub(super) unsafe fn erase_blocking( +pub(super) unsafe fn blocking_erase( base: u32, from: u32, to: u32, @@ -174,7 +174,7 @@ pub(super) unsafe fn erase_sector_unlocked(sector: &FlashSector) -> Result<(), E let _on_drop = OnDrop::new(|| family::lock()); - family::erase_sector_blocking(§or) + family::blocking_erase_sector(§or) } pub(super) unsafe fn erase_sector_with_critical_section(sector: &FlashSector) -> Result<(), Error> { @@ -246,29 +246,29 @@ impl embedded_storage::nor_flash::NorFlash for Flash<'_, MODE> { const ERASE_SIZE: usize = MAX_ERASE_SIZE; fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { - self.write_blocking(offset, bytes) + self.blocking_write(offset, bytes) } fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { - self.erase_blocking(from, to) + self.blocking_erase(from, to) } } foreach_flash_region! { ($type_name:ident, $write_size:literal, $erase_size:literal) => { impl crate::_generated::flash_regions::$type_name<'_, MODE> { - pub fn read_blocking(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { - read_blocking(self.0.base, self.0.size, offset, bytes) + pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { + blocking_read(self.0.base, self.0.size, offset, bytes) } } impl crate::_generated::flash_regions::$type_name<'_, Blocking> { - pub fn write_blocking(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { - unsafe { write_blocking(self.0.base, self.0.size, offset, bytes, write_chunk_with_critical_section) } + pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { + unsafe { blocking_write(self.0.base, self.0.size, offset, bytes, write_chunk_with_critical_section) } } - pub fn erase_blocking(&mut self, from: u32, to: u32) -> Result<(), Error> { - unsafe { erase_blocking(self.0.base, from, to, erase_sector_with_critical_section) } + pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> { + unsafe { blocking_erase(self.0.base, from, to, erase_sector_with_critical_section) } } } @@ -280,7 +280,7 @@ foreach_flash_region! { const READ_SIZE: usize = READ_SIZE; fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { - self.read_blocking(offset, bytes) + self.blocking_read(offset, bytes) } fn capacity(&self) -> usize { @@ -293,11 +293,11 @@ foreach_flash_region! { const ERASE_SIZE: usize = $erase_size; fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { - self.write_blocking(offset, bytes) + self.blocking_write(offset, bytes) } fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { - self.erase_blocking(from, to) + self.blocking_erase(from, to) } } }; diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs index cd17486e6..9adf3fab2 100644 --- a/embassy-stm32/src/flash/f0.rs +++ b/embassy-stm32/src/flash/f0.rs @@ -36,7 +36,7 @@ pub(crate) unsafe fn disable_blocking_write() { pac::FLASH.cr().write(|w| w.set_pg(false)); } -pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { let mut address = start_address; for chunk in buf.chunks(2) { write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap())); @@ -46,10 +46,10 @@ pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) fence(Ordering::SeqCst); } - wait_ready_blocking() + blocking_wait_ready() } -pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { pac::FLASH.cr().modify(|w| { w.set_per(true); }); @@ -60,7 +60,7 @@ pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), E w.set_strt(true); }); - let mut ret: Result<(), Error> = wait_ready_blocking(); + let mut ret: Result<(), Error> = blocking_wait_ready(); if !pac::FLASH.sr().read().eop() { trace!("FLASH: EOP not set"); @@ -92,7 +92,7 @@ pub(crate) unsafe fn clear_all_err() { }); } -unsafe fn wait_ready_blocking() -> Result<(), Error> { +unsafe fn blocking_wait_ready() -> Result<(), Error> { loop { let sr = pac::FLASH.sr().read(); diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index 4ce391288..b052b4d41 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs @@ -36,7 +36,7 @@ pub(crate) unsafe fn disable_blocking_write() { pac::FLASH.cr().write(|w| w.set_pg(false)); } -pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { let mut address = start_address; for chunk in buf.chunks(2) { write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap())); @@ -46,10 +46,10 @@ pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) fence(Ordering::SeqCst); } - wait_ready_blocking() + blocking_wait_ready() } -pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { pac::FLASH.cr().modify(|w| { w.set_per(true); }); @@ -60,7 +60,7 @@ pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), E w.set_strt(true); }); - let mut ret: Result<(), Error> = wait_ready_blocking(); + let mut ret: Result<(), Error> = blocking_wait_ready(); if !pac::FLASH.sr().read().eop() { trace!("FLASH: EOP not set"); @@ -92,7 +92,7 @@ pub(crate) unsafe fn clear_all_err() { }); } -unsafe fn wait_ready_blocking() -> Result<(), Error> { +unsafe fn blocking_wait_ready() -> Result<(), Error> { loop { let sr = pac::FLASH.sr().read(); diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 875bb912b..5e0e96204 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -108,15 +108,15 @@ mod alt_regions { macro_rules! foreach_altflash_region { ($type_name:ident, $region:ident) => { impl $type_name<'_, MODE> { - pub fn read_blocking(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { - crate::flash::common::read_blocking(self.0.base, self.0.size, offset, bytes) + pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { + crate::flash::common::blocking_read(self.0.base, self.0.size, offset, bytes) } } #[cfg(feature = "nightly")] impl $type_name<'_, Async> { pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { - self.read_blocking(offset, bytes) + self.blocking_read(offset, bytes) } pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> { @@ -138,7 +138,7 @@ mod alt_regions { const READ_SIZE: usize = crate::flash::READ_SIZE; fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { - self.read_blocking(offset, bytes) + self.blocking_read(offset, bytes) } fn capacity(&self) -> usize { @@ -299,9 +299,9 @@ pub(crate) async unsafe fn write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> wait_ready().await } -pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { write_start(start_address, buf); - wait_ready_blocking() + blocking_wait_ready() } unsafe fn write_start(start_address: u32, buf: &[u8; WRITE_SIZE]) { @@ -340,7 +340,7 @@ pub(crate) async unsafe fn erase_sector(sector: &FlashSector) -> Result<(), Erro ret } -pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { save_data_cache_state(); pac::FLASH.cr().modify(|w| { @@ -352,7 +352,7 @@ pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), E w.set_strt(true); }); - let ret: Result<(), Error> = wait_ready_blocking(); + let ret: Result<(), Error> = blocking_wait_ready(); clear_all_err(); restore_data_cache_state(); ret @@ -386,7 +386,7 @@ pub(crate) async unsafe fn wait_ready() -> Result<(), Error> { .await } -unsafe fn wait_ready_blocking() -> Result<(), Error> { +unsafe fn blocking_wait_ready() -> Result<(), Error> { loop { let sr = pac::FLASH.sr().read(); diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index ab518bf89..f0c6bf81d 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -38,7 +38,7 @@ pub(crate) unsafe fn disable_blocking_write() { pac::FLASH.cr().write(|w| w.set_pg(false)); } -pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { let mut address = start_address; for val in buf.chunks(4) { write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap())); @@ -48,10 +48,10 @@ pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) fence(Ordering::SeqCst); } - wait_ready_blocking() + blocking_wait_ready() } -pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { pac::FLASH.cr().modify(|w| { w.set_ser(true); w.set_snb(sector.index_in_bank) @@ -61,7 +61,7 @@ pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), E w.set_strt(true); }); - let ret: Result<(), Error> = wait_ready_blocking(); + let ret: Result<(), Error> = blocking_wait_ready(); pac::FLASH.cr().modify(|w| w.set_ser(false)); clear_all_err(); ret @@ -87,7 +87,7 @@ pub(crate) unsafe fn clear_all_err() { }); } -unsafe fn wait_ready_blocking() -> Result<(), Error> { +unsafe fn blocking_wait_ready() -> Result<(), Error> { loop { let sr = pac::FLASH.sr().read(); diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index d6818d594..ee824ed2b 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -43,7 +43,7 @@ pub(crate) unsafe fn enable_blocking_write() { pub(crate) unsafe fn disable_blocking_write() {} -pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(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) @@ -64,7 +64,7 @@ pub(crate) unsafe fn write_blocking(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(wait_ready_blocking(bank)); + res = Some(blocking_wait_ready(bank)); bank.sr().modify(|w| { if w.eop() { w.set_eop(true); @@ -84,7 +84,7 @@ pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) res.unwrap() } -pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { let bank = pac::FLASH.bank(sector.bank as usize); bank.cr().modify(|w| { w.set_ser(true); @@ -95,7 +95,7 @@ pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), E w.set_start(true); }); - let ret: Result<(), Error> = wait_ready_blocking(bank); + let ret: Result<(), Error> = blocking_wait_ready(bank); bank.cr().modify(|w| w.set_ser(false)); bank_clear_all_err(bank); ret @@ -142,7 +142,7 @@ unsafe fn bank_clear_all_err(bank: pac::flash::Bank) { }); } -unsafe fn wait_ready_blocking(bank: pac::flash::Bank) -> Result<(), Error> { +unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> Result<(), Error> { loop { let sr = bank.sr().read(); diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index c2394e0c9..76cad6d15 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -57,7 +57,7 @@ pub(crate) unsafe fn disable_blocking_write() { pac::FLASH.cr().write(|w| w.set_pg(false)); } -pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { let mut address = start_address; for val in buf.chunks(4) { write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap())); @@ -67,10 +67,10 @@ pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) fence(Ordering::SeqCst); } - wait_ready_blocking() + blocking_wait_ready() } -pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { #[cfg(any(flash_l0, flash_l1))] { pac::FLASH.pecr().modify(|w| { @@ -100,7 +100,7 @@ pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), E }); } - let ret: Result<(), Error> = wait_ready_blocking(); + let ret: Result<(), Error> = blocking_wait_ready(); #[cfg(any(flash_wl, flash_wb, flash_l4))] pac::FLASH.cr().modify(|w| w.set_per(false)); @@ -153,7 +153,7 @@ pub(crate) unsafe fn clear_all_err() { }); } -unsafe fn wait_ready_blocking() -> Result<(), Error> { +unsafe fn blocking_wait_ready() -> Result<(), Error> { loop { let sr = pac::FLASH.sr().read(); diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs index e569951f9..c007f1178 100644 --- a/embassy-stm32/src/flash/other.rs +++ b/embassy-stm32/src/flash/other.rs @@ -24,10 +24,10 @@ pub(crate) unsafe fn enable_blocking_write() { pub(crate) unsafe fn disable_blocking_write() { unimplemented!(); } -pub(crate) unsafe fn write_blocking(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { +pub(crate) unsafe fn blocking_write(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { unimplemented!(); } -pub(crate) unsafe fn erase_sector_blocking(_sector: &FlashSector) -> Result<(), Error> { +pub(crate) unsafe fn blocking_erase_sector(_sector: &FlashSector) -> Result<(), Error> { unimplemented!(); } pub(crate) unsafe fn clear_all_err() {