@@ -11,7 +11,7 @@ pub trait ReadNorFlash {
1111 /// Read a slice of data from the storage peripheral, starting the read
1212 /// operation at the given address offset, and reading `bytes.len()` bytes.
1313 ///
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
1515 /// the peripheral end address.
1616 fn try_read ( & mut self , offset : u32 , bytes : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
1717
@@ -223,7 +223,19 @@ where
223223 // Check if we can write the data block directly, under the limitations imposed by NorFlash:
224224 // - We can only change 1's to 0's
225225 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 ] ) ?;
227239 } else {
228240 self . storage . try_erase ( page. start , page. end ( ) ) ?;
229241 self . merge_buffer [ ..S :: ERASE_SIZE ]
0 commit comments