STM32F7+fatfs+sdcard: write in multiples of 1023 gives disk error (1024 is ok)
Hi,
I just ran into a strange problem that when doing multiple writes to an open file fails if it happens in chunks of 1023, but it is fine in chunks of the more common 1024.
Can someone confirm this (maybe give an explanation :), as far as I know there is not suppose to be such limitation of f_write ).
I am working on an STM32F7 with fatfs and an SD card configured for 1b (not 4b).
Example code:
FATFS m_SDFatFS;
FRESULT l_fatfsResult;
l_fatfsResult = f_mount(&m_SDFatFS, "", 1);
// Fatfs write test
{
FIL l_fil; /* File object */
FRESULT l_fatfsResult; /* FatFs return code */
uint8_t l_aBuf[1023] = {0}; // make sure your stack is big enough
UINT l_sizeWritten;
l_fatfsResult = f_open( &l_fil, "mytest.jpg", FA_CREATE_ALWAYS | FA_READ | FA_WRITE );
if( l_fatfsResult != FR_OK )
{
printf( "Error creating file: %d", l_fatfsResult );
}
l_fatfsResult = f_write( &l_fil, l_aBuf, sizeof(l_aBuf), &l_sizeWritten );
if( l_fatfsResult != FR_OK )
{
printf( "Error writing file: %d", l_fatfsResult );
}
else
{
printf( "Bytes written: %d", l_sizeWritten );
}
l_fatfsResult = f_write( &l_fil, l_aBuf, sizeof(l_aBuf), &l_sizeWritten );
if( l_fatfsResult != FR_OK )
{
printf( "Error writing file: %d", l_fatfsResult );
}
else
{
printf( "Bytes written: %d", l_sizeWritten );
}
l_fatfsResult = f_close( &l_fil );
if( l_fatfsResult != FR_OK )
{
printf( "Error closing file: %d", l_fatfsResult );
}
}If I change the buffer size to 1024 then everything works, if not then the second write fails (the first one is OK).
( I have not yet spend time looking deeper into this since at this point I am not yet sure if I will continue with fatfs/sdcard )
Regards
Bram
