diff --git a/cores/rp2040/flash_wrapper.cpp b/cores/rp2040/flash_wrapper.cpp index f447c60b1..e75c55d42 100644 --- a/cores/rp2040/flash_wrapper.cpp +++ b/cores/rp2040/flash_wrapper.cpp @@ -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 #include #ifdef PICO_RP2350 #include #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 @@ -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 @@ -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 @@ -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