hathach / tinyusb

An open source cross-platform USB stack for embedded system
https://www.tinyusb.org
MIT License
4.96k stars 1.04k forks source link

tud_ready returning true when not connected to mass storage host #1048

Open jcummings2 opened 3 years ago

jcummings2 commented 3 years ago

Operating System

Windows 10 for host

Board

Adafruit Feather M0 with added flash and battery including switch

Firmware

This firmware is based on the msc_external_flash sample. It was run with the Adafruit TinyUSB library version 1.4.0.

msc_external_flash_bug.ino

See also alternate msc_sdfat_bug.ino firmware below for use on an Adafruit Feather M0 Adalogger.

What happened ?

As mentioned in discussion 597 The tud_ready() function sometimes incorrectly returns true if the board was first connected to a computer, disconnected then connected to a charge-only source.

How to reproduce ?

  1. Upload the sketch above to the board
  2. Power off or disconnect the battery
  3. Connect to a computer
  4. Turn on or connect battery
  5. Wait about 10 seconds
  6. Disconnect from the computer for about 10 seconds
  7. Connect to a charge-only source for about 10 seconds
  8. Connect to a computer for about 10 seconds
  9. Optionally cycle the battery
  10. Disconnect/reconnect to computer to examine ready.txt log file

To test a different sequence, delete the ready.txt file. I have attached several log files with file names denoting the connection order with devices separated by an underscore. Each connection (or lack thereof in the case of none) was for about 10 seconds. The names correspond to:

Notice that I ran the computer_none_brick_computer scenario 3 times (file names ending in 0, 1 and 2). It is the only case that seemed to behave correctly. However, the brick_none_computer_brick case did not yield the desired results (I ran that one twice as well just to confirm).

ready_chargerSamsung.txt ready_chargerSamsung_none_computer_chargerSamsung.txt ready_computer.txt ready_computer_none_brick_computer_0.txt ready_computer_none_brick_computer_1.txt ready_computer_none_brick_computer_2.txt ready_computer_none_chargerAmazon_computer.txt ready_computer_none_chargerSamsung_computer.txt ready_brick.txt ready_brick_none_computer_brick_0.txt ready_brick_none_computer_brick_1.txt ready_chargerAmazon.txt ready_chargerAmazon_none_computer_chargerAmazon.txt

Debug Log

Didn't capture but can re-run the pertinent scenario(s) if needed.

Screenshots

N/A

hathach commented 3 years ago

thank you for detail issue report, please post your sketch as attached file for readability. Also I cannot reproduce your issue, since I don't have the MX25L25673G device. Please try to reproduce it with one of the Adafruit board without any hardware modification.

hathach commented 3 years ago

msc_external_flash_bug.ino

I have updated 1st post to make it easier to follow. but I still cannot reproduce your issue due to your sketch using additional flash device that I don't have. Can you try to reproduce this on one of adafruit M0 board that has on-board flash and update the sketch accordingly.

jcummings2 commented 3 years ago

Here is a new msc_sdfat_bug.ino sketch and a new set of results run against an Adafruit Feather M0 Adalogger with a microSD card inserted. The sketch is based on the msc_sdfat.info sample.

Results follow the same naming convention as above. The results are almost all the same. Interestingly, I could only get the computer_none_brick_computer scenario to behave correctly 1 out of the 3 times I ran it. With the external flash it appeared to behave correctly every time.

ready_chargerAmazon_none_computer_chargerAmazon.txt ready_chargerSamsung.txt ready_chargerSamsung_none_computer_chargerSamsung.txt ready_computer.txt ready_computer_none_brick_computer_0.txt ready_computer_none_brick_computer_1.txt ready_computer_none_brick_computer_2.txt ready_computer_none_chargerAmazon_computer.txt ready_computer_none_chargerSamsung_computer.txt ready_brick.txt ready_brick_computer_brick_0.txt ready_brick_none_computer_brick.txt ready_chargerAmazon.txt

hathach commented 3 years ago

most of other adafruit has external flash on board, is your Feather M0 an non-express version without spi flash on it ? Do you have any other M0, M4 board to test with.

jcummings2 commented 3 years ago

most of other adafruit has external flash on board, is your Feather M0 an non-express version without spi flash on it ? Do you have any other M0, M4 board to test with.

Correct, the Feather M0's I have are the non-express version that do not have external flash onboard and I don't have any M4 boards. I believe the first firmware above should work with minor modifications to point at the onboard external flash.