USBD app could be freeze when disconnecting the cable

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
User11179
Level 1
Level 1
First like received
Hi,

USBD app 4.0.14 on XMC4xxx could be freeze in a infinite loop.

The problem is in the file
Dave/Model/APPS/USBD/v4_0_14/Template/usb/core/xmc4000/usbd_endpoint_stream_xmc4000.c:
in function
Endpoint_Write_Stream_x():
...
93: while (Length)
94: {
95: if (ep->InInUse)
96: {
97: continue;
98: }
...

When trasmits a packet could happen the controller is busy because reading, so the driver wait
until rx finished.
Problem occurs when the driver is in this state and the user unplug the cable from the board.
InInUse flag is blocked to 1 and USBD is freeze in a infinite loop in this while().

I fix the problem adding a control that checks if USB_DeviceState is Unattached.
This stops the transfer and return an ENDPOINT_RWSTREAM_DeviceDisconnected error.

while (Length)
{
if (USB_DeviceState == (uint8_t)DEVICE_STATE_Unattached)
{
return ENDPOINT_RWSTREAM_DeviceDisconnected;
}
if (ep->InInUse)
{
continue;
}

In attachment the patch....

Is this fix okay to be merged to the next USBD app version?

Regards,
Matteo,
Sirius Electronic Systems
0 Likes
0 Replies