Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RP2350 PSRAM cache flush to avoid possible crash under high write workloads #9746

Closed
earlephilhower opened this issue Oct 23, 2024 · 2 comments · Fixed by #9752
Closed

Comments

@earlephilhower
Copy link

earlephilhower commented Oct 23, 2024

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,

for (int i = 1; i < 16 * 1024; i += 8) {
maintenance_ptr[i] = 0;
}

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!

@earlephilhower earlephilhower changed the title Update PSRAM cache flush to avoid possible crash under high write workloads Update RP2350 PSRAM cache flush to avoid possible crash under high write workloads Oct 23, 2024
@dhalbert
Copy link
Collaborator

Thanks @earlephilhower! @tannewt would you like to do a PR?

@dhalbert dhalbert added this to the 9.2.0 milestone Oct 23, 2024
@tannewt
Copy link
Member

tannewt commented Oct 23, 2024

Yes, I'll make a PR. I think I got this code from MicroPython so I'll check there too. :-)

bablokb pushed a commit to bablokb/circuitpython that referenced this issue Nov 1, 2024
Clean alone can lead to crashes.

Fixes adafruit#9746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants