Need help mounting a FAT partition

User avatar
MickPF
Posts: 62
Joined: Tue Apr 03, 2018 8:47 pm

Need help mounting a FAT partition

Postby MickPF » Thu Dec 25, 2025 9:03 pm

Hello,

After a long break, I'm working with ESP32 again.

For development, I'm using ESP-IDF 5.5.2 under Linux and an ESP32-S3-DevKitC-1.

I performed following steps:

[*]Created the partition table $PROJECT_DIR/partitions.csv:

Code: Select all

# ESP-IDF Partition Table
# This partition table is design for 16 or 32 MB flash
#
# Name,          Type, SubType, Offset,   Size, Flags
nvs,            data,   nvs,        0x009000,  24K,
phy_init,       data,   phy,        0x00f000,   4K,
factory,        app,    factory,    0x010000,   1M,
storage,        data,   fat,                ,   8M,
[*]Enabled my own partition table in the configuration. See "Screenshot 1" in the attachment,

[*]and set up FAT filesystem support (see "Screenshot 2").

[*]My code looks like this:

Code: Select all

static wl_handle_t  wl_handle = WL_INVALID_HANDLE;

char * const        part_name = "storage";
char * const        base_path = "/flash";

esp_vfs_fat_mount_config_t  mount_config =
{
    .max_files              = 10,
    .format_if_mount_failed = false,
    .allocation_unit_size   = CONFIG_WL_SECTOR_SIZE,
    .use_one_fat            = false,
};

esp_err_t flash_init(void)
{

    ESP_ERROR_CHECK(esp_vfs_fat_spiflash_mount_rw_wl(base_path, part_name, &mount_config, &wl_handle));

    ...
}
[*]Compiled this code with

idf.py build

[*]Copied files that the partition should contain to the directory $PROJECT_DIR/fat_partition

[*]Added the following line to the CMake file $PROJECT_DIR/main/CMakeLists.txt

Code: Select all

fatfs_create_spiflash_image( "storage" "${PROJECT_DIR}/fat_partition" FLASH_IN_PROJECT )
[*]Wrote the flash memory using command

idf.py flash

Its output

Code: Select all

