I mounted a FATFS partition on it and I can read/write files correctly.
However I can't understand how to mount again the partition after I invalidate it.
The way I invalidate the flash partition is by erasing a block of memory (8 sectors). If I manually restart the ESP32-S2, all works well and it mounts again the partition.
If I try to mount the partition after the erasure, the ESP32 crashes giving:
Code: Select all
Guru Meditation Error: Core 0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400947a6 PS : 0x00060630 A0 : 0x80095d20 A1 : 0x3ffeb0b0
0x400947a6: f_mount at C:/Espressif/frameworks/esp-idf-v4.4.1/components/fatfs/src/ff.c:3527
A2 : 0x3ffcc760 A3 : 0x00000001 A4 : 0x00000001 A5 : 0x00000000
A6 : 0x00000004 A7 : 0x3ffcc77c A8 : 0x80094755 A9 : 0x3ffeb090
A10 : 0x00000001 A11 : 0x80088608 A12 : 0x3ffcc770 A13 : 0x3ffd31c0
A14 : 0xc98dc025 A15 : 0x3ffd452c SAR : 0x0000001a EXCCAUSE: 0x0000001d
EXCVADDR: 0x80088608 LBEG : 0x3ffcc770 LEND : 0x3ffd31c0 LCOUNT : 0x400243e1
0x400243e1: _xt_user_exc at C:/Espressif/frameworks/esp-idf-v4.4.1/components/freertos/port/xtensa/xtensa_vectors.S:633
Backtrace:0x400947a3:0x3ffeb0b00x40095d1d:0x3ffeb0f0 0x40089f96:0x3ffeb120 0x4008860b:0x3ffeb160
0x400947a3: f_mount at C:/Espressif/frameworks/esp-idf-v4.4.1/components/fatfs/src/ff.c:3537
0x40095d1d: esp_vfs_fat_spiflash_mount at C:/Espressif/frameworks/esp-idf-v4.4.1/components/fatfs/vfs/vfs_fat_spiflash.c:76
0x40089f96: spi_ext_flash_mount_fatfs at C:\Users\User\Documents\Lavoro\build/../components/spi_manager_component/spi_manage.c:191
0x4008860b: task_testing at C:\Users\User\Documents\Lavoro\build/../main/core.c:1690
ELF file SHA256: 3306af21b5f4bc15
Rebooting...
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4002339d
0x4002339d: esp_restart_noos_dig at C:/Espressif/frameworks/esp-idf-v4.4.1/components/esp_system/esp_system.c:44 (discriminator 1)
- esp_err_t spi_ext_flash_mount_fatfs (const char * partition_label)
- {
- ESP_LOGI(g_p_tag, "Mounting FAT filesystem");
- FATFS * p_filesys;
- uint32_t free_clusters = 0;
- uint32_t total_sectors = 0;
- uint32_t free_sectors = 0;
- wl_handle_t s_wl_handle = WL_INVALID_HANDLE;
- esp_err_t ret = ESP_FAIL;
- const esp_vfs_fat_mount_config_t mount_config = {
- .max_files = FAT_NMAX_FILES,
- .format_if_mount_failed = true,
- .allocation_unit_size = CONFIG_WL_SECTOR_SIZE,
- };
- ret = esp_vfs_fat_spiflash_mount(g_p_base_path, partition_label,
- &mount_config, &s_wl_handle);
- if (ret != ESP_OK)
- {
- ESP_LOGE(g_p_tag, "Failed to mount FATFS (%s)", esp_err_to_name(ret));
- ret = ESP_FAIL;
- }
- else
- {
- if (FR_OK == f_getfree("0:", &free_clusters, &p_filesys))
- {
- total_sectors = (p_filesys->n_fatent - 2) * p_filesys->csize;
- free_sectors = free_clusters * p_filesys->csize;
- ESP_LOGI(g_p_tag, "FAT FS: %d KB total, %d KB free",
- (total_sectors * p_filesys->ssize) / 1024,
- (free_sectors * p_filesys->ssize) / 1024);
- }
- else
- {
- ESP_LOGW(g_p_tag, "Errore nell'ottenimento dei cluster.");
- }
- ret = ESP_OK;
- }
- return ret;
- }