DieVom
DieVom

Reputation: 31

Are there any limitations on the number of bytes for writing in Chan's FAT FILE SYSTEM MODULE?

I'm using the ARM Cortex-M7 (ATMEL processor) whit Chan's FAT File System Module and I have a problem when writing a file with a non-multiply byte amount of SECTOR_SIZE_DEFAULT (512 bytes).

After a loop where I write a file using the f_write() function with different lengths of bytes (not multiple SECTOR_SIZE_DEFAULT), some characters appear wrong.

Here's the main part where the writing happens:

            f_open(&FileObject, filename_aux, FA_CREATE_ALWAYS | FA_WRITE);
            do
            {
                len = getAviableData(buf);

                f_write(&FileObject, , buf, len, (UINT*)&ByteWritten);

                total += len;

            }while(total < MAX_LEN)
            f_close(&FileObject);

When I write it to another memory without File System, I do not have any problem.

Thanks.

Upvotes: 2

Views: 597

Answers (1)

DieVom
DieVom

Reputation: 31

Here is a solution:

f_open(&FileObject, filename_aux, FA_CREATE_ALWAYS | FA_WRITE);
do
{
        /* Cache Maintenance */
        SCB_CleanDCache_by_Addr((uint32_t *)buf, BUF_MAX_SIZE);

        len = getAviableData(buf);

        f_write(&FileObject, buf, len, (UINT*)&ByteWritten);

        /* Data Memory Barrier */
        __DMB();

        total += ByteWritten;

}while(total < MAX_LEN)
f_close(&FileObject);

Note that I added a DCache Maintenance and a Data Memory Barrier.

The file is now written correctly without errors.

Thanks.

Upvotes: 1

Related Questions