File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ target_link_libraries(flash_nuke
77 hardware_flash
88 )
99
10+ # We use flash command 0x9f to dynamically get the flash size
11+ # If that fails, assume 16Mb
12+ math (EXPR FLASH_SIZE_OVERRIDE "16 * 1024 * 1024" OUTPUT_FORMAT DECIMAL)
13+ target_compile_definitions (flash_nuke PRIVATE
14+ PICO_INCLUDE_FLASH_UTILS=1
15+ PICO_FLASH_SIZE_BYTES=${FLASH_SIZE_OVERRIDE}
16+ )
17+
1018# It doesn't make sense to run this program from flash. Always build a
1119# RAM-only binary.
1220pico_set_binary_type(flash_nuke no_flash)
Original file line number Diff line number Diff line change 2525#include "hardware/flash.h"
2626#include "pico/bootrom.h"
2727
28+ #define MIN_FLASH_SIZE (1024 * 1024 * 2)
29+
2830int main () {
29- uint flash_size_bytes ;
31+ uint flash_size_bytes = 0 ;
3032 uint8_t txbuf [4 ];
3133 uint8_t rxbuf [4 ];
3234 txbuf [0 ] = 0x9f ;
3335 flash_do_cmd (txbuf , rxbuf , 4 );
3436 flash_size_bytes = 1u << rxbuf [3 ];
37+ if (flash_size_bytes < MIN_FLASH_SIZE || flash_size_bytes > PICO_FLASH_SIZE_BYTES ) {
38+ flash_size_bytes = PICO_FLASH_SIZE_BYTES ;
39+ }
3540 flash_range_erase (0 , flash_size_bytes );
3641 // Leave an eyecatcher pattern in the first page of flash so picotool can
3742 // more easily check the size:
You can’t perform that action at this time.
0 commit comments