@@ -11,7 +11,7 @@ pub trait ReadNorFlash {
11
11
/// Read a slice of data from the storage peripheral, starting the read
12
12
/// operation at the given address offset, and reading `bytes.len()` bytes.
13
13
///
14
- /// This should throw an error in case `bytes.len()` will be larger than
14
+ /// This should throw an error in case `bytes.len()` will be larger than
15
15
/// the peripheral end address.
16
16
fn try_read ( & mut self , offset : u32 , bytes : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
17
17
@@ -223,7 +223,19 @@ where
223
223
// Check if we can write the data block directly, under the limitations imposed by NorFlash:
224
224
// - We can only change 1's to 0's
225
225
if is_subset {
226
- self . storage . try_write ( addr, data) ?;
226
+ // Use `merge_buffer` as allocation for padding `data` to `WRITE_SIZE`
227
+ let offset = addr as usize % S :: WRITE_SIZE ;
228
+ self . merge_buffer [ ..S :: WRITE_SIZE ]
229
+ . iter_mut ( )
230
+ . for_each ( |c| * c = 0u8 ) ;
231
+ self . merge_buffer [ ..S :: WRITE_SIZE ]
232
+ . iter_mut ( )
233
+ . skip ( offset)
234
+ . zip ( data)
235
+ . for_each ( |( a, b) | * a = * b) ;
236
+ let aligned_addr = addr - offset as u32 ;
237
+ self . storage
238
+ . try_write ( aligned_addr, & self . merge_buffer [ ..S :: WRITE_SIZE ] ) ?;
227
239
} else {
228
240
self . storage . try_erase ( page. start , page. end ( ) ) ?;
229
241
self . merge_buffer [ ..S :: ERASE_SIZE ]
0 commit comments