cancel
Showing results for 
Search instead for 
Did you mean: 

USB host on CubeMX: error after reconnecting flash drive

ASham.3
Associate

Hello comrades.

I am using CubeMX to implement USB MSC host and FatFs on STM32F767. My task is to periodically write files to various flash drives. When I first insert a USB drive into my device, everything goes right: in the APPLICATION_READY state, I mount the file system (FAT32) and successfully write data to the file. After finishing writing the file, I close it (f_close), unmount the file system (f_mount (NULL, "", 1)) and disconnect the flash drive.

When I reconnect the flash drive, I repeat these steps, but when I try to write data to the file again, the program ends up in an infinite loop inside the USBH_MSC_Write() function:

while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
  {
    if(((phost->Timer - timeout) >  (10000 * length)) || (phost->device.is_connected == 0))
    {
      MSC_Handle->state = MSC_IDLE;
      return USBH_FAIL;
    }
  }

That is, always USB_BUSY. The file is created but remains empty.

The problem is not always there: sometimes rewriting is successful. This is independent of the specific flash drive. The problem can happen if I just plug and unplug the flash drive, and then try to write the file. So I don't see any logic.

Help me please. And sorry my Google-English.

1 REPLY 1

Hello @ASham.3​,

Could you please provide us with the version of the firmware package and share your project for further check?

Thanks in advance.

BeST Regards,

Walid