This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: Failed to write larger files onto SD card

Part Number: TM4C1294NCPDT

Hi Folks,

I did a small example in order to validate FatFS in my applicaiton. The environment is looks like:

  • FreeRTOS 7.x
  • FatFs
  • SD card with Fat32 file system, 512 byte allocation size
  • SD card accessed via SPI
  • both of them are coming from the TI provided TivaWare

Here is the example code, right after the main():

static uint32_t dummy[512];
static libs::Storage storage("test", FA_CREATE_ALWAYS | FA_WRITE);

for (uint32_t cycle = 0; cycle < 40000; ++cycle) {
	for (uint32_t index = 0; index < 512; ++index) {
		dummy[index] = index;
	}

	if (storage.write(reinterpret_cast<uint8_t*>(dummy), 2048) == 0) {
		break;
	}
}

storage.close();

The Storage class is a thin wrapper aroung the FatFS API, so you can suppose that the API call is directly in place.

My problem is that this example seems to work correctly, if the "dummy" is equal (even less) to the allocation size of the SD card, but in the case above, I got "FR_INT_ERR" from remove_chain() in ff.c:

while (clst < fs->n_fatent) {			/* Not a last link? */
	nxt = get_fat(fs, clst);			/* Get cluster status */
	if (nxt == 0) break;				/* Empty cluster? */
	if (nxt == 1) { res = FR_INT_ERR; break; }	/* Internal error? */
	if (nxt == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }	/* Disk error? */

Can anybody help me, what did I wrong?

Regards,

Norbert

  • Hi,
    Are you trying to overwrite what you wrote each time? In each cycle loop don't you want to advance the write pointer to the next 2kB block?
  • Hi,

    No. The inner loop only fill the container for dummy data, then I wanted to store into the SD card. The outer loop intend to create an 80 MB file.

    Regards,
    Norbert
  • Hi Nobert,

      Does your storage.write() take care of incrementing the write pointer by 2k at the end of each 2k write. I was thinking in the line of using f_lseek() to advance the pointer after each 2k write. 

  • Hi,

    As I wanted to point about, the this write method is only a wrapper, that calls directly the f_write() method of FatFS API. Do I call f_lseek() too after each f_write() call?

    Regards,
    Norbert
  • Hi,

      That is my understanding. See below description.

    f_lseek

    The f_lseek function moves the file read/write pointer of an open file object. It can also be used to expand the file size (cluster pre-allocation).

    Description

    File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The f_lseek function moves the file read/write pointer without any read/write operation to the file.

    See details here. 

  • Hi Charles,

    f_lseek is not necessary to move file pointer during write. It has been done automatically read / write operations.

    Nevertheless, it seems that the problem is solved. For the further, I try to summarize what I did.

    • I used "Simple" disk -> properties -> format tool on Windows to create partition on the SD card, which left behind some unallocated space. I used gparted for formatting the SD card
    • My FatFS configuration uses 512 B as _MAX_SS, so it seems to be right choice for file system too
    • LFN support has been turned off
    • Coda page support has been set to 1 (ASCII code page)

    My project involved much more tasks so I don't have time to discover and validate, which were the minimal steps to fix my issue, but I hope, it can help somebody in the future.

    Regards,

    Norbert

  • Glad your problem is solved and the tips you provided.