Description
First of all, thanks for the RP2350 PSRAM code which we borrowed for arduino-pico! It made things much easier to get PSRAM .heap
and .data
running for us when the Pico2 came out!
We recently ran into an issue where flash writes caused data loss in PSRAM. Basically the same two issues you discovered and worked around, we had the pleasure of discovering and working around on our own. We added the QMI register save/restore and the XIP cache clean process around flash operations and ended up with essentially your code, too.
However, under very dirty cache cleans the processor can repeatably end up crashing during the cleaning process. The debug is in the RPI Forum thread here.
Essentially, it seems that the XIP cache really need to be both cleaned and invalidated line-by-line before the flash operations. This would add another write in your cache clear loop,
circuitpython/ports/raspberrypi/supervisor/internal_flash.c
Lines 53 to 55 in 45e0cf1
becomes
for (int i = 1; i < 16 * 1024; i += 8) {
maintenance_ptr[i] = 0; // Clean (write back)
maintenance_ptr[i - 1] = 0; // Invalidate
}
If you do find users with random crashes under PSRAM and flash write workloads, this change might help avoid a lot of head scratching and hair pulling.
Thanks again for the great work!