FATFS Question

DDAA0621
Posts: 2
Joined: Fri Aug 20, 2021 4:39 pm

FATFS Question

Postby DDAA0621 » Tue Apr 22, 2025 2:48 pm

Quick question:
If I have fatfs initialized in my CMake file as this:

Code: Select all

fatfs_create_spiflash_image(storage ../store FLASH_IN_PROJECT)
Why can I not use:

Code: Select all

esp_vfs_fat_spiflash_mount_ro(BASE_PATH, "storage", &esp_vfs_fat_mount_config);
Every time I try this message is received:

Code: Select all

vfs_fat_spiflash: f_mount failed (13)
Basically fatfs is telling me:

Code: Select all

FR_NO_FILESYSTEM,		/* (13) There is no valid FAT volume */
But if I use:

Code: Select all

esp_vfs_fat_spiflash_mount_rw_wl(BASE_PATH, "storage", &esp_vfs_fat_mount_config, &wl_handle);
Everything works fine.

The only reason why I ask is because we have some issues when the device is shutdown unexpectedly, we occasionally see the flash get corrupted. The thought is if we mount the filesystem in read-only mode which is all we need most of the time. We can then if we do need to write to the flash we can:
- unmount read-only
- mount in read/write
- do our update
- unmount read/write
- mount read-only.
We are hoping that being in read only mode most of the time, will help mitigate any issues with flash corruption due to unexpected shut down.
I've been looking at the ESP-IDF documentation and I am not seeing anywhere it is telling me I can't do what I'm trying to do.

Sprite
Espressif staff
Espressif staff
Posts: 10619
Joined: Thu Nov 26, 2015 4:08 am

Re: FATFS Question

Postby Sprite » Wed Apr 23, 2025 2:06 am

The _wl_ is the hint. FAT filesystems in flash can have a wear leveling layer underneath them; this makes sure writes to the same file in flash won't wear out the underlying flash cells. If you only need a read-only FAT filesystem, you don't need this: if there's no writes, the flash won't wear out. FAT filesystems with wear leveling look different 'on-disk' because the wear levelling needs metadata to figure out what goes where, and that's why mounting it as a ro filesystem without wear leveling doesn't work.

I'm not sure if esp_vfs_fat_spiflash_mount_ro_wl exists, but I don't think the flash will be written to except when you explicitly open a file on the filesystem and write to it; I think you can get away with keeping it mounted RW but just not writing often and flushing the filesystem to disk directly after.

Who is online

Users browsing this forum: Baidu [Spider], Semrush [Bot] and 8 guests