AnsweredAssumed Answered

MFS Invalid Sector Errors

Question asked by jschepler on Apr 6, 2018
Latest reply on Apr 12, 2018 by jschepler

I am using KSDK 1.3.0 with MQX and MFS.  We are using a 16 GB SD Card.

I am evaluating the reliability of the MFS file writes by using 1 task that writes to files.  I was running into issues with timeouts originally (see here).  I have a tick time of 1 ms for my system so I set the timeouts to the following until I hear back from what they should be set to in my other post:


#define ESDHC_CMD_TICK_TIMEOUT 40 // 40ms 
#define ESDHC_CMD12_TICK_TIMEOUT 1000 // 1 Sec
#define ESDHC_TRANSFER_TIMEOUT_MS 750 // 750ms

I am still using a similiar test procedure as before:

1. Create a new text file.

2. Write 1 KB of data into the file.

3. After 1024 Writes (1 MB), close the file.

4. Open the same file, seek to the end.

5. Perform steps 2 - 4 until I write 1,000 MB to the file.

6. After 1,000 MB has been written, close the current file and create a new one. Repeat steps 2-4 until 8 files have been created. (We are using a 16 GB card)


The farthest I have gotten is 5 files written before a failure during the writing of the 6th.  The errors I am receiving are the following:




These appear to happen at random.  Again, all I am doing in my program is writing to files.  

The latest error happened in the function "MFS_get_cluster_from_fat".  I set a breakpoint here so I am able to see the context of variables:


drive_ptr information and fat_entry:


So, fat_entry is a value of 0x0141_4141, but the LAST_CLUSTER is 0x001D_1C5B, so we are trying to write into a cluster that is greater than the max, which is why it fails.


However, I am not sure how fat_entry gets its value. 


How did it become greater than the LAST_CLUSTER? 


I noticed there are a some places where "location" is a byte value, and then other places where "location" is converted into a sector number.  Could it be related to some 32-bit overflow issue? 


Although I don't plan on creating such large files in my application, I am still concerned with the errors that are happening because I do not know the root cause.