1

We are using Chan's FatFS with FreeRTOS and lwIP on a board incorporating Cortex-M4. The board is able to send and receive files over a TCP socket and store them on SD card using FatFS.

I'm trying to test the functionality but seems like it's not operating correctly. When I send and receive the same file, each time the content gets corrupted in a similar manner. The most distinct characteristic of the corruption is that it appends two zero bytes to the beginning of file. This happens all the time while the rest of the corruption may differ (not significantly).

I'm aware that there is not enough information to solve the problem but I'm stuck and looking for some advises for troubleshooting the problem. Chan's code is pretty cryptic and I can not find my way through it.

Murat Şeker
  • 1,651
  • 1
  • 16
  • 29
  • You will need to start narrowing down the cause of the problem. If a transfer fails then either the FAT read, the TCP/IP transfer, the FAT write, or some glue logic in between is at fault. I suggest you start preparing a well-known test file ("Hello World", say) in the file system of the source device, add debug traces to the I/O buffers and calls on both ends, and hook a network sniffer. If the fault is intermittent then add assertions and stop on unexpected data. Oh, if it is intermittent and as there's an RTOS involved then do go over all of your locks and threading with a fine-tooth comb. – doynax Apr 18 '17 at 20:59
  • Hi, thanks for valuable tips. I think problem is not related to TCP because I've already sniffed the traffic and reconstructed the original file successfully. I believe it should have a relation with sector boundaries somehow because as far as I can see the file is corrupted on 0th, 512nd, 1024th.. bytes. – Murat Şeker Apr 18 '17 at 21:37

2 Answers2

1

For anyone having a similar issue, I've found a workaround. If I limit read-write operations to sector size (512 B), everything works OK. It probably reduces throughput but reliability is our top prio right now.

I'll not accept this since it's not a real solution.

Murat Şeker
  • 1,651
  • 1
  • 16
  • 29
0

If you provide the sequence and arguments that you use with fatfs function calls, then that can help me help you. I recently used fatfs for a datalogger application.