I have some challenges in USB connection /disconnection through firmware.
For stopping USB MSC:
For Restarting USB MSC:
g_msc.speed = USB_SPEED_FULL;
g_msc.attach = 0;
g_msc.mscHandle = (class_handle_t)NULL;
g_msc.deviceHandle = NULL;
USB_DeviceClassInit(CONTROLLER_ID, &msc_config_list, &g_msc.deviceHandle);
I presently implemented the above code and the code work perfectly fine when there is no transfers happening. I created a scenario by copying a huge file to the K64F USB drive. When the file is being copied, I tried to disable the USB functionality. USB functionality disconnected successfully. But after that, program execution and stuck in an infinite loop of
line: while (ehciState->registerBase->EPFLUSH & primeBit).
I tried a little bit more also by disabling/enabling clock, SD card and interrupt in a proper sequence. But still the same result. Is there a way, I can connect and disconnect the USB functionality like a normal USB Drive even if there are any transfers happening?
Surprisingly, I tried disconnecting and connecting the USB cable (used for MSC) again while the transfer is made. There were no issues at all. It worked the way that everyone would expect.