tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Plugging unplugging usb device

Open abakosh opened this issue 2 years ago • 5 comments

Operating System

Others

Board

Renesas RA

Firmware

custom firmware, Host, MSC , no OS , one device.

What happened ?

The system is becoming unresponsive or freezes the application (stuck in tuh_task). I am assuming the immature removing of the USB stick is causing this, however, I will say maybe there is a better way

How to reproduce ?

You must run into a situation where you write or read to the USB stick and then unplug it during the operation. Also during the enumeration of fast plugging and unplugging of the USB stick. The behavior changes significantly as you might get stuck in the tuh_task function, the application doesn't see the plugging or unplugging of the device, enumeration failed, and stuck in the NRDY state.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

I don't have meaningful log files, but it is easy to reproduce. you need to do one of the following: 1- fast plug and unplug 2- unplug during the enumeration process 3- unplug during USB is busy. 4- Some USB sticks might introduce issues once unplugging, even in an idle state. This point might be irrelevant for now.

Assumption: The handling of the detachment of the device can fix this issue, I would like to hear the opinions about what can be done there.

Thank you for your support

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existing issues, dicussion and documentation.

abakosh avatar Jul 24 '23 14:07 abakosh

The test was done with tinyusb at commit 8fa0b74d8016554d23f84981f78c656f215d76e8

abakosh avatar Jul 24 '23 14:07 abakosh

I am not sure , but I guess the lead is in this part

image

abakosh avatar Jul 24 '23 14:07 abakosh

yes, possibly, I did anticipate such as race between unplugged and application transfer. Never have enough time to test out al scenario though.

hathach avatar Jul 24 '23 14:07 hathach

PS: can you specify which RA mcu and devkit you are testing with. Always better to be specific.

hathach avatar Jul 24 '23 16:07 hathach

Custom RA4M2 with IAR.

abakosh avatar Jul 24 '23 17:07 abakosh