← index #16713Issue #18990
Related · high · value 2.027
QUERY · ISSUE

Serial com and external power supply

openby eleroyopened 2025-02-06updated 2025-02-23
bug

Port, board and/or hardware

rp2, raspberry pico

MicroPython version

MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico with RP2040

Reproduction

  1. Start a code with serial printing such as:
import time

while True:
    print(time.time())
    time.sleep(0.1)    
  1. Connect external power supply (+5V or 3V3)
  2. Disconnect usb
  3. Wait ~4 s
  4. Reconnect usb

Expected behaviour

When you reconnect USB, the board should be normally detected as CDC Serial device and printing.

Observed behaviour

When you reconnect USB the board is not detected anymore and it seems the program has been interrupted.

Additional Information

I suspect something like a buffer overflow on the serial output hardware is happening.

If the usb is reconnected quickly (in 1 second or so), the board is well detected.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

MicroPython USB-CDC Regression on RP2350 (Pico 2W)

closedby LofiFrenopened 2026-03-24updated 2026-03-25
bug

Port, board and/or hardware

RP2350 Pico 2W

MicroPython version

MicroPython versions v1.26.0 through v1.27.0 (and likely v1.28.0+) fail to enumerate USB-CDC on the RP2350 (Raspberry Pi Pico 2W). The device does not appear as a serial port on the host. The last working version is v1.25.0-preview (commit f187c77da).

Reproduction

  1. Build MicroPython v1.27.0 for BOARD=RPI_PICO2_W
  2. Flash the .uf2 to a Raspberry Pi Pico 2W
  3. Connect via USB -- no serial port appears (ls /dev/tty.usbmodem* on macOS returns nothing)
  4. Apply the two-line fix above, rebuild, reflash
  5. USB serial port appears and works normally

Expected behaviour

you should be able to connect usb to mac or windows (mac in this case)

Observed behaviour

Plug in usb and nothing happens

Additional Information

Root Cause

In the transition from v1.25.0 to v1.26.0, the --wrap=dcd_event_handler linker flag and its corresponding __wrap_dcd_event_handler() function were removed from ports/rp2/CMakeLists.txt and shared/tinyusb/mp_usbd.c.

The removal was intentional -- TinyUSB added a tud_event_hook_cb() callback (called from usbd.c:383) meant to replace the linker wrap. MicroPython v1.26.0+ implements this hook via MICROPY_WRAP_TUD_EVENT_HOOK_CB in shared/tinyusb/mp_usbd.c.

However, on the RP2350, the TinyUSB hook alone is not sufficient for USB device enumeration to succeed. The linker wrap is still needed. The RP2040 may not be affected (untested).

The Fix

Two changes restore USB functionality on RP2350 while keeping all v1.27.0 features (including BLE security):

1. ports/rp2/CMakeLists.txt -- Re-add linker wrap

 target_link_options(${MICROPY_TARGET} PRIVATE
     -Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
+    -Wl,--wrap=dcd_event_handler
     -Wl,--wrap=runtime_init_clocks
 )

2. shared/tinyusb/mp_usbd.c -- Re-add wrapper function

Add before the tud_event_hook_cb function:

extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr);

TU_ATTR_FAST_FUNC void __wrap_dcd_event_handler(dcd_event_t const *event, bool in_isr) {
    __real_dcd_event_handler(event, in_isr);
    mp_usbd_schedule_task();
    mp_hal_wake_main_task_from_isr();
}

Both the hook (tud_event_hook_cb) and the wrap (__wrap_dcd_event_handler) can coexist safely -- v1.25.0-preview had both. The wrap ensures the USB task is scheduled from the ISR context, which appears to be required on RP2350 for enumeration to complete.

Affected Versions

Version USB on RP2350 BLE Security
v1.25.0-preview (f187c77da) Works No (config params unknown)
v1.26.0 Broken Yes
v1.27.0 Broken Yes
v1.27.0 + patch (above) Works Yes
v1.28.0-preview Broken (untested, assumed) Yes

Discovered

2026-03-24 by LofiFren (PicoCalc project)
https://github.com/LofiFren/PicoCalc

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied