@@ -64,7 +64,15 @@ pub enum Function {
64
64
/// and checking the flash algorithm initialization status.
65
65
#[ macro_export]
66
66
macro_rules! algorithm {
67
- ( $type: ty) => {
67
+ ( $type: ty, {
68
+ flash_address: $flash_address: expr,
69
+ flash_size: $flash_size: expr,
70
+ page_size: $page_size: expr,
71
+ sectors: [ $( {
72
+ size: $size: expr,
73
+ address: $address: expr,
74
+ } ) ,+]
75
+ } ) => {
68
76
static mut _IS_INIT: bool = false ;
69
77
static mut _ALGO_INSTANCE: MaybeUninit <$type> = MaybeUninit :: uninit( ) ;
70
78
@@ -136,5 +144,74 @@ macro_rules! algorithm {
136
144
Err ( e) => e. get( ) ,
137
145
}
138
146
}
147
+
148
+ #[ allow( non_upper_case_globals) ]
149
+ #[ no_mangle]
150
+ #[ used]
151
+ #[ link_section = "DeviceData" ]
152
+ pub static FlashDevice : FlashDeviceDescription = FlashDeviceDescription {
153
+ // The version is never read by probe-rs and can be fixed.
154
+ vers: 0x0 ,
155
+ // The device name here can be customized but it really has no real use
156
+ // appart from identifying the device the ELF is intended for which we have
157
+ // in our YAML.
158
+ dev_name: [ 0u8 ; 128 ] ,
159
+ // The specification does not specify the values that can go here,
160
+ // but this value means internal flash device.
161
+ dev_type: 5 ,
162
+ dev_addr: $flash_address,
163
+ device_size: $flash_size,
164
+ page_size: $page_size,
165
+ _reserved: 0 ,
166
+ // The empty state of a byte in flash.
167
+ empty: 0xff ,
168
+ // This value can be used to estimate the amount of time the flashing procedure takes worst case.
169
+ program_time_out: 1000 ,
170
+ // This value can be used to estimate the amount of time the erasing procedure takes worst case.
171
+ erase_time_out: 2000 ,
172
+ flash_sectors: [
173
+ $(
174
+ FlashSector {
175
+ size: $size,
176
+ address: $address,
177
+ }
178
+ ) ,+,
179
+ // This marks the end of the flash sector list.
180
+ FlashSector {
181
+ size: 0xffff_ffff ,
182
+ address: 0xffff_ffff ,
183
+ }
184
+ ] ,
185
+ } ;
186
+
187
+ #[ repr( C ) ]
188
+ pub struct FlashDeviceDescription {
189
+ vers: u16 ,
190
+ dev_name: [ u8 ; 128 ] ,
191
+ dev_type: u16 ,
192
+ dev_addr: u32 ,
193
+ device_size: u32 ,
194
+ page_size: u32 ,
195
+ _reserved: u32 ,
196
+ empty: u8 ,
197
+ program_time_out: u32 ,
198
+ erase_time_out: u32 ,
199
+
200
+ flash_sectors: [ FlashSector ; $crate:: count!( $( $size) * ) + 1 ] ,
201
+ }
202
+
203
+ #[ repr( C ) ]
204
+ #[ derive( Copy , Clone ) ]
205
+ pub struct FlashSector {
206
+ size: u32 ,
207
+ address: u32 ,
208
+ }
139
209
} ;
140
210
}
211
+
212
+ #[ doc( hidden) ]
213
+ #[ macro_export]
214
+ macro_rules! count {
215
+ ( ) => ( 0usize ) ;
216
+ ( $x: tt $( $xs: tt) * ) => ( 1usize + count!( $( $xs) * ) ) ;
217
+ }
0 commit comments