cancel
Showing results for 
Search instead for 
Did you mean: 

f_write is giving FR_DISK_ERROR

yalamanda dosakayala
Associate II
Posted on February 08, 2018 at 16:44

Hi STM community,

I am working with STM32F779i board , using system workbench for stm IDE. in my project I am using freertos ,fatfs ,sdcard drivers and CAN drivers. Initially as per project requirement we need more RAM, so we have implemented SDRAM as RAM.

We have two tasks , one for fatfs and another for CAN . I am receiving a file from PC over CAN and writing it to a buffer(buffer size is sizeof file created with malloc) on to SDRAM, another task is waiting till we received whole file over CAN and then I am writing the buffer to file in the SDCARD .

I am able to write small files(10kB, 40KB) successfully,But for large files (more than > 50KB) the f_write is returning FR_DISK_ERR.

I dig into the f_write function and it is failing at below ABORT(fs, FR_DISK_ERR);

and the value of clst is 0xFFFFFFFF;

{

                        clst = create_chain(&fp->obj, fp->clust);    /* Follow or stretch cluster chain on the FAT */

                    }

                }

                if (clst == 0) break;        /* Could not allocate a new cluster (disk full) */

                if (clst == 1) ABORT(fs, FR_INT_ERR);

                if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);

}

Can anyone tell me why which case I will get this error ?

and   how to resolve this error ?

#stm32f7-eval
1 REPLY 1
Posted on February 08, 2018 at 17:09

If the media is corrupted you will need to run scandisk/chkdsk type utilities, or via windows properties, to resolve the errors.

If your DISKIO layer routines are failing, or causing corruption you need to understand what's happening there, and fix it.

You need to serialize access to SDIO/SDMMC and FsFat, ideally have all IO driving from one worker task so as to control/sequence the access to the resources.

One shouldn't need to hold megabytes of file data in memory, managing it in smaller pieces should be possible, but will require a paradigm change.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..