Browse Source

fatfs: fix SPIRAM allocation not used due to Kconfig option name error

Closes https://github.com/espressif/esp-idf/issues/5756
Ivan Grokhotkov 5 years ago
parent
commit
c330def25a

+ 3 - 3
components/fatfs/port/freertos/ffsystem.c

@@ -8,7 +8,7 @@
 #include <stdlib.h>
 #include "ff.h"
 #include "sdkconfig.h"
-#ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST
+#ifdef CONFIG_FATFS_ALLOC_PREFER_EXTRAM
 #include "esp_heap_caps.h"
 #endif
 
@@ -16,8 +16,8 @@ void* ff_memalloc (    /* Returns pointer to the allocated memory block (null on
     unsigned msize     /* Number of bytes to allocate */
 )
 {
-#ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST
-    return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
+#ifdef CONFIG_FATFS_ALLOC_PREFER_EXTRAM
+    return heap_caps_malloc_prefer(msize, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
                                             MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);
 #else
     return malloc(msize);

+ 12 - 0
components/fatfs/test/test_fatfs_spiflash.c

@@ -223,3 +223,15 @@ TEST_CASE("(WL) opendir, readdir, rewinddir, seekdir work as expected using UTF-
     test_teardown();
 }
 #endif
+
+#ifdef CONFIG_SPIRAM
+TEST_CASE("FATFS prefers SPI RAM for allocations", "[fatfs]")
+{
+    test_setup();
+    DIR* dir = opendir("/spiflash");
+    TEST_ASSERT_NOT_NULL(dir);
+    TEST_ASSERT(esp_ptr_external_ram(dir));
+    closedir(dir);
+    test_teardown();
+}
+#endif // CONFIG_SPIRAM

+ 1 - 1
tools/unit-test-app/sdkconfig.defaults

@@ -24,6 +24,6 @@ CONFIG_COMPILER_WARN_WRITE_STRINGS=y
 CONFIG_SPI_MASTER_IN_IRAM=y
 CONFIG_EFUSE_VIRTUAL=y
 CONFIG_SPIRAM_BANKSWITCH_ENABLE=n
-CONFIG_FATFS_ALLOC_EXTRAM_FIRST=y
+CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y
 CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y
 CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n