From cc366cc3c77d485469022fb074dec5663df399a6 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 10 Sep 2020 01:04:32 +0200 Subject: [PATCH] fatfs: fix SPIRAM allocation not used due to Kconfig option name error Closes https://github.com/espressif/esp-idf/issues/5756 --- components/fatfs/port/freertos/ffsystem.c | 6 +++--- components/fatfs/test/test_fatfs_spiflash.c | 12 ++++++++++++ tools/unit-test-app/sdkconfig.defaults | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/fatfs/port/freertos/ffsystem.c b/components/fatfs/port/freertos/ffsystem.c index 45a894de52..e64195851a 100644 --- a/components/fatfs/port/freertos/ffsystem.c +++ b/components/fatfs/port/freertos/ffsystem.c @@ -8,7 +8,7 @@ #include #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); diff --git a/components/fatfs/test/test_fatfs_spiflash.c b/components/fatfs/test/test_fatfs_spiflash.c index 64dbe4ff0d..6f1e052fdf 100644 --- a/components/fatfs/test/test_fatfs_spiflash.c +++ b/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 diff --git a/tools/unit-test-app/sdkconfig.defaults b/tools/unit-test-app/sdkconfig.defaults index 3dd326e122..c3bda906d5 100644 --- a/tools/unit-test-app/sdkconfig.defaults +++ b/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