Executing action: flash
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-S3
Running ninja in directory /home/mick/Projects/ESP-IDF/eve/build
Executing "ninja flash"...
[1/6] cd /home/mick/Projects/ESP-IDF/eve/build/esp-idf/esptool_p...artition-table.bin /home/mick/Projects/ESP-IDF/eve/build/eve.bin
eve.bin binary size 0x67080 bytes. Smallest app partition is 0x100000 bytes. 0x98f80 bytes (60%) free.
[1/1] cd /home/mick/Projects/ESP-IDF/eve/build/bootloader/esp-id... /home/mick/Projects/ESP-IDF/eve/build/bootloader/bootloader.bin
Bootloader binary size 0x5410 bytes. 0x2bf0 bytes (34%) free.
[5/6] cd /opt/ESP32/ESP-IDF/v5.5.2/components/esptool_py && /usr...ESP32/ESP-IDF/v5.5.2/components/esptool_py/run_serial_tool.cmake
esptool.py --chip esp32s3 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dout --flash_freq 80m --flash_size detect 0x0 bootloader/bootloader.bin 0x10000 eve.bin 0x8000 partition_table/partition-table.bin 0x110000 storage.bin
esptool.py v4.11.dev1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 16MB (AP_1v8)
Crystal is 40MHz
MAC: 90:e5:b1:cb:89:14
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 32MB
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00010000 to 0x00077fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x00110000 to 0x0090ffff...
SHA digest in image updated
Compressed 21520 bytes to 13707...
Writing at 0x00000000... (100 %)
Wrote 21520 bytes (13707 compressed) at 0x00000000 in 0.5 seconds (effective 314.9 kbit/s)...
Hash of data verified.
Compressed 422016 bytes to 190303...
Writing at 0x000730d8... (100 %)
Wrote 422016 bytes (190303 compressed) at 0x00010000 in 5.3 seconds (effective 633.5 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 119...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (119 compressed) at 0x00008000 in 0.0 seconds (effective 551.6 kbit/s)...
Hash of data verified.
Compressed 8388608 bytes to 78236...
Writing at 0x001c3ae3... (100 %)
Wrote 8388608 bytes (78236 compressed) at 0x00110000 in 55.3 seconds (effective 1214.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Done
[*]When I now run the monitor program with

idf.py monitor

I get the following Output:

Code: Select all

Executing action: monitor
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-S3
Running idf_monitor in directory /home/mick/Projects/ESP-IDF/eve
Executing "/opt/ESP32/tools/current/python_env/idf5.5_py3.12_env/bin/python /opt/ESP32/ESP-IDF/v5.5.2/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32s3-elf- --target esp32s3 --revision 0 /home/mick/Projects/ESP-IDF/eve/build/eve.elf /home/mick/Projects/ESP-IDF/eve/build/bootloader/bootloader.elf -m '/opt/ESP32/tools/current/python_env/idf5.5_py3.12_env/bin/python' '/opt/ESP32/ESP-IDF/v5.5.2/tools/idf.py'"...
--- esp-idf-monitor 1.8.0 on /dev/ttyUSB0 115200
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0xa (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fce2820,len:0x15bc
load:0x403c8700,len:0xe2c
--- 0x403c8700: _stext at ??:?
load:0x403cb700,len:0x2fcc
entry 0x403c8944
--- 0x403c8944: call_start_cpu0 at /opt/ESP32/ESP-IDF/v5.5.2/components/bootloader/subproject/main/bootloader_start.c:25
I (32) boot: ESP-IDF v5.5.2-dirty 2nd stage bootloader
I (33) boot: compile time Dec 25 2025 20:33:37
I (33) boot: Multicore bootloader
I (34) boot: chip revision: v0.2
I (36) boot: efuse block revision: v1.3
I (40) boot.esp32s3: Boot SPI Speed : 80MHz
I (44) boot.esp32s3: SPI Mode       : SLOW READ
I (48) boot.esp32s3: SPI Flash Size : 32MB
I (52) boot: Enabling RNG early entropy source...
I (56) boot: Partition Table:
I (59) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (78) boot:  2 factory          factory app      00 00 00010000 00100000
I (85) boot:  3 storage          Unknown data     01 81 00110000 00800000
I (91) boot: End of partition table
I (95) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=0e1fch ( 57852) map
I (116) esp_image: segment 1: paddr=0001e224 vaddr=3fc96c00 size=01df4h (  7668) load
I (118) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=29500h (169216) map
I (161) esp_image: segment 3: paddr=00049528 vaddr=3fc989f4 size=1af9ch (110492) load
I (190) esp_image: segment 4: paddr=000644cc vaddr=40374000 size=12b60h ( 76640) load
I (212) esp_image: segment 5: paddr=00077034 vaddr=50000000 size=00020h (    32) load
I (225) boot: Loaded app from partition at offset 0x10000
I (225) boot: Disabling RNG early entropy source...
I (236) octal_psram: vendor id    : 0x0d (AP)
I (236) octal_psram: dev id       : 0x03 (generation 4)
I (236) octal_psram: density      : 0x05 (128 Mbit)
I (238) octal_psram: good-die     : 0x01 (Pass)
I (242) octal_psram: Latency      : 0x01 (Fixed)
I (247) octal_psram: VCC          : 0x00 (1.8V)
I (251) octal_psram: SRF          : 0x01 (Fast Refresh)
I (256) octal_psram: BurstType    : 0x01 (Hybrid Wrap)
I (261) octal_psram: BurstLen     : 0x01 (32 Byte)
I (265) octal_psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (270) octal_psram: DriveStrength: 0x00 (1/1)
I (274) MSPI Timing: Enter psram timing tuning
I (279) esp_psram: Found 16MB PSRAM device
I (282) esp_psram: Speed: 80MHz
I (285) cpu_start: Multicore app
I (1140) esp_psram: SPI SRAM memory test OK
I (1149) cpu_start: GPIO 44 and 43 are used as console UART I/O pins
I (1149) cpu_start: Pro cpu start user code
I (1149) cpu_start: cpu freq: 240000000 Hz
I (1151) app_init: Application information:
I (1155) app_init: Project name:     eve
I (1159) app_init: App version:      1
I (1162) app_init: Compile time:     Dec 25 2025 20:33:31
I (1167) app_init: ELF file SHA256:  65ce9b6d6...
I (1172) app_init: ESP-IDF:          v5.5.2-dirty
I (1176) efuse_init: Min chip rev:     v0.0
I (1180) efuse_init: Max chip rev:     v0.99
I (1184) efuse_init: Chip rev:         v0.2
I (1188) heap_init: Initializing. RAM available for dynamic allocation:
I (1194) heap_init: At 3FCB4490 len 00035280 (212 KiB): RAM
I (1200) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (1205) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (1210) heap_init: At 600FE000 len 00001FE8 (7 KiB): RTCRAM
I (1216) esp_psram: Adding pool of 16384K of PSRAM memory to heap allocator
I (1223) spi_flash: detected chip: mxic (opi)
I (1226) spi_flash: flash io: opi_str
I (1230) sleep_gpio: Configure to isolate all GPIO pins in sleep state
I (1236) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (1243) main_task: Started on CPU0
I (1273) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (1273) main_task: Calling app_main()
E (1283) vfs_fat_spiflash: f_mount failed with error: "No filesystem detected" [13]. (This may indicate corrupt FS, or attempt to mount read-only fatfsgen image for write)
ESP_ERROR_CHECK failed: esp_err_t 0xffffffff (ESP_FAIL) at 0x4200b6dc
--- 0x4200b6dc: flash_init at /home/mick/Projects/ESP-IDF/eve/components/flash/flash.c:101
file: "./components/flash/flash.c" line 101
func: flash_init
expression: esp_vfs_fat_spiflash_mount_rw_wl(base_path, part_name, &mount_config, &wl_handle)

abort() was called at PC 0x4037bf87 on core 0
--- 0x4037bf87: _esp_error_check_failed at /opt/ESP32/ESP-IDF/v5.5.2/components/esp_system/esp_err.c:49


Backtrace: 0x4037bfc9:0x3fcb68b0 0x4037bf91:0x3fcb68d0 0x403839e1:0x3fcb68f0 0x4037bf87:0x3fcb6960 0x4200b6dc:0x3fcb6990 0x4200a4ca:0x3fcb69b0 0x4202865f:0x3fcb69e0 0x4037cc95:0x3fcb6a00
--- 0x4037bfc9: panic_abort at /opt/ESP32/ESP-IDF/v5.5.2/components/esp_system/panic.c:477
--- 0x4037bf91: esp_system_abort at /opt/ESP32/ESP-IDF/v5.5.2/components/esp_system/port/esp_system_chip.c:87
--- 0x403839e1: abort at /opt/ESP32/ESP-IDF/v5.5.2/components/newlib/src/abort.c:38
--- 0x4037bf87: _esp_error_check_failed at /opt/ESP32/ESP-IDF/v5.5.2/components/esp_system/esp_err.c:49
--- 0x4200b6dc: flash_init at /home/mick/Projects/ESP-IDF/eve/components/flash/flash.c:101
--- 0x4200a4ca: app_main at /home/mick/Projects/ESP-IDF/eve/main/main.c:288
--- 0x4202865f: main_task at /opt/ESP32/ESP-IDF/v5.5.2/components/freertos/app_startup.c:208
--- 0x4037cc95: vPortTaskWrapper at /opt/ESP32/ESP-IDF/v5.5.2/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139




ELF file SHA256: 65ce9b6d6

CPU halted.
Are there ways to determine the contents (directories and files) of the created partition file after it has been created?

What am I doing wrong?

Can someone please help me to solve this problem?

Thanks in Advance,
Michael
Attachments
Screenshot 2.png
Screenshot 2.png (167.01 KiB) Viewed 1433 times
Screenshot 1.png
Screenshot 1.png (87.65 KiB) Viewed 1433 times

nopnop2002
Posts: 347
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Need help mounting a FAT partition

Postby nopnop2002 » Fri Dec 26, 2025 12:49 am


User avatar
MickPF
Posts: 62
Joined: Tue Apr 03, 2018 8:47 pm

Re: Need help mounting a FAT partition

Postby MickPF » Fri Dec 26, 2025 2:09 am

Hello,

Yes! This example runs with the same hardware settings as my project.

The only difference is that this example doesn't load the partition at all, but instead formats an empty partition:

Code: Select all

    // To mount device we need name of device partition, define base_path
    // and allow format partition in case if it is new one and was not formatted before
    const esp_vfs_fat_mount_config_t mount_config = {
            .max_files = 4, // Number of files that can be open at a time
            .format_if_mount_failed = true, // If true, try to format the partition if mount fails
            .allocation_unit_size = CONFIG_WL_SECTOR_SIZE, // Size of allocation unit, cluster size.
            .use_one_fat = false, // Use only one FAT table (reduce memory usage), but decrease reliability of file system in case of power failure.
    };
I set "format_if_mount_failed" to "false" and flash a prepared partition from file! When I set it to "true", my code works also, but it formats the FAT partition and the files are lost!

The error must reside in the partition creation by the script "$IDF_PATH/components/fatfs/fatfsgen.py". May be it creates an incompatible partition file.

User avatar
MickPF
Posts: 62
Joined: Tue Apr 03, 2018 8:47 pm

Re: Need help mounting a FAT partition

Postby MickPF » Fri Dec 26, 2025 2:20 am

The cause of the error lies in the sector size:
It doesn't work with sector_size=512, but it works with sector_size=4096!

pacucha42
Espressif staff
Espressif staff
Posts: 40
Joined: Fri Mar 29, 2019 12:56 pm

Re: Need help mounting a FAT partition

Postby pacucha42 » Tue Dec 30, 2025 10:00 am

Hi @MickPF,
addendum to your research:
- formatting FAT means all the data is lost, the file system is simply (re)built from scratch (as any other file system)
- the sector size matters a lot as it's the basic unit for building clusters (the smallest cluster == 1 sector). fatfsgen.py has a command-line parameter to influence the sector size used for generating the file system instance ([--sector_size {512,1024,2048,4096}]). The utility provides inline help:

Code: Select all

usage: fatfsgen.py [-h] [--output_file OUTPUT_FILE] [--partition_size PARTITION_SIZE] [--sector_size {512,1024,2048,4096}] [--sectors_per_cluster {1,2,4,8,16,32,64,128}] [--root_entry_count ROOT_ENTRY_COUNT] [--long_name_support] [--use_default_datetime] [--fat_type {12,16,0}] [--fat_count {1,2}] [--wl_mode {safe,perf}] input_directory

If you need any further info, please let us know

User avatar
MickPF
Posts: 62
Joined: Tue Apr 03, 2018 8:47 pm

Re: Need help mounting a FAT partition

Postby MickPF » Thu Jan 01, 2026 3:53 pm

Hi,

integrating creation of and flashing my FAT partition in the file "$PROJECT_DIR/main/CMakeLists.txt by the line

Code: Select all

fatfs_create_spiflash_image( "storage" "${PROJECT_DIR}/fat_partition" FLASH_IN_PROJECT )
creates a partition with sector size of 4096 bytes!
I could not find any way to change it to 512 bytes!

Maybe you know that way...

I can accept the sector size of 4096 bytes...

Thanks for your help...

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Need help mounting a FAT partition

Postby MicroController » Fri Jan 02, 2026 12:46 pm

Code: Select all

fatfs_create_spiflash_image( "storage" "${PROJECT_DIR}/fat_partition" FLASH_IN_PROJECT )
creates a partition with sector size of 4096 bytes!
I could not find any way to change it to 512 bytes!
Doesn't work with wear-levelling apparently:

Code: Select all

'sector_size' / Int32ul,  # always 4096 for the types of NOR flash supported by ESP-IDF!
...
self.total_sectors = self.partition_size // FATDefaults.WL_SECTOR_SIZE
Last edited by MicroController on Fri Jan 02, 2026 1:01 pm, edited 2 times in total.

User avatar
MickPF
Posts: 62
Joined: Tue Apr 03, 2018 8:47 pm

Re: Need help mounting a FAT partition

Postby MickPF » Fri Jan 02, 2026 12:53 pm

I made this setting right at the beginning, but it resulted in the creation of a partition that couldn't be mounted!

Like I said, I accept the sector size of 4096 bytes. The main thing is that it works. And it does!

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Need help mounting a FAT partition

Postby MicroController » Fri Jan 02, 2026 1:01 pm

Yeah, just checked; see my edit :)

User avatar
MickPF
Posts: 62
Joined: Tue Apr 03, 2018 8:47 pm

Re: Need help mounting a FAT partition

Postby MickPF » Fri Jan 02, 2026 1:25 pm

I'd like to end this discussion!

As I said, I'm perfectly happy with a sector size of 4096 bytes, and I have neither the time nor the inclination to play with all sorts of settings and code!

Who is online

Users browsing this forum: Bing [Bot], ChatGPT-User, PerplexityBot, Qwantbot, YisouSpider and 9 guests