@@ -26,7 +26,6 @@ const FLASH_SECTORS_PER_BLOCK: usize = FLASH_SECTOR_SIZE / FLASH_BLOCK_SIZE;
26
26
const CHIP_DETECT_MAGIC_REG_ADDR : u32 = 0x40001000 ;
27
27
28
28
#[ derive( Clone , Copy , Debug , Eq , PartialEq , Display ) ]
29
- #[ allow( dead_code) ]
30
29
#[ repr( u8 ) ]
31
30
pub enum FlashSize {
32
31
#[ strum( serialize = "256KB" ) ]
@@ -47,7 +46,8 @@ pub enum FlashSize {
47
46
Flash32Mb = 0x19 ,
48
47
#[ strum( serialize = "64MB" ) ]
49
48
Flash64Mb = 0x1a ,
50
- FlashRetry = 0xFF , // used to hint that alternate detection should be tried
49
+ #[ strum( serialize = "128MB" ) ]
50
+ Flash128Mb = 0x21 ,
51
51
}
52
52
53
53
impl FlashSize {
@@ -62,7 +62,6 @@ impl FlashSize {
62
62
0x18 => Ok ( FlashSize :: Flash16Mb ) ,
63
63
0x19 => Ok ( FlashSize :: Flash32Mb ) ,
64
64
0x1a => Ok ( FlashSize :: Flash64Mb ) ,
65
- 0xFF => Ok ( FlashSize :: FlashRetry ) ,
66
65
_ => Err ( Error :: UnsupportedFlash ( FlashDetectError :: from ( value) ) ) ,
67
66
}
68
67
}
@@ -183,18 +182,21 @@ impl Flasher {
183
182
}
184
183
185
184
fn spi_autodetect ( & mut self ) -> Result < ( ) , Error > {
186
- // loop over all available spi params until we find one that successfully reads
187
- // the flash size
185
+ // Loop over all available SPI parameters until we find one that successfully
186
+ // reads the flash size.
188
187
for spi_params in TRY_SPI_PARAMS . iter ( ) . copied ( ) {
189
188
self . enable_flash ( spi_params) ?;
190
- if self . flash_detect ( ) ? {
191
- // flash detect successful, save these spi params
189
+ if let Some ( flash_size) = self . flash_detect ( ) ? {
190
+ // Flash detection was successful, so save the flash size and SPI parameters and
191
+ // return.
192
+ self . flash_size = flash_size;
192
193
self . spi_params = spi_params;
194
+
193
195
return Ok ( ( ) ) ;
194
196
}
195
197
}
196
198
197
- // none of the spi parameters were successful
199
+ // None of the SPI parameters were successful.
198
200
Err ( Error :: FlashConnect )
199
201
}
200
202
@@ -206,11 +208,18 @@ impl Flasher {
206
208
Ok ( ( ) )
207
209
}
208
210
209
- fn flash_detect ( & mut self ) -> Result < bool , Error > {
211
+ fn flash_detect ( & mut self ) -> Result < Option < FlashSize > , Error > {
212
+ const FLASH_RETRY : u8 = 0xFF ;
213
+
210
214
let flash_id = self . spi_command ( CommandType :: FlashDetect , & [ ] , 24 ) ?;
211
- let size_id = flash_id >> 16 ;
215
+ let size_id = ( flash_id >> 16 ) as u8 ;
216
+
217
+ // This value indicates that an alternate detection method should be tried.
218
+ if size_id == FLASH_RETRY {
219
+ return Ok ( None ) ;
220
+ }
212
221
213
- self . flash_size = match FlashSize :: from ( size_id as u8 ) {
222
+ let flash_size = match FlashSize :: from ( size_id) {
214
223
Ok ( size) => size,
215
224
Err ( _) => {
216
225
eprintln ! (
@@ -222,7 +231,7 @@ impl Flasher {
222
231
}
223
232
} ;
224
233
225
- Ok ( self . flash_size != FlashSize :: FlashRetry )
234
+ Ok ( Some ( flash_size) )
226
235
}
227
236
228
237
fn sync ( & mut self ) -> Result < ( ) , Error > {
0 commit comments