2024-07-16 04:03 PM
I'm simply trying to do:
but nothing is created despite the return message. Could it be my SD card? I'm able to read from it in 4B mode.
Any suggestions would be gratefully received.
Solved! Go to Solution.
2024-07-18 06:56 AM
It turns out that it was as simple as enabling hardware flow control in the MX. I had been unable to get it to mount without the clock divider being 4, but I imagined that may have been creating timing issues as I see the recommended value is 0. May this have caused underrun issues that hardware flow control can prevent?
Thanks for all your willingness to help.
2024-07-16 04:11 PM
How do you determine that nothing is created?
2024-07-16 04:15 PM
f_stat actually says that the file is created but when I open the SD on my desktop, nothing is visible.
2024-07-17 02:18 AM - edited 2024-07-17 02:18 AM
some sort of "caching" issue?
Are you sure to close the file? I don't think FatFs (necessarily) writes immediately to the card without a close or flush?
2024-07-17 02:29 AM
Hello @WellLeithed ,
Could you kindly refer to the example provided in our reference firmware package, FatFs_uSD_Standalone, and examine the differences? Or could you please provide the model of the STM32 MCU you are utilizing so that I can attempt to reproduce on my side?
2024-07-17 09:11 AM
Hi, SH.
I'm using the L476RG.
I've just done:
While it have been able to read from a uSD, when I open, write and then try to close, open and write return ok but the close returns " fr_disk_err".
I see that FatFs_uSD_Standalone uses f_mkfs and I'm trying to work out if I need to apply this too.
2024-07-18 03:47 AM
Hello @WellLeithed ,
Could you kindly test this code snippet and confirm whether it functions correctly on your end?
/*##-1- Link the micro SD disk I/O driver ##################################*/
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
{
/*##-2- Register the file system object to the FatFs module ##############*/
if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
{
/* FatFs Initialization Error */
Error_Handler();
}
else
{
/*##-3- Create a FAT file system (format) on the logical drive #########*/
/* WARNING: Formatting the uSD card will delete all content on the device */
if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, buffer, sizeof(buffer)) != FR_OK)
{
/* FatFs Format Error */
Error_Handler();
}
else
{
/*##-4- Create and Open a new text file object with write access #####*/
if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
/* 'STM32.TXT' file Open for write Error */
Error_Handler();
}
else
{
/*##-5- Write data to the text file ################################*/
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Write or EOF Error */
Error_Handler();
}
else
{
/*##-6- Close the open text file #################################*/
f_close(&MyFile);
/*##-7- Open the text file object with read access ###############*/
if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK)
{
/* 'STM32.TXT' file Open for read Error */
Error_Handler();
}
else
{
/*##-8- Read data from the text file ###########################*/
res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
if((bytesread == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Read or EOF Error */
Error_Handler();
}
else
{
/*##-9- Close the open text file #############################*/
f_close(&MyFile);
/*##-10- Compare read data with the expected data ############*/
if((bytesread != byteswritten))
{
/* Read data is different from the expected data */
Error_Handler();
}
else
{
/* Success of the demo: no error occurrence */
}
}
}
}
}
}
}
}
BRs,
Sarra
2024-07-18 03:59 AM
No reason to use f_mkfs() unless the file system is trashed. Cards come properly formatted.
Instrument DISKIO to understand interaction, failure and success. Validate your read functionality first, then write. Ensure data written is subsequently read back properly.
2024-07-18 04:25 AM
See the posting tips for how to properly post source code:
2024-07-18 06:02 AM
I was able to use return successfully from FATFS_Link Driver by copying:
Disk_drvTypeDef disk = {{0},{0},{0},0};
within FATFS_LinkDriverEx. However, having returned successfully from this function, I'm no longer able to mount. I'm unable to debug beyond:
stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
in diskio.c with pdrv = 0