Skip to content

Commit 3e98f1c

Browse files
committed
Add ERASE_BYTE const to NorFlash trait
Related issue #35
1 parent 3fddbf7 commit 3e98f1c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/nor_flash.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ pub trait NorFlash: ReadNorFlash {
8989
/// The minumum number of bytes the storage peripheral can erase
9090
const ERASE_SIZE: usize;
9191

92+
/// The content of erased storage
93+
///
94+
/// Usually is `0xff` for NOR flash
95+
const ERASE_BYTE: u8 = 0xff;
96+
9297
/// Erase the given storage range, clearing all data within `[from..to]`.
9398
/// The given range will contain all 1s afterwards.
9499
///
@@ -168,6 +173,7 @@ impl<T: ReadNorFlash> ReadNorFlash for &mut T {
168173
impl<T: NorFlash> NorFlash for &mut T {
169174
const WRITE_SIZE: usize = T::WRITE_SIZE;
170175
const ERASE_SIZE: usize = T::ERASE_SIZE;
176+
const ERASE_BYTE: u8 = T::ERASE_BYTE;
171177

172178
fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
173179
T::erase(self, from, to)
@@ -361,7 +367,7 @@ where
361367
// Use `merge_buffer` as allocation for padding `data` to `WRITE_SIZE`
362368
let offset = addr as usize % S::WRITE_SIZE;
363369
let aligned_end = data.len() % S::WRITE_SIZE + offset + data.len();
364-
self.merge_buffer[..aligned_end].fill(0xff);
370+
self.merge_buffer[..aligned_end].fill(S::ERASE_BYTE);
365371
self.merge_buffer[offset..offset + data.len()].copy_from_slice(data);
366372
self.storage
367373
.write(addr - offset as u32, &self.merge_buffer[..aligned_end])?;

0 commit comments

Comments
 (0)