FATFS Unlink driver
Hello,
I have problem when I use FATFS with my STM32F2.
My code come from example STM32-Tools\STM32_FW_libraries\HAL_CUBEMX_libs\STM32Cube_FW_F2_V1.6.0\Projects\STM32F207ZG-Nucleo\Applications\FatFs\FatFs_USBDisk\
It's works very well but only one time (with this example and in my code)
Normally
these functions should allow a reset of the FAT ?
- FATFS_UnLinkDriver(USBDISKPath);
- f_mount(NULL, (TCHAR const*)'', 0);
When I plug again my USB key (after the first good test) , I have problem with function
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
res return FR_NO_FILESYSTEM
it seems that the unlink function doesn't work correctly
if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
{ USBH_Init(&hUSB_Host, USBH_UserProcess, 0); USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS); USBH_Start(&hUSB_Host); while (1) { USBH_Process(&hUSB_Host); switch(Appli_state) { case APPLICATION_START: MSC_Application(); Appli_state = APPLICATION_IDLE; break; case APPLICATION_IDLE: default: break; } } } static void MSC_Application(void){ FRESULT res; /* FatFs function common result code */ uint32_t byteswritten, bytesread; /* File write/read counts */ uint8_t wtext[] = 'This is STM32 working with FatFs'; /* File write buffer */ uint8_t rtext[100]; /* File read buffer */ /* Register the file system object to the FatFs module */ if(f_mount(&USBDISKFatFs, (TCHAR const*)USBDISKPath, 0) != FR_OK) { /* FatFs Initialization Error */ Error_Handler(); } else { /* Create and Open a new text file object with write access */ if(f_open(&MyFile, 'STMTXT', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'STMTXT' file Open for write Error */ Error_Handler(); } else { /* Write data to the text file */ res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten); .............. /* Unlink the USB disk I/O driver */ FATFS_UnLinkDriver(USBDISKPath);}static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id){ switch(id) { case HOST_USER_SELECT_CONFIGURATION: break; case HOST_USER_DISCONNECTION: Appli_state = APPLICATION_IDLE; BSP_LED_Off(LED1); BSP_LED_Off(LED3); f_mount(NULL, (TCHAR const*)'', 0); break; case HOST_USER_CLASS_ACTIVE: Appli_state = APPLICATION_START; break; default: break; }}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�? FATFS USBDISKFatFs; /* File system object for USB disk logical drive */FIL MyFile; /* File object */char USBDISKPath[4]; /* USB Host logical drive path */USBH_HandleTypeDef hUSB_Host; /* USB Host handle */typedef enum { APPLICATION_IDLE = 0, APPLICATION_START, APPLICATION_RUNNING,}MSC_ApplicationTypeDef;MSC_ApplicationTypeDef Appli_state = APPLICATION_IDLE;�?�?�?�?�?�?�?�?�?�?�?�?I would like to avoid a reset if possible,
Thanks,
Nico
