]> granicus.if.org Git - esp-idf/blobdiff - components/spi_flash/flash_mmap.c
Merge branch 'bugfix/freertos_check_task_waiting_termination' into 'master'
[esp-idf] / components / spi_flash / flash_mmap.c
index 2db0c2437f9de1434ad183352e1f35d734bd1274..52e64c11a5c61fc1087e9f843a036fc187813545 100644 (file)
@@ -31,6 +31,7 @@
 #include "esp_flash_encrypt.h"
 #include "esp_log.h"
 #include "cache_utils.h"
+#include "esp_spiram.h"
 
 #ifndef NDEBUG
 // Enable built-in checks in queue.h in debug builds
@@ -134,7 +135,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
             return ESP_ERR_INVALID_ARG;
         }
     }
-    mmap_entry_t* new_entry = (mmap_entry_t*) malloc(sizeof(mmap_entry_t));
+    mmap_entry_t* new_entry = (mmap_entry_t*) heap_caps_malloc(sizeof(mmap_entry_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
     if (new_entry == 0) {
         return ESP_ERR_NO_MEM;
     }
@@ -225,6 +226,9 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
        entire cache.
     */
     if (!did_flush && need_flush) {
+#if CONFIG_SPIRAM_SUPPORT
+        esp_spiram_writeback_cache();
+#endif
         Cache_Flush(0);
         Cache_Flush(1);
     }
@@ -330,6 +334,9 @@ static inline IRAM_ATTR bool update_written_pages(size_t start_addr, size_t leng
                tricky because mmaped memory can be used on un-pinned
                cores, or the pointer passed between CPUs.
             */
+#if CONFIG_SPIRAM_SUPPORT
+            esp_spiram_writeback_cache();
+#endif
             Cache_Flush(0);
 #ifndef CONFIG_FREERTOS_UNICORE
             Cache_Flush(1);