From ce6dc26497263e2c9457710321c94485bd8c31f9 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Wed, 4 Jun 2025 19:35:51 +0100 Subject: [PATCH] Update nuke.c to auto-detect flash size Fixes https://github.com/raspberrypi/pico-examples/issues/642 Thanks to @Gadgetoid for the work "Making A Thing" - Support [PiMoRoNi by buying stuff](https://shop.pimoroni.com/)! --- flash/nuke/nuke.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/flash/nuke/nuke.c b/flash/nuke/nuke.c index 521f5d74f..5a3156b16 100644 --- a/flash/nuke/nuke.c +++ b/flash/nuke/nuke.c @@ -27,12 +27,11 @@ int main() { uint flash_size_bytes; -#ifndef PICO_FLASH_SIZE_BYTES -#warning PICO_FLASH_SIZE_BYTES not set, assuming 16M - flash_size_bytes = 16 * 1024 * 1024; -#else - flash_size_bytes = PICO_FLASH_SIZE_BYTES; -#endif + uint8_t txbuf[4]; + uint8_t rxbuf[4]; + txbuf[0] = 0x9f; + flash_do_cmd(txbuf, rxbuf, 4); + flash_size_bytes = 1u << rxbuf[3]; flash_range_erase(0, flash_size_bytes); // Leave an eyecatcher pattern in the first page of flash so picotool can // more easily check the size: