AnsweredAssumed Answered

stm32f4Discovery Fat_Fs problem

Question asked by khramenkov.sergey on May 5, 2016
Latest reply on May 5, 2016 by khramenkov.sergey
Could anyone help me with the fat fs and f_unlink function ?


I have created a project in STM32CubeMX (version 4.12.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*)"STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
            //f_unlink ((TCHAR const*)"STM32.TXT");
            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 STM32.TXT 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*)"STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
        //  f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
        //  f_close(&MyFile);
            TRes = f_unlink ((TCHAR const*)"STM32.TXT");
            USART3->DR = TRes;
            FATFS_UnLinkDriver(USBDISKPath);
        Appli_state=APPLICATION_IDLE;
        }



Thanks for help !

Attachments

Outcomes