cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4Discovery Fat_Fs problem

Khramenkov.Sergey
Associate
Posted on May 05, 2016 at 13:21

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 !
2 REPLIES 2
slimen
Senior
Posted on May 05, 2016 at 17:03

Hi,

This user manual “

http://www2.st.com/content/ccc/resource/technical/document/user_manual/61/79/2b/96/c8/b4/48/19/DM00105259.pdf/files/DM00105259.pdf/jcr:content/translations/en.DM00105259.pdf

â€� 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_USBDisk

Regards

Khramenkov.Sergey
Associate
Posted on May 05, 2016 at 17:21

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.