1+ use embedded_storage:: nor_flash:: { ErrorType , NorFlash , ReadNorFlash } ;
12use stm32h7xx_hal:: flash:: LockedFlashBank ;
23
4+ use stm32h7xx_hal:: flash:: Error as FlashError ;
5+
36pub struct Flash ( pub LockedFlashBank ) ;
47
58impl Flash {
@@ -8,9 +11,8 @@ impl Flash {
811 }
912}
1013
11- impl embedded_storage:: nor_flash:: ErrorType for Flash {
12- type Error =
13- <LockedFlashBank as embedded_storage:: nor_flash:: ErrorType >:: Error ;
14+ impl ErrorType for Flash {
15+ type Error = FlashError ;
1416}
1517
1618impl embedded_storage:: nor_flash:: ReadNorFlash for Flash {
@@ -20,7 +22,23 @@ impl embedded_storage::nor_flash::ReadNorFlash for Flash {
2022 & mut self ,
2123 offset : u32 ,
2224 bytes : & mut [ u8 ] ,
23- ) -> Result < ( ) , Self :: Error > {
25+ ) -> Result < ( ) , FlashError > {
26+ self . 0 . read ( offset, bytes)
27+ }
28+
29+ fn capacity ( & self ) -> usize {
30+ self . 0 . capacity ( )
31+ }
32+ }
33+
34+ impl embedded_storage_async:: nor_flash:: ReadNorFlash for Flash {
35+ const READ_SIZE : usize = LockedFlashBank :: READ_SIZE ;
36+
37+ async fn read (
38+ & mut self ,
39+ offset : u32 ,
40+ bytes : & mut [ u8 ] ,
41+ ) -> Result < ( ) , FlashError > {
2442 self . 0 . read ( offset, bytes)
2543 }
2644
@@ -45,3 +63,24 @@ impl embedded_storage::nor_flash::NorFlash for Flash {
4563 bank. write ( offset, bytes)
4664 }
4765}
66+
67+ impl embedded_storage_async:: nor_flash:: NorFlash for Flash {
68+ const WRITE_SIZE : usize =
69+ stm32h7xx_hal:: flash:: UnlockedFlashBank :: WRITE_SIZE ;
70+ const ERASE_SIZE : usize =
71+ stm32h7xx_hal:: flash:: UnlockedFlashBank :: ERASE_SIZE ;
72+
73+ async fn erase ( & mut self , from : u32 , to : u32 ) -> Result < ( ) , FlashError > {
74+ let mut bank = self . 0 . unlocked ( ) ;
75+ bank. erase ( from, to)
76+ }
77+
78+ async fn write (
79+ & mut self ,
80+ offset : u32 ,
81+ bytes : & [ u8 ] ,
82+ ) -> Result < ( ) , FlashError > {
83+ let mut bank = self . 0 . unlocked ( ) ;
84+ bank. write ( offset, bytes)
85+ }
86+ }
0 commit comments