From 94381019f4a7ffbb236d671b51677d4e769fb7ae Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 5 Mar 2025 11:18:56 -0600 Subject: [PATCH] skip reprogramming flash with identical content this is a terrible workaround: the disabled interrupts of flash copy(?) cause USB HID input to break. with this change, I can play Kirby merely by selecting it from the menu, resetting once I reach the title screen, then selecting it from the menu a second time. --- MCUME_pico2/flash/flash_t.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/MCUME_pico2/flash/flash_t.c b/MCUME_pico2/flash/flash_t.c index 2dfc428..0510398 100644 --- a/MCUME_pico2/flash/flash_t.c +++ b/MCUME_pico2/flash/flash_t.c @@ -2,6 +2,8 @@ RP2350 flash driver */ +#include + #include "flash_t.h" #include "hardware/flash.h" @@ -24,17 +26,19 @@ int flash_load(const char * filename) if (f) { while ( (offset < (HW_FLASH_STORAGE_TOP-FLASH_SECTOR_SIZE)) && (n = emu_FileRead(cache,FLASH_SECTOR_SIZE,f) ) ) { //memcpy(cache, (unsigned char *)offset, n); - uint32_t ints = save_and_disable_interrupts(); - flash_range_erase(offset, FLASH_SECTOR_SIZE); - flash_range_program(offset, (const uint8_t *)&cache[0], FLASH_SECTOR_SIZE); - restore_interrupts(ints); - emu_printi(n); - emu_printi(offset); - //uint8_t * pt = (uint8_t*)(XIP_BASE + offset); - //emu_printi(pt[0]); - //emu_printi(pt[1]); - //emu_printi(pt[2]); - //emu_printi(pt[3]); + if (memcmp(cache, (unsigned char*)XIP_BASE + offset, n)) { + uint32_t ints = save_and_disable_interrupts(); + flash_range_erase(offset, FLASH_SECTOR_SIZE); + flash_range_program(offset, (const uint8_t *)&cache[0], FLASH_SECTOR_SIZE); + restore_interrupts(ints); + emu_printi(n); + emu_printi(offset); + //uint8_t * pt = (uint8_t*)(XIP_BASE + offset); + //emu_printi(pt[0]); + //emu_printi(pt[1]); + //emu_printi(pt[2]); + //emu_printi(pt[3]); + } offset += FLASH_SECTOR_SIZE; size += n; } @@ -99,4 +103,4 @@ int flash_verify(unsigned char * buf, int size) } emu_printf("flash_verify OK."); return 0; -} \ No newline at end of file +}