From 58fffe7744d2053ace95f1383e6e93804d3dfad3 Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Wed, 22 Nov 2023 14:37:14 +0000 Subject: [PATCH 1/8] Add CFLAG to select SPIRAM heap caps malloc --- src/lfs_config.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lfs_config.h b/src/lfs_config.h index f57b183..501b70c 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -210,7 +210,12 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); // Note, memory must be 64-bit aligned static inline void *lfs_malloc(size_t size) { #ifndef LFS_NO_MALLOC +#ifdef LFS_MALLOC_SPIRAM + return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); +#else return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); +#endif + #else (void)size; return NULL; From 0336f5fd3186ecbb84aef4635068e4df0b96e76e Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Wed, 22 Nov 2023 14:44:11 +0000 Subject: [PATCH 2/8] Remove redundant whitespace --- src/lfs_config.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lfs_config.h b/src/lfs_config.h index 501b70c..718c217 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -215,7 +215,6 @@ static inline void *lfs_malloc(size_t size) { #else return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); #endif - #else (void)size; return NULL; From f61da67ffdd41130164872140c9a48aa89231f55 Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Tue, 28 Nov 2023 14:57:36 +0000 Subject: [PATCH 3/8] Kconfig for memory allocation strategy --- CMakeLists.txt | 4 ++++ Kconfig | 31 +++++++++++++++++++++++++++++++ src/esp_littlefs.c | 28 +++++++++++++++++++++------- src/lfs_config.h | 30 +++++++++++++++++++----------- 4 files changed, 75 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77db274..4568206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,3 +30,7 @@ endif() if(CONFIG_LITTLEFS_MULTIVERSION) target_compile_definitions(${COMPONENT_LIB} PUBLIC -DLFS_MULTIVERSION) endif() + +if(CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE) + target_compile_definitions(${COMPONENT_LIB} PUBLIC -DLFS_NO_MALLOC) +endif() diff --git a/Kconfig b/Kconfig index 2f01cfd..a43cc0d 100644 --- a/Kconfig +++ b/Kconfig @@ -208,4 +208,35 @@ menu "LittleFS" bool "Write LittleFS 2.0 (no forward-looking erase-state CRCs)" endchoice + + choice LITTLEFS_MALLOC_STRATEGY + prompt "Buffer allocation strategy" + default LITTLEFS_MALLOC_STRATEGY_GENERAL + help + Maps lfs_malloc to ESP-IDF capabilities-based memory allocator or + disables dynamic allocation in favour of user-provided static buffers. + + config LITTLEFS_MALLOC_STRATEGY_DISABLE + bool "Static buffers only" + help + Disallow dynamic allocation, static buffers must be provided by the calling application. + + config LITTLEFS_MALLOC_STRATEGY_GENERAL + bool "System malloc" + help + On systems with heap in PSRAM, if the allocation size exceeds SPIRAM_MALLOC_ALWAYSINTERNAL + then external heap will be preferred. + + config LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY + bool "Internal heap" + help + Uses ESP-IDF heap_caps_malloc to prefer allocation from internal heap. + + config LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY + bool "SPIRAM heap" + depends on SPIRAM_USE_MALLOC && ESP32_SPIRAM_SUPPORT + help + Uses ESP-IDF heap_caps_malloc to prefer allocation from SPIRAM heap. + + endchoice endmenu diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 86e9fc1..0bc2ecf 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -160,6 +160,16 @@ static esp_littlefs_t * _efs[CONFIG_LITTLEFS_MAX_PARTITIONS] = { 0 }; static const char * esp_littlefs_errno(enum lfs_error lfs_errno); #endif +static inline void * esp_littlefs_calloc(size_t __nmemb, size_t __size) { + /* Used internally by this wrapper only */ +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) + return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); +#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) + return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); +#else /* CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE, CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL and default */ + return calloc(__nmemb, __size); +#endif +} static void esp_littlefs_free_fds(esp_littlefs_t * efs) { /* Need to free all files that were opened */ @@ -239,7 +249,7 @@ esp_err_t format_from_efs(esp_littlefs_t *efs) return ESP_FAIL; } efs->cache_size = CONFIG_LITTLEFS_FD_CACHE_MIN_SIZE; // Initial size of cache; will resize ondemand - efs->cache = calloc(sizeof(*efs->cache), efs->cache_size); + efs->cache = esp_littlefs_calloc(sizeof(*efs->cache), efs->cache_size); } ESP_LOGV(ESP_LITTLEFS_TAG, "Format Success!"); @@ -686,7 +696,7 @@ static void esp_littlefs_take_efs_lock(void) { static esp_err_t esp_littlefs_init_efs(esp_littlefs_t** efs, const esp_partition_t* partition, bool read_only) { /* Allocate Context */ - *efs = calloc(1, sizeof(esp_littlefs_t)); + *efs = esp_littlefs_calloc(1, sizeof(esp_littlefs_t)); if (*efs == NULL) { ESP_LOGE(ESP_LITTLEFS_TAG, "esp_littlefs could not be malloced"); return ESP_ERR_NO_MEM; @@ -730,7 +740,7 @@ static esp_err_t esp_littlefs_init_efs(esp_littlefs_t** efs, const esp_partition return ESP_ERR_NO_MEM; } - (*efs)->fs = calloc(1, sizeof(lfs_t)); + (*efs)->fs = esp_littlefs_calloc(1, sizeof(lfs_t)); if ((*efs)->fs == NULL) { ESP_LOGE(ESP_LITTLEFS_TAG, "littlefs could not be malloced"); return ESP_ERR_NO_MEM; @@ -829,7 +839,7 @@ static esp_err_t esp_littlefs_init(const esp_vfs_littlefs_conf_t* conf) goto exit; } efs->cache_size = 4; - efs->cache = calloc(sizeof(*efs->cache), efs->cache_size); + efs->cache = esp_littlefs_calloc(sizeof(*efs->cache), efs->cache_size); if(conf->grow_on_mount){ res = lfs_fs_grow(efs->fs, efs->partition->size / efs->cfg.block_size); @@ -935,9 +945,9 @@ static int esp_littlefs_allocate_fd(esp_littlefs_t *efs, vfs_littlefs_file_t ** /* Allocate file descriptor here now */ #ifndef CONFIG_LITTLEFS_USE_ONLY_HASH - *file = calloc(1, sizeof(**file) + path_len); + *file = esp_littlefs_calloc(1, sizeof(**file) + path_len); #else - *file = calloc(1, sizeof(**file)); + *file = esp_littlefs_calloc(1, sizeof(**file)); #endif if (*file == NULL) { @@ -1156,8 +1166,12 @@ static int vfs_littlefs_open(void* ctx, const char * path, int flags, int mode) mkdirs(efs, path); #endif // CONFIG_LITTLEFS_SPIFFS_COMPAT +#ifndef CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE /* Open File */ res = lfs_file_open(efs->fs, &file->file, path, lfs_flags); +#else + #error "The use of static buffers is not current supported by this VFS wrapper" +#endif #if CONFIG_LITTLEFS_OPEN_DIR if ( flags & O_DIRECTORY && res == LFS_ERR_ISDIR) { @@ -1692,7 +1706,7 @@ static DIR* vfs_littlefs_opendir(void* ctx, const char* name) { int res; vfs_littlefs_dir_t *dir = NULL; - dir = calloc(1, sizeof(vfs_littlefs_dir_t)); + dir = esp_littlefs_calloc(1, sizeof(vfs_littlefs_dir_t)); if( dir == NULL ) { ESP_LOGE(ESP_LITTLEFS_TAG, "dir struct could not be malloced"); errno = ENOMEM; diff --git a/src/lfs_config.h b/src/lfs_config.h index 718c217..91e7a1a 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -12,15 +12,21 @@ #include #include #include -#include "esp_heap_caps.h" +#include "sdkconfig.h" #include "esp_log.h" -#ifndef LFS_NO_MALLOC + +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) || \ + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) || \ + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) #include +#include "esp_heap_caps.h" #endif + #ifndef LFS_NO_ASSERT #include #endif + #if !defined(LFS_NO_DEBUG) || \ !defined(LFS_NO_WARN) || \ !defined(LFS_NO_ERROR) || \ @@ -209,13 +215,13 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); // Allocate memory, only used if buffers are not provided to littlefs // Note, memory must be 64-bit aligned static inline void *lfs_malloc(size_t size) { -#ifndef LFS_NO_MALLOC -#ifdef LFS_MALLOC_SPIRAM - return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); -#else - return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); -#endif -#else +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) + return malloc(size); +#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) + return heap_caps_aligned_alloc(8, size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); +#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) + return heap_caps_aligned_alloc(8, size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); +#else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default (void)size; return NULL; #endif @@ -223,9 +229,11 @@ static inline void *lfs_malloc(size_t size) { // Deallocate memory, only used if buffers are not provided to littlefs static inline void lfs_free(void *p) { -#ifndef LFS_NO_MALLOC +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) || \ + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) || \ + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) free(p); -#else +#else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default (void)p; #endif } From ba9bfffcf67b3bd95d95c64db0a36d357600450d Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Tue, 28 Nov 2023 15:11:44 +0000 Subject: [PATCH 4/8] Remove "ONLY" from strategy as may be misleading --- Kconfig | 4 ++-- src/esp_littlefs.c | 4 ++-- src/lfs_config.h | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Kconfig b/Kconfig index a43cc0d..ab9d906 100644 --- a/Kconfig +++ b/Kconfig @@ -227,12 +227,12 @@ menu "LittleFS" On systems with heap in PSRAM, if the allocation size exceeds SPIRAM_MALLOC_ALWAYSINTERNAL then external heap will be preferred. - config LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY + config LITTLEFS_MALLOC_STRATEGY_INTERNAL bool "Internal heap" help Uses ESP-IDF heap_caps_malloc to prefer allocation from internal heap. - config LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY + config LITTLEFS_MALLOC_STRATEGY_SPIRAM bool "SPIRAM heap" depends on SPIRAM_USE_MALLOC && ESP32_SPIRAM_SUPPORT help diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 0bc2ecf..73330b0 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -162,9 +162,9 @@ static const char * esp_littlefs_errno(enum lfs_error lfs_errno); static inline void * esp_littlefs_calloc(size_t __nmemb, size_t __size) { /* Used internally by this wrapper only */ -#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); -#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) +#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); #else /* CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE, CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL and default */ return calloc(__nmemb, __size); diff --git a/src/lfs_config.h b/src/lfs_config.h index 91e7a1a..cc7b73a 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -17,8 +17,8 @@ #if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) || \ - defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) || \ - defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) || \ + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) #include #include "esp_heap_caps.h" #endif @@ -217,9 +217,9 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); static inline void *lfs_malloc(size_t size) { #if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) return malloc(size); -#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) +#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) return heap_caps_aligned_alloc(8, size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); -#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) +#elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) return heap_caps_aligned_alloc(8, size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); #else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default (void)size; @@ -230,8 +230,8 @@ static inline void *lfs_malloc(size_t size) { // Deallocate memory, only used if buffers are not provided to littlefs static inline void lfs_free(void *p) { #if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) || \ - defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL_ONLY) || \ - defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM_ONLY) + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) || \ + defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) free(p); #else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default (void)p; From 1804da9991ccf544f77ef7f9e7f8c52a6a951f89 Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Tue, 28 Nov 2023 15:38:32 +0000 Subject: [PATCH 5/8] Add Kconfig for asserts --- CMakeLists.txt | 4 ++++ Kconfig | 9 ++++++++- src/lfs_config.h | 6 ++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4568206..8d3dd96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,3 +34,7 @@ endif() if(CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE) target_compile_definitions(${COMPONENT_LIB} PUBLIC -DLFS_NO_MALLOC) endif() + +if(NOT CONFIG_LITTLEFS_ASSERTS) + target_compile_definitions(${COMPONENT_LIB} PUBLIC -DLFS_NO_ASSERT) +endif() diff --git a/Kconfig b/Kconfig index ab9d906..3849bce 100644 --- a/Kconfig +++ b/Kconfig @@ -238,5 +238,12 @@ menu "LittleFS" help Uses ESP-IDF heap_caps_malloc to prefer allocation from SPIRAM heap. - endchoice + endchoice + + config LITTLEFS_ASSERTS + bool "Enable asserts" + default "y" + help + Selects whether littlefs performs runtime assert checks. + endmenu diff --git a/src/lfs_config.h b/src/lfs_config.h index cc7b73a..c54ffc0 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -23,7 +23,7 @@ #include "esp_heap_caps.h" #endif -#ifndef LFS_NO_ASSERT +#ifdef CONFIG_LITTLEFS_ASSERTS #include #endif @@ -87,13 +87,11 @@ extern const char ESP_LITTLEFS_TAG[]; #endif // Runtime assertions -#ifndef LFS_ASSERT -#ifndef LFS_NO_ASSERT +#ifdef CONFIG_LITTLEFS_ASSERTS #define LFS_ASSERT(test) assert(test) #else #define LFS_ASSERT(test) #endif -#endif // Builtin functions, these may be replaced by more efficient From 717f2c13933363bc5e4c56f89090280211e0255f Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Wed, 29 Nov 2023 14:46:15 +0000 Subject: [PATCH 6/8] Revert 64-bit buffer alignment requirement --- Kconfig | 16 +++++++++------- src/esp_littlefs.c | 2 +- src/lfs_config.h | 14 +++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Kconfig b/Kconfig index 3849bce..2cdce46 100644 --- a/Kconfig +++ b/Kconfig @@ -211,7 +211,7 @@ menu "LittleFS" choice LITTLEFS_MALLOC_STRATEGY prompt "Buffer allocation strategy" - default LITTLEFS_MALLOC_STRATEGY_GENERAL + default LITTLEFS_MALLOC_STRATEGY_DEFAULT help Maps lfs_malloc to ESP-IDF capabilities-based memory allocator or disables dynamic allocation in favour of user-provided static buffers. @@ -221,22 +221,24 @@ menu "LittleFS" help Disallow dynamic allocation, static buffers must be provided by the calling application. - config LITTLEFS_MALLOC_STRATEGY_GENERAL - bool "System malloc" + config LITTLEFS_MALLOC_STRATEGY_DEFAULT + bool "Default heap selection" help - On systems with heap in PSRAM, if the allocation size exceeds SPIRAM_MALLOC_ALWAYSINTERNAL - then external heap will be preferred. + Uses an automatic allocation strategy. On systems with heap in SPIRAM, if + the allocation size does not exceed SPIRAM_MALLOC_ALWAYSINTERNAL then internal + heap allocation if preferred, otherwise allocation will be attempted from SPIRAM + heap. config LITTLEFS_MALLOC_STRATEGY_INTERNAL bool "Internal heap" help - Uses ESP-IDF heap_caps_malloc to prefer allocation from internal heap. + Uses ESP-IDF heap_caps_malloc to allocate from internal heap. config LITTLEFS_MALLOC_STRATEGY_SPIRAM bool "SPIRAM heap" depends on SPIRAM_USE_MALLOC && ESP32_SPIRAM_SUPPORT help - Uses ESP-IDF heap_caps_malloc to prefer allocation from SPIRAM heap. + Uses ESP-IDF heap_caps_malloc to allocate from SPIRAM heap. endchoice diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 73330b0..3d0db14 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -166,7 +166,7 @@ static inline void * esp_littlefs_calloc(size_t __nmemb, size_t __size) { return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); #elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); -#else /* CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE, CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL and default */ +#else /* CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE, CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT and default */ return calloc(__nmemb, __size); #endif } diff --git a/src/lfs_config.h b/src/lfs_config.h index c54ffc0..58b138b 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -16,7 +16,7 @@ #include "esp_log.h" -#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) || \ +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT) || \ defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) || \ defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) #include @@ -211,14 +211,14 @@ static inline uint32_t lfs_tobe32(uint32_t a) { uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); // Allocate memory, only used if buffers are not provided to littlefs -// Note, memory must be 64-bit aligned +// For the lookahead buffer, memory must be 32-bit aligned static inline void *lfs_malloc(size_t size) { -#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) - return malloc(size); +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT) + return malloc(size); // Equivalent to heap_caps_malloc_default(size); #elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) - return heap_caps_aligned_alloc(8, size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); #elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) - return heap_caps_aligned_alloc(8, size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); #else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default (void)size; return NULL; @@ -227,7 +227,7 @@ static inline void *lfs_malloc(size_t size) { // Deallocate memory, only used if buffers are not provided to littlefs static inline void lfs_free(void *p) { -#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_GENERAL) || \ +#if defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT) || \ defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) || \ defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) free(p); From 0f6d52c9b9f83dafbd6e34686746f8565a5c3410 Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Wed, 29 Nov 2023 15:04:50 +0000 Subject: [PATCH 7/8] Wording --- src/esp_littlefs.c | 4 ++-- src/lfs_config.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 3d0db14..a226682 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -166,7 +166,7 @@ static inline void * esp_littlefs_calloc(size_t __nmemb, size_t __size) { return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); #elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) return heap_caps_calloc(__nmemb, __size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); -#else /* CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE, CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT and default */ +#else /* CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE, CONFIG_LITTLEFS_MALLOC_STRATEGY_DEFAULT or not defined */ return calloc(__nmemb, __size); #endif } @@ -1170,7 +1170,7 @@ static int vfs_littlefs_open(void* ctx, const char * path, int flags, int mode) /* Open File */ res = lfs_file_open(efs->fs, &file->file, path, lfs_flags); #else - #error "The use of static buffers is not current supported by this VFS wrapper" + #error "The use of static buffers is not currently supported by this VFS wrapper" #endif #if CONFIG_LITTLEFS_OPEN_DIR diff --git a/src/lfs_config.h b/src/lfs_config.h index 58b138b..95a34cf 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -219,7 +219,7 @@ static inline void *lfs_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); #elif defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); -#else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default +#else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE or not defined (void)size; return NULL; #endif From e63e049284df2fc47dc2b37f0e49f656650f8554 Mon Sep 17 00:00:00 2001 From: Tony Jackson Date: Wed, 29 Nov 2023 15:08:42 +0000 Subject: [PATCH 8/8] Wording --- src/lfs_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lfs_config.h b/src/lfs_config.h index 95a34cf..1a2a506 100644 --- a/src/lfs_config.h +++ b/src/lfs_config.h @@ -231,7 +231,7 @@ static inline void lfs_free(void *p) { defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_INTERNAL) || \ defined(CONFIG_LITTLEFS_MALLOC_STRATEGY_SPIRAM) free(p); -#else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE and default +#else // CONFIG_LITTLEFS_MALLOC_STRATEGY_DISABLE or not defined (void)p; #endif }