@@ -37,6 +37,16 @@ fn eeprom_size_to_feature(size: u32) -> String {
37
37
format ! ( "eeprom-{}" , size)
38
38
}
39
39
40
+ /// Get the Flash size feature for a certain size.
41
+ fn flash_size_to_feature ( size : u32 ) -> String {
42
+ format ! ( "flash-{}" , size)
43
+ }
44
+
45
+ /// Get the RAM size feature for a certain size.
46
+ fn ram_size_to_feature ( size : u32 ) -> String {
47
+ format ! ( "ram-{}" , size)
48
+ }
49
+
40
50
fn main ( ) -> Result < ( ) , String > {
41
51
let args = App :: new ( "cube-parse" )
42
52
. version ( env ! ( "CARGO_PKG_VERSION" ) )
@@ -87,7 +97,7 @@ fn main() -> Result<(), String> {
87
97
// MCU map
88
98
//
89
99
// This maps a MCU ref name to the corresponding `mcu::Mcu` instance.
90
- let mut mcu_map: HashMap < String , mcu:: Mcu > = HashMap :: new ( ) ;
100
+ let mut mcu_map: HashMap < String , ( & family :: Mcu , mcu:: Mcu ) > = HashMap :: new ( ) ;
91
101
92
102
// GPIO map
93
103
//
@@ -105,13 +115,23 @@ fn main() -> Result<(), String> {
105
115
// The keys of this map are EEPROM sizes, the values are Vecs of MCU ref names.
106
116
let mut mcu_eeprom_size_map: HashMap < u32 , Vec < String > > = HashMap :: new ( ) ;
107
117
118
+ // Flash size map
119
+ //
120
+ // The keys of this map are flash sizes, the values are Vecs of MCU ref names.
121
+ let mut mcu_flash_size_map: HashMap < u32 , Vec < String > > = HashMap :: new ( ) ;
122
+
123
+ // RAM size map
124
+ //
125
+ // The keys of this map are RAM sizes, the values are Vecs of MCU ref names.
126
+ let mut mcu_ram_size_map: HashMap < u32 , Vec < String > > = HashMap :: new ( ) ;
127
+
108
128
// Iterate through subfamilies, then through MCUs. Fill the maps above with
109
129
// aggregated data.
110
130
for sf in family {
111
131
for mcu in sf {
112
132
// Load MCU data from the XML files
113
133
let mcu_dat = mcu:: Mcu :: load ( & db_dir, & mcu. name )
114
- . map_err ( |e| format ! ( "Could not load MCU data: {}" , e) ) ?;
134
+ . map_err ( |e| format ! ( "Could not load MCU data for mcu {} : {}" , & mcu . name , e) ) ?;
115
135
116
136
// Fill GPIO map
117
137
let gpio_version = mcu_dat. get_ip ( "GPIO" ) . unwrap ( ) . get_version ( ) . to_string ( ) ;
@@ -134,7 +154,23 @@ fn main() -> Result<(), String> {
134
154
. push ( mcu. ref_name . clone ( ) ) ;
135
155
}
136
156
137
- mcu_map. insert ( mcu. ref_name . clone ( ) , mcu_dat) ;
157
+ // Fill flash size map
158
+ if let Some ( flash_size) = mcu. flash_size ( ) {
159
+ mcu_flash_size_map
160
+ . entry ( flash_size)
161
+ . or_insert ( vec ! [ ] )
162
+ . push ( mcu. ref_name . clone ( ) ) ;
163
+ }
164
+
165
+ // Fill RAM size map
166
+ if let Some ( ram_size) = mcu. ram_size ( ) {
167
+ mcu_ram_size_map
168
+ . entry ( ram_size)
169
+ . or_insert ( vec ! [ ] )
170
+ . push ( mcu. ref_name . clone ( ) ) ;
171
+ }
172
+
173
+ mcu_map. insert ( mcu. ref_name . clone ( ) , ( mcu, mcu_dat) ) ;
138
174
}
139
175
}
140
176
@@ -144,6 +180,8 @@ fn main() -> Result<(), String> {
144
180
& mcu_gpio_map,
145
181
& mcu_package_map,
146
182
& mcu_eeprom_size_map,
183
+ & mcu_flash_size_map,
184
+ & mcu_ram_size_map,
147
185
& mcu_family,
148
186
) ?,
149
187
GenerateTarget :: PinMappings => generate_pin_mappings ( & mcu_gpio_map, & db_dir) ?,
@@ -178,10 +216,12 @@ lazy_static! {
178
216
/// Finally, the MCU features are printed, they act purely as aliases for the
179
217
/// other features.
180
218
fn generate_features (
181
- mcu_map : & HashMap < String , mcu:: Mcu > ,
219
+ mcu_map : & HashMap < String , ( & family :: Mcu , mcu:: Mcu ) > ,
182
220
mcu_gpio_map : & HashMap < String , Vec < String > > ,
183
221
mcu_package_map : & HashMap < String , String > ,
184
222
mcu_eeprom_size_map : & HashMap < u32 , Vec < String > > ,
223
+ mcu_flash_size_map : & HashMap < u32 , Vec < String > > ,
224
+ mcu_ram_size_map : & HashMap < u32 , Vec < String > > ,
185
225
mcu_family : & str ,
186
226
) -> Result < ( ) , String > {
187
227
// IO features
@@ -206,6 +246,24 @@ fn generate_features(
206
246
}
207
247
println ! ( ) ;
208
248
249
+ // Flash sizes
250
+ let mut flash_sizes = mcu_flash_size_map. keys ( ) . collect :: < Vec < _ > > ( ) ;
251
+ flash_sizes. sort ( ) ;
252
+ println ! ( "# Features based on Flash size (in kbytes)" ) ;
253
+ for size in flash_sizes {
254
+ println ! ( "{} = []" , flash_size_to_feature( * size) ) ;
255
+ }
256
+ println ! ( ) ;
257
+
258
+ // RAM sizes
259
+ let mut ram_sizes = mcu_ram_size_map. keys ( ) . collect :: < Vec < _ > > ( ) ;
260
+ ram_sizes. sort ( ) ;
261
+ println ! ( "# Features based on RAM size (in kbytes)" ) ;
262
+ for size in ram_sizes {
263
+ println ! ( "{} = []" , ram_size_to_feature( * size) ) ;
264
+ }
265
+ println ! ( ) ;
266
+
209
267
// Physical packages
210
268
if !mcu_package_map. is_empty ( ) {
211
269
println ! ( "# Physical packages" ) ;
@@ -246,11 +304,22 @@ fn generate_features(
246
304
// GPIO version feature
247
305
dependencies. push ( gpio_version_feature. clone ( ) ) ;
248
306
307
+ let ( mcu_info, mcu_dat) = mcu_map. get ( mcu) . unwrap ( ) ;
308
+
249
309
// EEPROM size
250
- if let Some ( size) = mcu_map . get ( mcu ) . unwrap ( ) . get_eeprom_size ( ) {
310
+ if let Some ( size) = mcu_dat . get_eeprom_size ( ) {
251
311
dependencies. push ( eeprom_size_to_feature ( size) ) ;
252
312
}
253
313
314
+ // Flash & RAM size
315
+ if let Some ( flash_size) = mcu_info. flash_size ( ) {
316
+ dependencies. push ( flash_size_to_feature ( flash_size) ) ;
317
+ }
318
+
319
+ if let Some ( ram_size) = mcu_info. ram_size ( ) {
320
+ dependencies. push ( ram_size_to_feature ( ram_size) ) ;
321
+ }
322
+
254
323
mcu_aliases. push ( format ! (
255
324
"mcu-{} = [{}]" ,
256
325
mcu,
0 commit comments