I am working on a new +FAT port. This is a media driver for SD Card over SPI.
At first I tested it with something similar to the FATFileSystem example at https://os.mbed.com/docs/mbed-os/v5.15/apis/fatfilesystem.html. That seemed to work well. Next, I tried FreeRTOSv10.2.1_191129\FreeRTOS-Labs\Demo\Common\FreeRTOS_Plus_FAT_Demos\CreateAndVerifyExampleFiles.c, and I am going crazy trying to debug this. It gets through prvCreateDemoFilesUsing_ff_fwrite OK, but, when it gets to prvVerifyDemoFileUsing_ff_fread, the files are gone!
Creating file /fs/root001.txt in /fs
Creating file /fs/root002.txt in /fs
Creating file /fs/root003.txt in /fs
Creating file /fs/root004.txt in /fs
Creating file /fs/root005.txt in /fs
Reading file root001.txt from /fs
FF_fopen(root001.txt): No such file or directory (-2)
assertion "pxFile" failed: file "CreateAndVerifyExampleFiles.c", line 236, function: prvVerifyDemoFileUsing_ff_fread
Sure enough, if I yank the card and put it into the slot on my PC, I don’t see the root???.txt files.
I added some more printf()s to the FATFileSystem example, and I added a directory listing in the middle:
ls();
err = ff_chdir("fs");
if (err < 0) {
FF_PRINTF("chdir error: %s (%d)\n", strerror(stdioGET_ERRNO()),
-stdioGET_ERRNO());
}
ls();
Sure enough, the numbers.txt file is there:
FF_Mount:
FF_FS_Add:
Reading FAT and calculating Free Space
Partition Nr 0
Type 12 (FAT32)
VolLabel 'NO NAME '
TotalSectors 15515648
SecsPerCluster 64
Size 7753728 KB
FreeSize 7753536 KB ( 100 perc free )
Opening "/fs/numbers.txt"... Fail :(
No file found, creating a new file... OK
Writing numbers (10/10)... OK
Seeking file... OK
Incrementing numbers (0/10)...
Incrementing numbers (1/10)...
Incrementing numbers (2/10)...
Incrementing numbers (3/10)...
Incrementing numbers (4/10)...
Incrementing numbers (5/10)...
Incrementing numbers (6/10)...
Incrementing numbers (7/10)...
Incrementing numbers (8/10)...
Incrementing numbers (10/10)... OK
Closing "/fs/numbers.txt"... OK
Directory Listing:
fs [directory] [size=1024]
. [directory] [size=1024]
Directory Listing:
System Volume Information [directory] [size=0]
numbers.txt [writable file] [size=60]
.. [directory] [size=1024]
. [directory] [size=1024]
Opening "/fs/numbers.txt"... OK
numbers:
5
6
7
8
9
10
11
12
13
Closing "/fs/numbers.txt"... OK
When I pull the card and mount it in Windows, sometimes I see numbers.txt, and sometimes I don’t. Similary, at the start of the test, sometimes the old file is found, but usually I get:
Opening "/fs/numbers.txt"... Fail :(
No file found, creating a new file... OK
What could be happening here? Am I missing some step needed to commit changes to the card? Is my hardware no good? (I did try a couple different microSD cards). What should I be looking at next?
CreateAndVerifyExampleFiles.c (16.0 KB)
x.c (5.9 KB)