2021-05-10 02:37 AM
I am trying to implement simple appication to scan existing files in USB stick in root directory. I just use ST sample as reference and following is the user call back code. The error is line 27
It manage to reach :
Appli_state = APPLICATION_START; and then successful mount f_mount().
Then it hit Appli_state = APPLICATION_READY; and then go here:
fr = f_findfirst(&dj, &fno, "/", "*.txt");
the returned fr so far always give FR_DISK_ERR. But I have verified by USB stick is ok when I use my PC to detect, write and read files.
I'd appreciate if someone can give some pointeres.
I am using STM32F769 Discovery Board and utilizing USB_OTG_HS peripheral as USB Host class MSC.
FRESULT fr; /* Return value */
DIR dj; /* Directory object */
FILINFO fno; /* File information */
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
{
/* USER CODE BEGIN CALL_BACK_1 */
switch(id)
{
case HOST_USER_SELECT_CONFIGURATION:
break;
case HOST_USER_DISCONNECTION:
Appli_state = APPLICATION_DISCONNECT;
printf("app disconnect\r\n");
if(FATFS_UnLinkDriver(USBKey_Path) != 0) {
printf("ERROR : Cannot unlink FatFS driver! \n");
}
if(f_mount(NULL, "", 0) != FR_OK)
{
printf("ERROR : Cannot DeInitialize FatFs! \n");
}
break;
case HOST_USER_CLASS_ACTIVE:
Appli_state = APPLICATION_READY;
fr = f_findfirst(&dj, &fno, "/", "*.txt"); // why always returns FR_DISK_ERR ?
while (fr == FR_OK && fno.fname[0]) { /* Repeat while an item is found */
printf("%s\r\n", fno.fname); /* Print the object name */
fr = f_findnext(&dj, &fno); /* Search for next item */
}
f_closedir(&dj);
break;
case HOST_USER_CONNECTION:
Appli_state = APPLICATION_START;
printf("app start\r\n");
if(f_mount(&USBH_FatFs, "", 0) != FR_OK) {
printf("ERROR : Cannot Initialize FatFs! \n");
}
else {
printf("Mount success\r\n");
}
break;
default:
break;
}
/* USER CODE END CALL_BACK_1 */
}
2021-05-10 07:16 PM
In fact it seems, I cannot do any simple write/read too e.g. f_write() and f_read()