AnsweredAssumed Answered

K64F Enabling and Disabling USB while File Transfer is happening

Question asked by Mahendran Manoharan on Aug 30, 2019
Latest reply on Sep 22, 2019 by Sabina Bruce

Hi,

 

I have some challenges in USB connection /disconnection through firmware.

 

For stopping USB MSC:

USB_DeviceStop(g_msc.deviceHandle);
USB_DeviceClassDeinit(CONTROLLER_ID);

 

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);
USB_DeviceRun(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 

file:          usb_device_ehci.c

function:      USB_DeviceEhciCancel() 

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.

 

best regards,

Mahendran

Outcomes