I'm customizing the bootloader project provided with SDK 1.0.0.7.
File read from micro SD is working fine, but writing is not possibile.
I get nasty file system corruption at every try. This is the code:
fresult = f_open( &FileObject, string_buffer, FA_CREATE_NEW | FA_WRITE );
f_sync( &FileObject );
i=0
while ( ... there is some data to write ... ) {
fresult = f_write(&FileObject, &data_to_write, 1, &byte_count);
f_sync( &FileObject );
i++;
}
This code fails when i=4096 whit fresult=FR_INT_ERR.
In particular, in ff.c this is the function call that cause the error:
clst = create_chain(fp->fs, 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(fp->fs, FR_INT_ERR);
if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
fp->clust = clst; /* Update current cluster */
Create_chain function returns value 1 because of this line:
if (clst == 0) { /* Create a new chain */
scl = fs->last_clust; /* Get suggested start point */
if (!scl || scl >= fs->n_fatent) scl = 1;
}
else { /* Stretch the current chain */
cs = get_fat(fs, clst); /* Check the cluster status */
if (cs < 2) return 1; /* It is an invalid cluster */
if (cs < fs->n_fatent) return cs; /* It is already followed by next cluster */
scl = clst;
}
The cs value is zero, and comes from this line of get_fat function:
case FS_FAT32 :
if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)))) break;
p = &fs->win[clst * 4 % SS(fs)];
return LD_DWORD(p) & 0x0FFFFFFF;
I've tried searching google for advice, with no result.
Maybe I'm the first one here that is using FatFS for writing data to a memory device. Someone at TI can help?
When data is written to memory device, is there any interrupt or DMA to be configured? I can't understand it from examples provided with SDK.