@@ -40,16 +40,20 @@ const esp_partition_t *check_ffat_partition(const char* label)
4040
4141bool F_Fat::begin (bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
4242{
43- if (_wl_handle){
43+ if (_wl_handle != WL_INVALID_HANDLE ){
4444 log_w (" Already Mounted!" );
4545 return true ;
4646 }
4747
48- if (!check_ffat_partition (partitionLabel)) return false ;
48+ if (!check_ffat_partition (partitionLabel)){
49+ log_e (" No fat partition found on flash" );
50+ return false ;
51+ }
4952
5053 esp_vfs_fat_mount_config_t conf = {
5154 .format_if_mount_failed = formatOnFail,
52- .max_files = maxOpenFiles
55+ .max_files = maxOpenFiles,
56+ .allocation_unit_size = CONFIG_WL_SECTOR_SIZE
5357 };
5458 esp_err_t err = esp_vfs_fat_spiflash_mount (basePath, partitionLabel, &conf, &_wl_handle);
5559 if (err){
@@ -62,13 +66,13 @@ bool F_Fat::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles
6266
6367void F_Fat::end ()
6468{
65- if (_wl_handle){
69+ if (_wl_handle != WL_INVALID_HANDLE ){
6670 esp_err_t err = esp_vfs_fat_spiflash_unmount (_impl->mountpoint (), _wl_handle);
6771 if (err){
6872 log_e (" Unmounting FFat partition failed! Error: %d" , err);
6973 return ;
7074 }
71- _wl_handle = 0 ;
75+ _wl_handle = WL_INVALID_HANDLE ;
7276 _impl->mountpoint (NULL );
7377 }
7478}
@@ -77,7 +81,7 @@ bool F_Fat::format(bool full_wipe, char* partitionLabel)
7781{
7882 esp_err_t result;
7983 bool res = true ;
80- if (_wl_handle){
84+ if (_wl_handle != WL_INVALID_HANDLE ){
8185 log_w (" Already Mounted!" );
8286 return false ;
8387 }
@@ -102,7 +106,8 @@ bool F_Fat::format(bool full_wipe, char* partitionLabel)
102106// Now do a mount with format_if_fail (which it will)
103107 esp_vfs_fat_mount_config_t conf = {
104108 .format_if_mount_failed = true ,
105- .max_files = 1
109+ .max_files = 1 ,
110+ .allocation_unit_size = CONFIG_WL_SECTOR_SIZE
106111 };
107112 result = esp_vfs_fat_spiflash_mount (" /format_ffat" , partitionLabel, &conf, &temp_handle);
108113 esp_vfs_fat_spiflash_unmount (" /format_ffat" , temp_handle);
0 commit comments