Chapter 2. API Reference
8. Call the FatFs function f_mount for the same drive number, with NULL FATFS* argument, to unmount
the filesystem.
9. Call the FatFs function ff_diskio_register() with NULL ff_diskio_impl_t* argument and
the same drive number to unregister the disk I/O driver.
10. Call esp_vfs_fat_unregister_path() with the path where the file system is mounted to remove
FatFs from VFS, and free the FATFS structure allocated in Step 1.
The convenience functions esp_vfs_fat_sdmmc_mount, esp_vfs_fat_sdspi_mount and
esp_vfs_fat_sdcard_unmount wrap the steps described above and also handle SD card initialization.
These two functions are described in the next section.
esp_err_t esp_vfs_fat_register(const char *base_path, const char *fat_drive, size_t max_files,
FATFS **out_fs)
Register FATFS with VFS component.
This function registers given FAT drive in VFS, at the specified base path. If only one drive is used, fat_drive
argument can be an empty string. Refer to FATFS library documentation on how to specify FAT drive. This
function also allocates FATFS structure which should be used for f_mount call.
Note This function doesn’t mount the drive into FATFS, it just connects POSIX and C standard library IO
function with FATFS. You need to mount desired drive into FATFS separately.
Return
• ESP_OK on success
• ESP_ERR_INVALID_STATE if esp_vfs_fat_register was already called
• ESP_ERR_NO_MEM if not enough memory or too many VFSes already registered
Parameters
• base_path: path prefix where FATFS should be registered
• fat_drive: FATFS drive specification; if only one drive is used, can be an empty string
• max_files: maximum number of files which can be open at the same time
• [out] out_fs: pointer to FATFS structure which can be used for FATFS f_mount call is re-
turned via this argument.
esp_err_t esp_vfs_fat_unregister_path(const char *base_path)
Un-register FATFS from VFS.
Note FATFS structure returned by esp_vfs_fat_register is destroyed after this call. Make sure to call f_mount
function to unmount it before calling esp_vfs_fat_unregister_ctx. Difference between this function and
the one above is that this one will release the correct drive, while the one above will release the last
registered one
Return
• ESP_OK on success
• ESP_ERR_INVALID_STATE if FATFS is not registered in VFS
Parameters
• base_path: path prefix where FATFS is registered. This is the same used when
esp_vfs_fat_register was called
Using FatFs with VFS and SD cards
The header file fatfs/vfs/esp_vfs_fat.h defines convenience functions esp_vfs_fat_sdmmc_mount(),
esp_vfs_fat_sdspi_mount() and esp_vfs_fat_sdcard_unmount(). These function perform
Steps 1–3 and 7–9 respectively and handle SD card initialization, but provide only limited error handling. Developers
are encouraged to check its source code and incorporate more advanced features into production applications.
The convenience function esp_vfs_fat_sdmmc_unmount() unmounts the filesystem and releases the re-
sources acquired by esp_vfs_fat_sdmmc_mount().
esp_err_t esp_vfs_fat_sdmmc_mount(const char *base_path, const sdmmc_host_t *host_config,
const void *slot_config, const esp_vfs_fat_mount_config_t
*mount_config, sdmmc_card_t **out_card)
Convenience function to get FAT filesystem on SD card registered in VFS.
This is an all-in-one function which does the following:
Espressif Systems 696
Submit Document Feedback
Release v4.4