2016-05-05 04:21 AM
Could anyone help me with the fat fs and f_unlink function ?
I have created a project in STM32CubeMX (version 4.0), then generated C code and MDK-ARM project. The project is in attachment. I modified Main function as:while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();
if (Appli_state== APPLICATION_READY) {
f_mount(&USBDISKFatFs, (TCHAR const*)USBDISKPath, 0);
f_open(&MyFile, (TCHAR const*)''STMTXT'', FA_CREATE_ALWAYS | FA_WRITE);
//f_unlink ((TCHAR const*)''STMTXT'');
f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
f_close(&MyFile);
FATFS_UnLinkDriver(USBDISKPath);
Appli_state=APPLICATION_IDLE;
}
/* USER CODE BEGIN 3 */
}
It creates file STMTXT on my USB disck without any problem, but if i place f_unlink enstead of f_open, it returns '' A hard error occurred in the low level disk I/O layer (01)''
while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();
if (Appli_state== APPLICATION_READY) {
f_mount(&USBDISKFatFs, (TCHAR const*)USBDISKPath, 0);
// f_open(&MyFile, (TCHAR const*)''STMTXT'', FA_CREATE_ALWAYS | FA_WRITE);
// f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
// f_close(&MyFile);
TRes = f_unlink ((TCHAR const*)''STMTXT'');
USART3->DR = TRes;
FATFS_UnLinkDriver(USBDISKPath);
Appli_state=APPLICATION_IDLE;
}
Thanks for help !
2016-05-05 08:03 AM
Hi,
This user manual “� provides a description of how to use the STM32Cube firmware components with a generic FAT File System (FatFs) and help you to have more idea about functions used.I suggest you have a look to this example which can help you to develop an application using most of the functions offered by FatFs: STM32Cube_FW_F4_V1.11.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDiskRegards2016-05-05 08:21 AM
Thank you for your answer.
I have read ''UM1721 User manual'' and tried example project from ''STM32Cube_FW_F4_V1.11.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDisk''It works good (it excludes hardware problems), but nowhere used f_unlink.Debugging by st-link leads to ''USBH_MSC_Read'' function in ''usbh_msc.c'', which returns ''USBH_FAIL'', because ''MSC_Handle->unit[lun].state != MSC_IDLE''It looks like there are some problem in fat_fs porting, because all another functions work perfectly.