Skip to content

Commit

Permalink
SFT-4402: Flash erase for simulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandudey committed Jan 7, 2025
1 parent 61d51e7 commit e7a426e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion extmod/foundation-rust/embedded-storage-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<

let from = usize::try_from(from).expect("u32 bigger than usize");
let to = usize::try_from(to).expect("u32 bigger than usize");
self.storage[from..from + to].fill(0xFF);
self.storage[from..to].fill(0xFF);
fs::write(&self.path, &self.storage)?;
Ok(())
}
Expand Down
32 changes: 28 additions & 4 deletions extmod/foundation-rust/src/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,23 @@ pub extern "C" fn write(offset: u32, data: *const u8, len: usize) -> bool {
/// Erase a sector of the flash storage.
#[export_name = "foundation_flash_sector_erase"]
pub extern "C" fn sector_erase(offset: u32) -> bool {
let mut flash = unsafe { FLASH.borrow_mut() };

#[cfg(target_arch = "arm")]
{
let mut flash = unsafe { FLASH.borrow_mut() };
if flash.as_mut_inner().sector_erase(offset).is_err() {
return false;
}
}

if let Err(_) = flash.as_mut_inner().sector_erase(offset) {
#[cfg(not(target_arch = "arm"))]
{
// Erase 4 KiB.
if flash
.as_mut_inner()
.erase(offset, offset + (4 * 1024))
.is_err()
{
return false;
}
}
Expand All @@ -158,11 +170,23 @@ pub extern "C" fn sector_erase(offset: u32) -> bool {
/// Erase a block of the flash storage.
#[export_name = "foundation_flash_block_erase"]
pub extern "C" fn block_erase(offset: u32) -> bool {
let mut flash = unsafe { FLASH.borrow_mut() };

#[cfg(target_arch = "arm")]
{
let mut flash = unsafe { FLASH.borrow_mut() };
if flash.as_mut_inner().block_erase_64kib(offset).is_err() {
return false;
}
}

if let Err(_) = flash.as_mut_inner().block_erase_64kib(offset) {
#[cfg(not(target_arch = "arm"))]
{
// Erase 64 KiB.
if flash
.as_mut_inner()
.erase(offset, offset + (64 * 1024))
.is_err()
{
return false;
}
}
Expand Down

0 comments on commit e7a426e

Please sign in to comment.