From db40e442f5bac0d86b2895a28ae6799a3c2c3050 Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Sun, 19 Jan 2025 23:21:02 -0500 Subject: [PATCH 1/8] Update CMakeLists.txt Only require `sdmmc` when `CONFIG_LITTLEFS_SDMMC_SUPPORT` is set. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd6d847..6680984 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ list(APPEND SOURCES src/esp_littlefs.c src/littlefs_esp_part.c src/lfs_config.c) if(CONFIG_LITTLEFS_SDMMC_SUPPORT) list(APPEND SOURCES src/littlefs_sdmmc.c) + list(APPEND priv_requires sdmmc) endif() if(IDF_VERSION_MAJOR GREATER_EQUAL 5) @@ -12,7 +13,7 @@ if(IDF_VERSION_MAJOR GREATER_EQUAL 5) else() list(APPEND pub_requires spi_flash) endif() -list(APPEND priv_requires esptool_py spi_flash vfs sdmmc) +list(APPEND priv_requires esptool_py spi_flash vfs) idf_component_register( SRCS ${SOURCES} From c1491b95a59f8e83977922515519aafe71e68b8e Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Sun, 19 Jan 2025 23:24:05 -0500 Subject: [PATCH 2/8] Update esp_littlefs.c Avoid referring to `portMUX_INITIALIZER_UNLOCKED` and `portENTER_CRITICAL` / `portEXIT_CRITICAL`, which are not available for ESP8266 RTOS SDK. --- src/esp_littlefs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index ebc7a88..a5b95ae 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -899,13 +899,17 @@ static int esp_littlefs_flags_conv(int m) { static void esp_littlefs_take_efs_lock(void) { if( _efs_lock == NULL ){ +#ifdef ESP32 // ESP8266 only has one core, no need for SMP protection static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL(&mux); +#endif if( _efs_lock == NULL ){ _efs_lock = xSemaphoreCreateMutex(); assert(_efs_lock); } +#ifdef ESP32 portEXIT_CRITICAL(&mux); +#endif } xSemaphoreTake(_efs_lock, portMAX_DELAY); From 7a5a017011f48ea236b20f6918b65d1793d3c4d1 Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Mon, 20 Jan 2025 00:44:52 -0500 Subject: [PATCH 3/8] Update esp_littlefs.h ESP8266 RTOS SDK default enables VFS DIR support. --- include/esp_littlefs.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/esp_littlefs.h b/include/esp_littlefs.h index 101445a..ad4fbe5 100644 --- a/include/esp_littlefs.h +++ b/include/esp_littlefs.h @@ -19,6 +19,11 @@ extern "C" { #define ESP_LITTLEFS_VERSION_MINOR 16 #define ESP_LITTLEFS_VERSION_PATCH 2 +#ifdef ESP8266 +// ESP8266 RTOS SDK default enables VFS DIR support +#define CONFIG_VFS_SUPPORT_DIR 1 +#endif + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 2) && CONFIG_VFS_SUPPORT_DIR #define ESP_LITTLEFS_ENABLE_FTRUNCATE #endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 2) From da26995a562c6efea36c2c214f291846bb21ac11 Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Mon, 20 Jan 2025 11:27:23 -0500 Subject: [PATCH 4/8] Update esp_littlefs.c Use a more generic condition for ESP8266 RTOS SDK compatibility. --- src/esp_littlefs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index a5b95ae..b7ccc61 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -899,7 +899,7 @@ static int esp_littlefs_flags_conv(int m) { static void esp_littlefs_take_efs_lock(void) { if( _efs_lock == NULL ){ -#ifdef ESP32 // ESP8266 only has one core, no need for SMP protection +#if portNUM_PROCESSORS > 1 // SMP protection needed for multi-core static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL(&mux); #endif @@ -907,7 +907,7 @@ static void esp_littlefs_take_efs_lock(void) { _efs_lock = xSemaphoreCreateMutex(); assert(_efs_lock); } -#ifdef ESP32 +#if portNUM_PROCESSORS > 1 portEXIT_CRITICAL(&mux); #endif } From 687778f9de00ead9c09db7d8d1b0a5b4eba4193d Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Tue, 21 Jan 2025 00:09:16 -0500 Subject: [PATCH 5/8] Update CMakeLists.txt Add `sdmmc` to `pub_requires` since it is referred to in include/esp_littlefs.h --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6680984..c3623bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ list(APPEND SOURCES src/esp_littlefs.c src/littlefs_esp_part.c src/lfs_config.c) if(CONFIG_LITTLEFS_SDMMC_SUPPORT) list(APPEND SOURCES src/littlefs_sdmmc.c) list(APPEND priv_requires sdmmc) + list(APPEND pub_requires sdmmc) endif() if(IDF_VERSION_MAJOR GREATER_EQUAL 5) From 50d72a1b257f14168f7dd1a81dc6b7dc77c991f7 Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Tue, 21 Jan 2025 00:11:23 -0500 Subject: [PATCH 6/8] Update esp_littlefs.c Use `taskENTER_CRITICAL()` and `taskEXIT_CRITICAL()` for single core concurrency protection. --- src/esp_littlefs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index b7ccc61..9ef13b7 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -899,9 +899,11 @@ static int esp_littlefs_flags_conv(int m) { static void esp_littlefs_take_efs_lock(void) { if( _efs_lock == NULL ){ -#if portNUM_PROCESSORS > 1 // SMP protection needed for multi-core +#if portNUM_PROCESSORS > 1 static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL(&mux); +#else + taskENTER_CRITICAL(); #endif if( _efs_lock == NULL ){ _efs_lock = xSemaphoreCreateMutex(); @@ -909,6 +911,8 @@ static void esp_littlefs_take_efs_lock(void) { } #if portNUM_PROCESSORS > 1 portEXIT_CRITICAL(&mux); +#else + taskEXIT_CRITICAL(); #endif } From 4acf5f0a52ce3377a6e8b9fd52f0c9c1f0fa032a Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Tue, 21 Jan 2025 20:02:07 -0500 Subject: [PATCH 7/8] Update CMakeLists.txt `priv_requires` not needed if `pub_requires` is used. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3623bc..3d23559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ list(APPEND SOURCES src/esp_littlefs.c src/littlefs_esp_part.c src/lfs_config.c) if(CONFIG_LITTLEFS_SDMMC_SUPPORT) list(APPEND SOURCES src/littlefs_sdmmc.c) - list(APPEND priv_requires sdmmc) list(APPEND pub_requires sdmmc) endif() From b0dbabb5795666380beb07be59f69b3496399c99 Mon Sep 17 00:00:00 2001 From: Zhenyu Wu Date: Tue, 21 Jan 2025 20:04:30 -0500 Subject: [PATCH 8/8] Update esp_littlefs.c Use `ESP8266` to guard the concurrency protection API patch instead. --- src/esp_littlefs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 9ef13b7..711dc10 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -899,20 +899,20 @@ static int esp_littlefs_flags_conv(int m) { static void esp_littlefs_take_efs_lock(void) { if( _efs_lock == NULL ){ -#if portNUM_PROCESSORS > 1 +#ifdef ESP8266 + taskENTER_CRITICAL(); +#else static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL(&mux); -#else - taskENTER_CRITICAL(); #endif if( _efs_lock == NULL ){ _efs_lock = xSemaphoreCreateMutex(); assert(_efs_lock); } -#if portNUM_PROCESSORS > 1 - portEXIT_CRITICAL(&mux); -#else +#ifdef ESP8266 taskEXIT_CRITICAL(); +#else + portEXIT_CRITICAL(&mux); #endif }