https://github.com/wreyford/demo_esp_littlefs/tree/main
I followed all the guides and precautions
IDF-extension 1.6.5
vcCode 1.85.1
ESP32 module kit
Espressif IDF 5.2
partitions Table:
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
littlefs, data, spiffs, , 0xF0000,
- [105/106] Generating binary image from built executable
esptool.py v4.7.0
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
Generated C:/Users/User/Desktop/Proiect_gen/Project_VSCode/demo_esp_littlefs/build/bootloader/bootloader.bin
[106/106] cmd.exe /C "cd /D C:\Users\User\Desktop\Proiect_gen\Project_VSCode\demo_esp_littlefs\build\bootloader\esp-idf\esptool_py && C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe C:/Espressif/frameworks/esp-idf-v5.2/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x1000 C:/Users/User/Desktop/Proiect_gen/Project_VSCode/demo_esp_littlefs/build/bootloader/bootloader.bin"
Bootloader binary size 0x6850 bytes. 0x7b0 bytes (7%) free.
[911/926] Building C object esp-idf/esp_littlefs/CMakeFiles/__idf_esp_littlefs.dir/src/littlefs/lfs.c.obj
ninja: build stopped: subcommand failed.
* Il processo del terminale "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command ninja " è stato terminato. Codice di uscita: 1.
- #include <stdio.h>
- #include "sdkconfig.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_system.h"
- #include "esp_spi_flash.h"
- #include "esp_err.h"
- #include "esp_log.h"
- #include "esp_littlefs.h"
- static const char *TAG = "demo_esp_littlefs";
- void app_main(void)
- {
- printf("Demo LittleFs implementation by esp_littlefs!\n");
- printf(" https://github.com/joltwallet/esp_littlefs\n");
- /* Print chip information */
- esp_chip_info_t chip_info;
- esp_chip_info(&chip_info);
- printf("This is %s chip with %d CPU cores, WiFi%s%s, ",
- CONFIG_IDF_TARGET,
- chip_info.cores,
- (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
- (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
- printf("silicon revision %d, ", chip_info.revision);
- printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
- (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
- printf("Free heap: %d\n", esp_get_free_heap_size());
- printf("Now we are starting the LittleFs Demo ...\n");
- ESP_LOGI(TAG, "Initializing LittelFS");
- esp_vfs_littlefs_conf_t conf = {
- .base_path = "/littlefs",
- .partition_label = "littlefs",
- .format_if_mount_failed = true,
- .dont_mount = false,
- };
- // Use settings defined above to initialize and mount LittleFS filesystem.
- // Note: esp_vfs_littlefs_register is an all-in-one convenience function.
- esp_err_t ret = esp_vfs_littlefs_register(&conf);
- if (ret != ESP_OK)
- {
- if (ret == ESP_FAIL)
- {
- ESP_LOGE(TAG, "Failed to mount or format filesystem");
- }
- else if (ret == ESP_ERR_NOT_FOUND)
- {
- ESP_LOGE(TAG, "Failed to find LittleFS partition");
- }
- else
- {
- ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
- }
- return;
- }
- size_t total = 0, used = 0;
- ret = esp_littlefs_info(conf.partition_label, &total, &used);
- if (ret != ESP_OK)
- {
- ESP_LOGE(TAG, "Failed to get LittleFS partition information (%s)", esp_err_to_name(ret));
- }
- else
- {
- ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
- }
- // Use POSIX and C standard library functions to work with files.
- // First create a file.
- ESP_LOGI(TAG, "Opening file");
- FILE *f = fopen("/littlefs/hello.txt", "w");
- if (f == NULL)
- {
- ESP_LOGE(TAG, "Failed to open file for writing");
- return;
- }
- fprintf(f, "LittleFS Rocks!\n");
- fclose(f);
- ESP_LOGI(TAG, "File written");
- // Check if destination file exists before renaming
- struct stat st;
- if (stat("/littlefs/foo.txt", &st) == 0)
- {
- // Delete it if it exists
- unlink("/littlefs/foo.txt");
- }
- // Rename original file
- ESP_LOGI(TAG, "Renaming file");
- if (rename("/littlefs/hello.txt", "/littlefs/foo.txt") != 0)
- {
- ESP_LOGE(TAG, "Rename failed");
- return;
- }
- // Open renamed file for reading
- ESP_LOGI(TAG, "Reading file");
- f = fopen("/littlefs/foo.txt", "r");
- if (f == NULL)
- {
- ESP_LOGE(TAG, "Failed to open file for reading");
- return;
- }
- char line[64];
- fgets(line, sizeof(line), f);
- fclose(f);
- // strip newline
- char *pos = strchr(line, '\n');
- if (pos)
- {
- *pos = '\0';
- }
- ESP_LOGI(TAG, "Read from file: '%s'", line);
- // All done, unmount partition and disable LittleFS
- esp_vfs_littlefs_unregister(conf.partition_label);
- ESP_LOGI(TAG, "LittleFS unmounted");
- }