I've successfully read and written flash to the last sector using the Pi Pico, but now on a custom board which utilizes the larger W25Q128JVS I'm having trouble.
EDIT TLDR: I write to the beginning of the last sector, then read back (by adding XIP_BASE to the address), but get all zeros instead of 0xFF (presumed empty flash value) or what I just wrote. PICO_FLASH_SIZE_BYTES seems okay (134217728).
This results in:I'd expect this to read back a 1 and 255 instead of 0 and 0. So either the buffer isn't being properly written, or I'm not reading from the same location it wrote to.
Also I was under the impression that the erased flash memory has a value of 0xFF, so if this is true I really must be reading from the wrong location? Or is 0xff a bad assumption?
Any ideas?
EDIT TLDR: I write to the beginning of the last sector, then read back (by adding XIP_BASE to the address), but get all zeros instead of 0xFF (presumed empty flash value) or what I just wrote. PICO_FLASH_SIZE_BYTES seems okay (134217728).
Code:
#define FLASH_LAST_SECTOR (PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE) PF("PICO_FLASH_SIZE_BYTES=%d", PICO_FLASH_SIZE_BYTES);page = 0; // for simplicity in debuggingmemset(buffer, 0xFF, FLASH_PAGE_SIZE);buffer[0] = settings.mode;buffer[1] = settings.sample_num;buffer[2] = settings.tone_num;flash_range_erase(FLASH_LAST_SECTOR, FLASH_SECTOR_SIZE);PF("----- Writing flash page=%d addr=%d\n", page, (FLASH_LAST_SECTOR + page * FLASH_PAGE_SIZE));PF("buffer[0]=%d buffer[4]=%d\n", buffer[0], buffer[4]);flash_range_program(FLASH_LAST_SECTOR + page * FLASH_PAGE_SIZE, (uint8_t *)buffer, FLASH_PAGE_SIZE);// add XIP_BASE to the address we just used in flash_range_program()uint32_t newaddr = XIP_BASE + (FLASH_LAST_SECTOR + page * FLASH_PAGE_SIZE);PF("XIP_BASE=%d + addr=%d == newaddr=%d\n", XIP_BASE, (FLASH_LAST_SECTOR + page * FLASH_PAGE_SIZE), newaddr);PF("read back buffer[0]=%d buffer[4]=%d\n", *(uint8_t *)(newaddr), *(uint8_t *)(newaddr+4));
Code:
PICO_FLASH_SIZE_BYTES=134217728----- Writing flash page=0 addr=134213632buffer[0]=1 buffer[4]=255XIP_BASE=268435456 + addr=134213632 == newaddr=402649088read back buffer[0]=0 buffer[4]=0
Also I was under the impression that the erased flash memory has a value of 0xFF, so if this is true I really must be reading from the wrong location? Or is 0xff a bad assumption?
Any ideas?
Statistics: Posted by mstrat — Tue Aug 13, 2024 5:18 pm — Replies 3 — Views 47