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

Workaround PSRAM cache invalid'n by reading flash #2551

Merged
merged 7 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cores/rp2040/flash_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,35 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Arduino.h>
#include <hardware/flash.h>

#ifdef PICO_RP2350
#include <hardware/structs/qmi.h>
#endif

#if defined(PICO_RP2350) && defined(RP2350_PSRAM_CS)
static void __no_inline_not_in_flash_func(flushcache)() {
for (volatile uint8_t* cache = (volatile uint8_t*)0x18000001; cache < (volatile uint8_t*)(0x18000001 + 2048 * 8); cache += 8) {
*cache = 0;
__compiler_memory_barrier();
*(cache - 1) = 0;
__compiler_memory_barrier();
}
}
#elif defined(PICO_RP2350)
static void __no_inline_not_in_flash_func(flushcache)() {
// Null
}
#endif


extern "C" {
extern void __real_flash_range_erase(uint32_t flash_offs, size_t count);
void __wrap_flash_range_erase(uint32_t flash_offs, size_t count) {
#ifdef PICO_RP2350
auto s = qmi_hw->m[1];
flushcache();
#endif
__real_flash_range_erase(flash_offs, count);
#ifdef PICO_RP2350
Expand All @@ -41,6 +58,7 @@ extern "C" {
void __wrap_flash_range_program(uint32_t flash_offs, const uint8_t *data, size_t count) {
#ifdef PICO_RP2350
auto s = qmi_hw->m[1];
flushcache();
#endif
__real_flash_range_program(flash_offs, data, count);
#ifdef PICO_RP2350
Expand All @@ -53,6 +71,7 @@ extern "C" {
void __wrap_flash_get_unique_id(uint8_t *id_out) {
#ifdef PICO_RP2350
auto s = qmi_hw->m[1];
flushcache();
#endif
__real_flash_get_unique_id(id_out);
#ifdef PICO_RP2350
Expand All @@ -65,6 +84,7 @@ extern "C" {
void __wrap_flash_do_cmd(const uint8_t *txbuf, uint8_t *rxbuf, size_t count) {
#ifdef PICO_RP2350
auto s = qmi_hw->m[1];
flushcache();
#endif
__real_flash_do_cmd(txbuf, rxbuf, count);
#ifdef PICO_RP2350
Expand Down
Loading