Reputation: 31
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
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