vfs_fat_spiflash: esp_vfs_fat_register failed 0x(101)

f.h-f.s.
Posts: 176
Joined: Thu Dec 08, 2016 2:53 pm

vfs_fat_spiflash: esp_vfs_fat_register failed 0x(101)

Postby f.h-f.s. » Wed Oct 18, 2017 8:52 am

Hi all,

I added the wear-level FAT filesystem to my project. Had low memory at the startup so I added a delay before I started the vfs and it works.

Then I wanted to move the startup of vfs to a callback I get when my connections are set up. When I start vfs at that point, esp_vfs_fat_register fails with error code 0x101(ESP_ERR_NO_MEM).

I traced the error to https://github.com/espressif/esp-idf/blob/master/components/fatfs/src/vfs_fat.c#L127
I also added a debug print line, to see if I was short on memory but that does not seem to be an issue.

Code: Select all

   size_t ctx_size = sizeof(vfs_fat_ctx_t) + max_files * sizeof(FIL);
   vfs_fat_ctx_t *fat_ctx = (vfs_fat_ctx_t *)calloc(1, ctx_size);
   ESP_LOGI(TAG, "fat_ctx == %p, ctx_size: %d, max_files: %d, sizeof(vfs_fat_ctx_t): %d, sizeof(FIL): %d, heap: %d, taskSHWM: %d", fat_ctx, ctx_size, max_files, sizeof(vfs_fat_ctx_t), sizeof(FIL), esp_get_free_heap_size(), uxTaskGetStackHighWaterMark(NULL));


Successful after startup of vfs with 2 minute delay:

Code: Select all

I (122564) BEA*ST: Starting log 62488, Stackhwm 2096
D (122564) vfs_fat_spiflash: using pdrv=0
I (122564) vfs_fat: fat_ctx == 0x3ffe436c, ctx_size: 22784, max_files: 4, sizeof(vfs_fat_ctx_t): 6240, sizeof(FIL): 4136, heap: 39320, taskSHWM: 2096
I (122574) FSLog: /spiflash/10180744
I (122574) FSLog: 65 bytes
I (122584) FSLog: /spiflash/10131108
I (122584) FSLog: 10069 bytes
I (122584) FSLog: /spiflash/10131115
I (122594) FSLog: 10031 bytes
I (122594) FSLog: /spiflash/10131124
I (122604) FSLog: 10004 bytes
I (122574) FSLog: Read total size: 30169
I (122604) FSLog: strftime: 18
Filename: /spiflash/10180818
I (122614) BEA*ST: Mount & Logging started


Fail when starting vfs from callback:

Code: Select all

I (7324) BEA*ST: Trying to mount & start log, Heap 58900, Stackhwm 6868
D (9334) vfs_fat_spiflash: using pdrv=0
I (9334) vfs_fat: fat_ctx == 0x0, ctx_size: 22784, max_files: 4, sizeof(vfs_fat_ctx_t): 6240, sizeof(FIL): 4136, heap: 58896, taskSHWM: 5540
D (9334) vfs_fat_spiflash: esp_vfs_fat_register failed 0x(101)
E (9404) FSLog: Failed to mount FATFS (0x101)


Success when decreasing the max files from 4 to 1:

Code: Select all

I (8804) BEA*ST: Trying to mount & start log, Heap 66440, Stackhwm 552
D (8814) vfs_fat_spiflash: using pdrv=0
I (8814) vfs_fat: fat_ctx == 0x3ffe06ac, ctx_size: 10376, max_files: 1, sizeof(vfs_fat_ctx_t): 6240, sizeof(FIL): 4136, heap: 55672, taskSHWM: 552
I (8834) FSLog: /spiflash/10180744
I (8834) FSLog: 65 bytes
I (8834) FSLog: /spiflash/10131108
I (8844) FSLog: 10069 bytes
I (8844) FSLog: /spiflash/10131115
I (8844) FSLog: 10031 bytes
I (8854) FSLog: /spiflash/10131124
I (8854) FSLog: 10004 bytes
I (8854) FSLog: /spiflash/10180818
I (8864) FSLog: 65 bytes
I (8864) FSLog: /spiflash/10180823
I (8874) FSLog: 65 bytes
I (8824) FSLog: Read total size: 30299
I (8874) FSLog: strftime: 18
Filename: /spiflash/10180828
I (8884) BEA*ST: Mount & Logging started


The issue is solved by decreasing max files from 4 to 1, but I would't mind knowing what caused the issue.
The calloc fails but why?

Who is online

Users browsing this forum: No registered users and 3 guests