diff options
Diffstat (limited to 'embassy-boot/boot/src/mem_flash.rs')
| -rw-r--r-- | embassy-boot/boot/src/mem_flash.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/embassy-boot/boot/src/mem_flash.rs b/embassy-boot/boot/src/mem_flash.rs index dd85405c8..c62379b24 100644 --- a/embassy-boot/boot/src/mem_flash.rs +++ b/embassy-boot/boot/src/mem_flash.rs | |||
| @@ -32,6 +32,23 @@ impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> MemFla | |||
| 32 | pending_write_successes: None, | 32 | pending_write_successes: None, |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | |||
| 36 | pub fn program(&mut self, offset: u32, bytes: &[u8]) -> Result<(), MemFlashError> { | ||
| 37 | let offset = offset as usize; | ||
| 38 | assert!(bytes.len() % WRITE_SIZE == 0); | ||
| 39 | assert!(offset % WRITE_SIZE == 0); | ||
| 40 | assert!(offset + bytes.len() <= SIZE); | ||
| 41 | |||
| 42 | self.mem[offset..offset + bytes.len()].copy_from_slice(bytes); | ||
| 43 | |||
| 44 | Ok(()) | ||
| 45 | } | ||
| 46 | |||
| 47 | pub fn assert_eq(&self, offset: u32, expectation: &[u8]) { | ||
| 48 | for i in 0..expectation.len() { | ||
| 49 | assert_eq!(self.mem[offset as usize + i], expectation[i], "Index {}", i); | ||
| 50 | } | ||
| 51 | } | ||
| 35 | } | 52 | } |
| 36 | 53 | ||
| 37 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> Default | 54 | impl<const SIZE: usize, const ERASE_SIZE: usize, const WRITE_SIZE: usize> Default |
