Adafruit_TinyUSB_Arduino icon indicating copy to clipboard operation
Adafruit_TinyUSB_Arduino copied to clipboard

USB MSC on Not Attaching Feather ESP32-S3 Reverse TFT

Open brentru opened this issue 1 year ago • 9 comments

Operating System

MacOS

Arduino IDE version

1.8.19

Board

Adafruit Feather ESP32-S3 Reverse TFT

ArduinoCore version

latest ESP32 BSP

TinyUSB Library version

latest

Sketch as ATTACHED TXT

example - msc_external_flash

Compiled Log as ATTACHED TXT

compile.txt

What happened ?

@hathach Hi - a user reported that their board (Adafruit Feather ESP32-S3 w/PSRAM) running WipperSnapper Arduino failed to attach USB. I'm able to reproduce this with a Feather ESP32-S3 Reverse TFT and the msc_external_flash.ino example from this library.

The device can initialize and read the flash contents but it never mounts/shows up in macOS Finder:

Adafruit TinyUSB Mass Storage External Flash example
JEDEC ID: 0x204016
Flash size: 960 KB
Opening root
Flash contents:
         0 .fseventsd/
         0 .metadata_never_index
         0 .Trashes
       262 wipper_boot_out.txt
       237 secrets.json
       237 ignore.json

For reference, the code section which initializes USB-MSC within WipperSnapper is here: https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/blob/main/src/provisioning/tinyusb/Wippersnapper_FS.cpp#L194

Related issue - https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/issues/591

How to reproduce ?

Upload the msc_external_flash example to an Adafruit Feather ESP32-S3 Rev. TFT.

Debug Log

idf-log.txt

Screenshots

n/a

brentru avatar Jul 01 '24 19:07 brentru

@hathach Hi - could you take a look at this issue?

brentru avatar Jul 09 '24 14:07 brentru

@brentru I have tested with feather s3 tft with board selection is reservetft (sinnce I don't have reserve version). It works just fine with my Linux machine, msc mounted created new file is OK. I notice that I have to run https://github.com/adafruit/Adafruit_SPIFlash/blob/master/examples/SdFat_format/SdFat_format.ino first since my board does not pre-formatted.

I am not sure what is missing here, @brentru can you

  • run sudo dmesg -w when reset board to run application, as well as lsusb then lsusb -v -d 239a: here, maybe macos host is picky.
  • try with my compiled uf2 to test with msc_external_flash.ino.zip
  • attached your msc_external_flash.ino.bin here, I will try to test your comipled binary to see if that works on my pc.

hathach avatar Jul 11 '24 05:07 hathach

@hathach Sorry for the delay, was wrapping WipperSnapper for Python. Here are my test notes..

notice that I have to run https://github.com/adafruit/Adafruit_SPIFlash/blob/master/examples/SdFat_format/SdFat_format.ino first since my board does not pre-formatted.

I tried this, and came to the same error.

run sudo dmesg -w when reset board to run application

Output: https://gist.github.com/brentru/b46eccdbcd358e6321ef9fddd5c956a7

lsusb then lsusb -v -d 239a:

Output: https://gist.github.com/brentru/33d27ea032493c45982d8a9969928acd

try with my compiled uf2 to test with msc_external_flash.ino.zip

This works as-expected.

attached your msc_external_flash.ino.bin here, I will try to test your comipled binary to see if that works on my pc.

Attached! msc_external_flash.ino.bin.zip

brentru avatar Jul 22 '24 16:07 brentru

@hathach Noting that I'm also seeing this issue on a QT Py ESP32-S2 with firmware compiled by PlatformIO IDE

brentru avatar Jul 23 '24 17:07 brentru

@hathach Getting the same issue on an ESP32-S2 QT PY, may be a macOS thing?

brentru avatar Aug 09 '24 19:08 brentru

@brentru sorry for huge delay, I tested again with latest of everything. And indeed, there is an issue enumerating with macos (tested on my x86 macos 12.7.6). As far as I could remember, arduino-esp32 core will always start with usb pin assigned to jtag usb, but then switch to otg usb if needed. For Linux/Windows, it will renumerate after a short bus reset signal, however for macos, it looks like the reset interval is too short ~ 20us, which is indeed not long enough as reset accordingly to USB spec. I am sure it previoulsy work with macos, maybe core change something in v3. Give me a bit of time, I am working on a PR (either to our lib or esp32 core) for this.

PS: meanwhile, can you verify that when unplugging the very same board to other non-macos machine, it could show up, maybe trying an android ?

image

hathach avatar Aug 27 '24 13:08 hathach

PS: meanwhile, can you verify that when unplugging the very same board to other non-macos machine, it could show up, maybe trying an android ?

Same board works OK on Windows 11

brentru avatar Aug 27 '24 14:08 brentru

PS: meanwhile, can you verify that when unplugging the very same board to other non-macos machine, it could show up, maybe trying an android ?

Same board works OK on Windows 11

Thanks for testing, I think we found the root cause, will work on the fix real soon.

hathach avatar Aug 27 '24 14:08 hathach

@hathach Okay, keep me in the loop as I am still seeing reports of this from people running WipperSnapper.

brentru avatar Aug 29 '24 12:08 brentru

This help to prevent S3 to be enumerated as USB JTAG while waitinf for 2nd reset (200-500 ms) https://github.com/adafruit/tinyuf2/pull/406 . Now it enumerate as arduino, however it is too fast with macOS that device is fully enumerated before setup()/msc.begin() is invoked --> mising interface. We will need to forcing re-enumeration, I am working on that with another PR.

hathach avatar Aug 30 '24 16:08 hathach

Okay, thanks for the update!

brentru avatar Sep 03 '24 14:09 brentru

@brentru this should be fixed by #454 which update tinyusb to be able to force re-enumeration with esp32s3. I will make an PR to arduino-esp32 to bump up tinyuf2 to prevent jtag enumeration, but it is optional fix :). Please try again to see if that works for you. In WipperSnapper library, you may also need to force enumeration as well since S3 is very fast, by the time we call usb_msc.begin(), the enumeration is already complete (without msc driver)

hathach avatar Sep 05 '24 10:09 hathach

@brentru this should be fixed by https://github.com/adafruit/Adafruit_TinyUSB_Arduino/pull/454 which update tinyusb to be able to force re-enumeration with esp32s3. I will make an PR to arduino-esp32 to bump up tinyuf2 to prevent jtag enumeration, but it is optional fix :)

I'll try with the TinyUSB update only, first, then the arduino-esp32 fix

brentru avatar Sep 05 '24 14:09 brentru