From 2497b633ae38f8fc3435f6c147535b79d21e6b44 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 28 Aug 2024 18:47:31 +0200 Subject: [PATCH] Fix flash initialization for RP2350. Signed-off-by: Pol Henarejos --- src/fs/file.c | 7 +++---- src/fs/flash.c | 15 ++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/fs/file.c b/src/fs/file.c index fafa8bf..fa47599 100644 --- a/src/fs/file.c +++ b/src/fs/file.c @@ -251,8 +251,7 @@ void scan_region(bool persistent) { endp = end_rom_pool; startp = start_rom_pool; } - for (uintptr_t base = flash_read_uintptr(endp); base >= startp; - base = flash_read_uintptr(base)) { + for (uintptr_t base = flash_read_uintptr(endp); base >= startp; base = flash_read_uintptr(base)) { if (base == 0x0) { //all is empty break; } @@ -276,8 +275,8 @@ void scan_region(bool persistent) { void wait_flash_finish(); void scan_flash() { initialize_flash(false); //soft initialization - if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff && - *(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t)) == 0xffffffff) { + uint32_t r1 = *(uintptr_t *) flash_read(end_rom_pool), r2 = *(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t)); + if ((r1 == 0xffffffff || r1 == 0xefefefef) && (r2 == 0xffffffff || r2 == 0xefefefef)) { printf("First initialization (or corrupted!)\n"); uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)]; memset(empty, 0, sizeof(empty)); diff --git a/src/fs/flash.c b/src/fs/flash.c index 75527c2..466e710 100644 --- a/src/fs/flash.c +++ b/src/fs/flash.c @@ -52,12 +52,17 @@ //To avoid possible future allocations, data region starts at the end of flash and goes upwards to the center region +#ifdef PICO_RP2350 +// Table partition for RP2350 needs 8kb +const uintptr_t end_flash = (XIP_BASE + PICO_FLASH_SIZE_BYTES - 2 * FLASH_SECTOR_SIZE); +#else +const uintptr_t end_flash = (XIP_BASE + PICO_FLASH_SIZE_BYTES); +#endif + +const uintptr_t end_rom_pool = end_flash - FLASH_DATA_HEADER_SIZE - 4; //This is a fixed value. DO NOT CHANGE +const uintptr_t start_rom_pool = end_rom_pool - FLASH_PERMANENT_REGION; //This is a fixed value. DO NOT CHANGE +const uintptr_t end_data_pool = start_rom_pool - FLASH_DATA_HEADER_SIZE; //This is a fixed value. DO NOT CHANGE const uintptr_t start_data_pool = (XIP_BASE + FLASH_TARGET_OFFSET); -const uintptr_t end_data_pool = (XIP_BASE + PICO_FLASH_SIZE_BYTES) - FLASH_DATA_HEADER_SIZE - - FLASH_PERMANENT_REGION - FLASH_DATA_HEADER_SIZE - 4; //This is a fixed value. DO NOT CHANGE -const uintptr_t end_rom_pool = (XIP_BASE + PICO_FLASH_SIZE_BYTES) - FLASH_DATA_HEADER_SIZE - 4; //This is a fixed value. DO NOT CHANGE -const uintptr_t start_rom_pool = (XIP_BASE + PICO_FLASH_SIZE_BYTES) - FLASH_DATA_HEADER_SIZE - - FLASH_PERMANENT_REGION; //This is a fixed value. DO NOT CHANGE extern int flash_program_block(uintptr_t addr, const uint8_t *data, size_t len); extern int flash_program_halfword(uintptr_t addr, uint16_t data);