@@ -75,6 +75,15 @@ pub trait FlashAlgorithm: Sized + 'static {
75
75
/// * `data` - The data to compare with.
76
76
#[ cfg( feature = "verify" ) ]
77
77
fn verify ( & mut self , address : u32 , size : u32 , data : Option < & [ u8 ] > ) -> Result < ( ) , ErrorCode > ;
78
+
79
+ /// Read flash.
80
+ ///
81
+ /// # Arguments
82
+ ///
83
+ /// * `address` - The start address of the flash to read.
84
+ /// * `data` - The data.
85
+ #[ cfg( feature = "read-flash" ) ]
86
+ fn read_flash ( & mut self , address : u32 , data : & mut [ u8 ] ) -> Result < ( ) , ErrorCode > ;
78
87
}
79
88
80
89
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
@@ -167,6 +176,7 @@ macro_rules! algorithm {
167
176
}
168
177
}
169
178
$crate:: erase_chip!( $type) ;
179
+ $crate:: read_flash!( $type) ;
170
180
$crate:: verify!( $type) ;
171
181
172
182
#[ allow( non_upper_case_globals) ]
@@ -270,6 +280,33 @@ macro_rules! erase_chip {
270
280
} ;
271
281
}
272
282
283
+ #[ doc( hidden) ]
284
+ #[ macro_export]
285
+ #[ cfg( not( feature = "read-flash" ) ) ]
286
+ macro_rules! read_flash {
287
+ ( $type: ty) => { } ;
288
+ }
289
+ #[ doc( hidden) ]
290
+ #[ macro_export]
291
+ #[ cfg( feature = "read-flash" ) ]
292
+ macro_rules! read_flash {
293
+ ( $type: ty) => {
294
+ #[ no_mangle]
295
+ #[ link_section = ".entry" ]
296
+ pub unsafe extern "C" fn ReadFlash ( addr: u32 , size: u32 , data: * mut u8 ) -> u32 {
297
+ if !_IS_INIT {
298
+ return 1 ;
299
+ }
300
+ let this = & mut * _ALGO_INSTANCE. as_mut_ptr( ) ;
301
+ let data_slice: & mut [ u8 ] = unsafe { core:: slice:: from_raw_parts_mut( data, size as usize ) } ;
302
+ match <$type as $crate:: FlashAlgorithm >:: read_flash( this, addr, data_slice) {
303
+ Ok ( ( ) ) => 0 ,
304
+ Err ( e) => e. get( ) ,
305
+ }
306
+ }
307
+ } ;
308
+ }
309
+
273
310
#[ doc( hidden) ]
274
311
#[ macro_export]
275
312
#[ cfg( not( feature = "verify" ) ) ]
0 commit comments