@@ -2,7 +2,7 @@ use atomic_polyfill::{fence, Ordering};
22use embassy_hal_common:: drop:: OnDrop ;
33use embassy_hal_common:: { into_ref, PeripheralRef } ;
44
5- use super :: { family, Error , FlashLayout , FlashRegion , FlashSector , FLASH_BASE , FLASH_SIZE , WRITE_SIZE } ;
5+ use super :: { family, Error , FlashLayout , FlashRegion , FlashSector , FLASH_BASE , FLASH_SIZE , MAX_ERASE_SIZE , WRITE_SIZE } ;
66use crate :: flash:: FlashBank ;
77use crate :: Peripheral ;
88
@@ -162,6 +162,35 @@ impl FlashRegion {
162162 }
163163}
164164
165+ impl embedded_storage:: nor_flash:: ErrorType for Flash < ' _ > {
166+ type Error = Error ;
167+ }
168+
169+ impl embedded_storage:: nor_flash:: ReadNorFlash for Flash < ' _ > {
170+ const READ_SIZE : usize = 1 ;
171+
172+ fn read ( & mut self , offset : u32 , bytes : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
173+ self . blocking_read ( offset, bytes)
174+ }
175+
176+ fn capacity ( & self ) -> usize {
177+ FLASH_SIZE
178+ }
179+ }
180+
181+ impl embedded_storage:: nor_flash:: NorFlash for Flash < ' _ > {
182+ const WRITE_SIZE : usize = WRITE_SIZE ;
183+ const ERASE_SIZE : usize = MAX_ERASE_SIZE ;
184+
185+ fn write ( & mut self , offset : u32 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
186+ self . blocking_write ( offset, bytes)
187+ }
188+
189+ fn erase ( & mut self , from : u32 , to : u32 ) -> Result < ( ) , Self :: Error > {
190+ self . blocking_erase ( from, to)
191+ }
192+ }
193+
165194foreach_flash_region ! {
166195 ( $type_name: ident, $write_size: literal, $erase_size: literal) => {
167196 impl crate :: _generated:: flash_regions:: $type_name<' _> {
0 commit comments