FreeRTOS+FAT file allocation corruption

andylong0206 wrote on June 21, 2018:


I have implemented a web server using FreeRTOS+TCP and FreeRTOS+FAT for my IoT project. It is using an external flash chip (SST25VF016B which has 2MB capacity). I have implemented wear levelling. All is good with that. However, when I transfer file(s) which are a few hundred kB, the FAT table keeps getting corrupt after FTP transfer. I’ve attached an image of what I am seing.

If I transfer just the TestImage.jpg, and observe the remote window in FileZilla, I can see the file momentarily getting placed correctly then a second later getting a corrupt name. If I transfer back to windows PC, rename the file and extension, the content of the file is correct. In this case the image is correct. The Flash driver implements CRC checking etc, so if the data was incorrect it would complain at that level. I’m reasonably confident that this is not a storage issue, it’s something else.

Incidentally if I use smaller of files seems to be OK.

Any Ideas or hints appreciated.



RIchardBarry-AWS wrote on June 22, 2018:

I think you are using code from the FreeRTOS Labs download, rather than code provided in the Amazon FreeRTOS git repo. Please correct me if I am wrong.

Do I understand correctly that if you FTP files onto your device, then FTP the same files off your device again, the received file matches the transmitted file. If so then both FTP and the file system would seem to be functional, and the only error is how the files are viewed in FileZilla.

If the above is accurate then it may be due to caching in FileZilla. FileZilla will show what it thinks is on the disk rather than manually reading back the files from the disk. Try re-freshing the display in FileZilla. I can’t remember the keys to do that, but it might be F5 or CTRL F5.

andylong0206 wrote on June 22, 2018:

Yes the code is from the FreeRTOS Labs download. Appologies if this is not the correct forum with FreeRTOS now being Amazon FreeRTOS and so on.

OK, so the FAT table is defo being corrupted and not a FileZilla refresh issue. This is real confusing the hell out of me. When I FTP copy folder structures the names get corrupted at some point during the transfer and I can’t go into the folders. Again, this only seems to be when the files within are large. The console print asserts no such folder when it gets corrupted.

I’m currently doing a sanity check on my flash storage again as this makes no senses at all presently.


andylong0206 wrote on June 23, 2018:

OK so I’ve resolved this issue myself…

In FreeRTOSFATconfig.h, if ffconfigWRITE_BOTH_FATS is set to 1, i.e. to FATS being maintained the FATS gets corrupt! By setting this to 0, yes you only have one FAT to rely on, but the issue has gone. I think there must be a bug somewhere, but for now this works for me. An up side of one FAT is that the efficiency is improved.

I hope this helps anyone using FreeRTOS-Plus-FAT and large(ish) files experiencing the same issue using FAT12.


RIchardBarry-AWS wrote on June 25, 2018:

Appreciate you taking the time to report back.