Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing USB descriptors on ESP32S2 crashes #4746

Closed
Neradoc opened this issue May 11, 2021 · 9 comments · Fixed by #4754
Closed

changing USB descriptors on ESP32S2 crashes #4746

Neradoc opened this issue May 11, 2021 · 9 comments · Fixed by #4754
Assignees
Labels
bug crash espressif applies to multiple Espressif chips usb
Milestone

Comments

@Neradoc
Copy link

Neradoc commented May 11, 2021

Tested on the Feather S2. I expected that trying to use more endpoints than available results in reset to safe mode. Here are a few boot.py that cause issues. (Manual safe mode recovers).

import usb_cdc
usb_cdc.enable(console=True, data=True)
  • reset loop (status LED alternates purple and black)
import usb_hid
usb_hid.disable()
import usb_cdc
usb_cdc.enable(console=True, data=True)
  • code.py runs
  • device connected seen on USB (ioreg) but no drive, no serial

Those work as expected:

import usb_hid
usb_hid.disable()
import usb_cdc
usb_cdc.enable(console=True, data=False)
import usb_hid
usb_hid.disable()
import storage
storage.disable_usb_drive()
import usb_cdc
usb_cdc.enable(console=True, data=True)
@dhalbert dhalbert self-assigned this May 11, 2021
@dhalbert dhalbert added this to the 7.0.0 milestone May 11, 2021
@tannewt tannewt added bug crash espressif applies to multiple Espressif chips usb labels May 11, 2021
@Neradoc
Copy link
Author

Neradoc commented May 15, 2021

It's not fixed, I have both error cases above do a reset loop on latest on ESP32-S2.

@dhalbert
Copy link
Collaborator

dhalbert commented May 15, 2021

I tested on the Metro ESP32-S2 with your examples and did not get a reset loop, hmm. I will test again.

@Neradoc
Copy link
Author

Neradoc commented May 15, 2021

Oh it works (as in: drops to safe mode due to not enough endpoints) when I erase_flash and install with the Circuitpython bin, but crashes if I install the UF2 bootloader first and install with the UF2.

@dhalbert
Copy link
Collaborator

I only tested with the .bin. I just re-tested and it goes into safe mode with USB devices need more endpoints than are available. as I expected with a boot.py:

import usb_cdc
usb_cdc.enable(console=True, data=True)

If boot.py is empty and you use the UF2 version does it work?

Could you compare the initial prompt with the version number between the .bin. and the .uf2 version to make sure they are the same build? Thanks.

There isn't anything in my USB impl that should care whether it's UF2 or .bin.

@Neradoc
Copy link
Author

Neradoc commented May 15, 2021

I tried with the artifacts, with the the latest S3, I fixed my toolchain to be able to build locally, same result every time. I tried the bin from the same local build, goes to safe mode. Empty boot.py, no boot.py, or the boot.py listed above to work do work as expected.
TinyUF2 uses USB, could it leave it in a state where there's some endpoint cleanup needed ?

@dhalbert
Copy link
Collaborator

See #4766 for problem diagnosis.

@todbot
Copy link

todbot commented Jul 5, 2021

I'm still having this problem. On an ESP32S2 MagTag 2.9", I do the following:

esptool.py --port /dev/tty.usbmodem01 erase_flash
esptool.py --port /dev/tty.usbmodem01 write_flash 0x0 ~/adafruit-circuitpython-adafruit_magtag_2.9_grayscale-en_US-20210703-cece649.bin

and I get a fresh CP7 install. I then create the following boot.py:

# boot.py
import usb_midi
usb_midi.disable() 
print("disable MIDI")
import usb_hid
usb_hid.disable()
print("disable HID")

Reset the board and the above works. I see those print statements in boot_out.txt. However, if I change boot.py to this:

# boot.py
import usb_midi
usb_midi.disable() 
print("disable MIDI")
import usb_hid
usb_hid.disable()
print("disable HID")
import usb_cdc
usb_cdc.enable(console=True, data=True)
print("enable CDC console & data")

Upon reset, the board appears dead and no USB device appears in the USB devices list. Upon first reset, the D4 LED of the MagTag flashes yellow four times (and then maybe briefly blue?). The only recourse is to repeat the erase_flash and write_flash steps with esptool.py.

@Neradoc
Copy link
Author

Neradoc commented Jul 6, 2021

I was able to reproduce with the Magtag (7.0.0-alpha.3-495-gcece6492a built locally, without tinyuf2).

  • The Magtag does not appear on USB.
  • It is able to be recovered by pressing boot on the yellow blink on reset. (Manually go to safe mode).

The Feather S2 in the same conditions reboots into safe mode (with the second boot.py).

You are in safe mode because:
USB devices need more endpoints than are available.

@tannewt
Copy link
Member

tannewt commented Jul 8, 2021

@todbot please open a new issue. Closed issues are hard to track and I suspect this might be a different problem from the original. (My guess is that the safe mode restart isn't working.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash espressif applies to multiple Espressif chips usb
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants