Skip to content

ESP32s3 hangs on stdout if USB cable connected but CDC not attached #18000

Description

@jonathanhogg

Port, board and/or hardware

ESP32 / UM_TINYS3

MicroPython version

HEAD as of 8c47e44 with the suggested USB fix from #17560 applied – otherwise USB is not reliable for me as I'm using macOS. Same behaviour with official release version of 1.26 though.

Reproduction

  1. Install code below as boot.py
from time import sleep_ms
from machine import Pin, bitstream


led_power = Pin(17, Pin.OUT, value=1)
led = Pin(18, Pin.OUT)

while True:
    bitstream(led, 0, (400, 850, 800, 450), bytes([0, 127, 0]))
    sleep_ms(500)
    bitstream(led, 0, (400, 850, 800, 450), bytes([0, 0, 0]))
    sleep_ms(500)
    print("Hello world!")

Expected behaviour

Code should run, blinking the LED as soon as power is applied – either from USB or externally – and continue to run if the USB cable is connected or disconnected, whether or not a serial console is attached.

Observed behaviour

  • Power up from USB: LED blinks for about 20 seconds and then controller locks solid and mpremote cannot attach to it
  • Power up from USB and attach mpremote immediately: LED blinks and Hello world! appears repeatedly on the console ad infinitum
  • Power up from USB, attach mpremote watch for a bit and then detach serial console leaving USB cable connected: LED blinks for a few seconds after detaching terminal and then controller locks solid
  • Power up from external power: LED blinks ad infinitum
  • Power up from external power, wait a bit and then connect a USB cable without attaching to the serial: locks solid a few seconds after connecting the cable

It looks like connecting the USB is starting some kind of serial buffering that is exhausted after 255 bytes and hangs the controller.

Additional Information

This used to work in 1.24.

Code of Conduct

Yes, I agree

Activity

  1. dpgeorge commented on Aug 28, 2025

    @dpgeorge
    Member

    Can you please try #17960? It has a newer TinyUSB and a fix to use tx_overwritabe_if_not_connected.

  2. jonathanhogg commented on Aug 28, 2025

    @jonathanhogg
    ContributorAuthor

    Ah, yes, can confirm that @projectgus's #17960 fixes the issue(s) for me.

    @dpgeorge: what are the chances of a 1.26.1 with this in it? Sadly, 1.26 is unusable for me at the moment and the ESP32 PCNT support meant I was so close to being able to run my code on stock MicroPython… 😉

  3. dpgeorge commented on Aug 28, 2025

    @dpgeorge
    Member

    Ah, yes, can confirm that @projectgus's #17960 fixes the issue(s) for me.

    OK, that's great, thanks for confirming.

    what are the chances of a 1.26.1 with this in it?

    A high chance! We probably also need #17999 (fixes a similar issue with Windows).

  4. Rai-Sp commented on Aug 29, 2025

    @Rai-Sp

    A simple workaround:

    Change line 98 in micropython/shared/tinyusb/mp_usbd_cdc.c from
    if (!tusb_inited()) {
    to
    if (!tusb_inited() || !tud_cdc_connected()) {

    This may not be a good solution, but it WORKS.
    For me, it's not a problem, that everything printed is lost, while no terminal is connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions