Fix flash initialization for RP2350.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-08-28 18:47:31 +02:00
parent 0560e49b5c
commit 2497b633ae
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
2 changed files with 13 additions and 9 deletions

View file

@ -251,8 +251,7 @@ void scan_region(bool persistent) {
endp = end_rom_pool; endp = end_rom_pool;
startp = start_rom_pool; startp = start_rom_pool;
} }
for (uintptr_t base = flash_read_uintptr(endp); base >= startp; for (uintptr_t base = flash_read_uintptr(endp); base >= startp; base = flash_read_uintptr(base)) {
base = flash_read_uintptr(base)) {
if (base == 0x0) { //all is empty if (base == 0x0) { //all is empty
break; break;
} }
@ -276,8 +275,8 @@ void scan_region(bool persistent) {
void wait_flash_finish(); void wait_flash_finish();
void scan_flash() { void scan_flash() {
initialize_flash(false); //soft initialization initialize_flash(false); //soft initialization
if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff && uint32_t r1 = *(uintptr_t *) flash_read(end_rom_pool), r2 = *(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t));
*(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t)) == 0xffffffff) { if ((r1 == 0xffffffff || r1 == 0xefefefef) && (r2 == 0xffffffff || r2 == 0xefefefef)) {
printf("First initialization (or corrupted!)\n"); printf("First initialization (or corrupted!)\n");
uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)]; uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)];
memset(empty, 0, sizeof(empty)); memset(empty, 0, sizeof(empty));

View file

@ -52,12 +52,17 @@
//To avoid possible future allocations, data region starts at the end of flash and goes upwards to the center region //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 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_block(uintptr_t addr, const uint8_t *data, size_t len);
extern int flash_program_halfword(uintptr_t addr, uint16_t data); extern int flash_program_halfword(uintptr_t addr, uint16_t data);