Skip to content

lib/tinyusb: Update to version 0.19.0-24.#18406

Merged
dpgeorge merged 3 commits into
micropython:masterfrom
dpgeorge:lib-tinyusb-update-0-19
Nov 24, 2025
Merged

lib/tinyusb: Update to version 0.19.0-24.#18406
dpgeorge merged 3 commits into
micropython:masterfrom
dpgeorge:lib-tinyusb-update-0-19

Conversation

@dpgeorge

@dpgeorge dpgeorge commented Nov 12, 2025

Copy link
Copy Markdown
Member

Summary

This PR updates TinyUSB to 0.19.0-24. That's 0.19.0 plus the following changes:

  • remove obsolete dcd_esp32sx
  • fix for HID stylus descriptor and HID example
  • typos, docs and generator scripts
  • MTP fix
  • DWC2 enumeration when EP0 size=8
  • DWC2 fix for EP0 IN
  • stm32 FSDEV IRQ remapping fix
  • DWC2 ZLP fix

The reason we need the extra 24 commits is due to a bug with TinyUSB's handling of zero-length-packets in the DWC2 (Synopsis) backend, which affects the stm32 port. That's fixed by hathach/tinyusb#3293

(The same DWC2 bug affects ESP32-Sx, but needs to be fixed separately because we are using the IDF component manager to get TinyUSB for the esp32 port.)

Testing

Tested on Linux and macOS using the test from #18402, with the following boards:

  • rp2 Pico: ok
  • rp2 Pico 2 RISCV: ok
  • mimxrt TEENSY40: ok (although fails DATA IN for largest packet, but that's also on current TinyUSB)
  • samd ADAFRUIT_ITSYBITSY_M0_EXPRESS: ok (but fails DATA OUT verified for 16k packets, but that's also on current TinyUSB)
  • stm32 PYBV10: ok
  • stm32 OPENMV_N6: ok (but known issue with soft reset)
  • nrf ARDUINO_NANO_33_BLE_SENSE: ok

Trade-offs and Alternatives

Not much alternative here, we anyway need to update TinyUSB to keep up with the latest version, and get STM32N6 support.

@dpgeorge dpgeorge added the lib Relates to lib/ directory in source label Nov 12, 2025
@dpgeorge dpgeorge requested a review from projectgus November 12, 2025 04:12
@codecov

codecov Bot commented Nov 12, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (c9af4e1) to head (207562d).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18406   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22299    22299           
=======================================
  Hits        21938    21938           
  Misses        361      361           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 12, 2025

Copy link
Copy Markdown

Code size report:

Reference:  tools/mpy-tool.py: Add Compiler Explorer JSON output. [c9af4e1]
Comparison: shared/tinyusb: Remove macro guard for tx_overwritabe_if_not_connected. [merge of 207562d]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:  +376 +0.100% TEENSY40[incl +4(data)]
        rp2:  +380 +0.041% RPI_PICO_W[incl +8(bss)]
       samd:  +368 +0.135% ADAFRUIT_ITSYBITSY_M4_EXPRESS[incl +4(data) -4(bss)]
  qemu rv32:    +0 +0.000% VIRT_RV32

@projectgus projectgus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change seems good to me, it's clearly necessary for the DWC2 ZLP fix at least.

Code size impact is larger than we'd like, but again unsure if there's much alternative.

One thing to note is that this update will bring in the header change from 3ec2e36 - as we now expect this to be enabled universally then we could take out the #if guard around it.

@iabdalkader

Copy link
Copy Markdown
Contributor

I've tested this with AE3 and N6 (my DFU bootloader, not the new stm32 stack support), and DFU and CDC seem to work fine.

@dpgeorge dpgeorge force-pushed the lib-tinyusb-update-0-19 branch from 8e2395e to ebde083 Compare November 17, 2025 04:20
@dpgeorge

Copy link
Copy Markdown
Member Author

One thing to note is that this update will bring in the header change from 3ec2e36 - as we now expect this to be enabled universally then we could take out the #if guard around it.

Good catch! I've now removed that header guard, and updated the struct name to the newer version.

@dpgeorge

Copy link
Copy Markdown
Member Author

I updated this PR to use the freshly released TinyUSB 0.20.0. Still needs testing.

@dpgeorge

Copy link
Copy Markdown
Member Author

I tested TinyUSB 0.20.0 on ADAFRUIT_ITSYBITSY_M0_EXPRESS (samd21) and there is a problem, it takes about 5 seconds between the USB device enumeration and the CDC to appear, and then some of the TX date appears in the RX buffer.

Doing a git bisect on TinyUSB, the commit that introduces that problem is: hathach/tinyusb@f11adb0

I spent a bit of time trying to work out the issue but did not make any progress (the issue could very well be with our integration of TinyUSB, although the bug doesn't happen on other ports). So for now I think we need to stick with 0.19.0-24, as originally tested for this PR.

@hathach FYI see above, it looks like there's a problem with TinyUSB 0.20.0 on samd21, at least with the way we are using it.

@HiFiPhile

Copy link
Copy Markdown

Are you testing with stock example like cdc_dual_ports ? Sounds like memory corruption that multiple buffers are overlapped.

@hathach

hathach commented Nov 21, 2025

Copy link
Copy Markdown

@dpgeorge commit migrate cdc device to use common edpt stream API. maybe I miss something and/or there is some configure that need some tweak up. I will try to test when possible.

@dpgeorge

Copy link
Copy Markdown
Member Author

Are you testing with stock example like cdc_dual_ports ?

No, I'm was only testing with MicroPython, with all commits as at this PR.

But, I did now test the TinyUSB cdc_dual_ports example with the itsybitsy_m0 board profile, and the example works fine, the USB CDC appears immediately after enumeration.

@robert-hh

Copy link
Copy Markdown
Contributor

I tested TinyUSB 0.20.0 on ADAFRUIT_ITSYBITSY_M0_EXPRESS (samd21) and there is a problem, it takes about 5 seconds between the USB device enumeration and the CDC to appear, and then some of the TX date appears in the RX buffer.

I had a similar experience with SAMD devices and previous TinyUSB versions, both the initial delay and output data appearing in the RX buffer. About the latter I had a discussion with @projectgus, but I did not find the link instantly. He said it was changed, but it still happens with various boards, both SAMD and ESP32. The initial delayed enumeration disappeared after I changed the USB hub on my desk. But that may have been just coincidence, because the change was for a different reason.

@dpgeorge

Copy link
Copy Markdown
Member Author

The initial delayed enumeration disappeared after I changed the USB hub on my desk

FWIW, I'm using a USB port directly into the (Arch Linux) PC, so the only USB hubs are the internal ones.

And my testing shows that the issue is clearly introduced by the TinyUSB commit I link to above.

Signed-off-by: Damien George <damien@micropython.org>
This is 0.19.0 plus the following changes:
- remove obsolete dcd_esp32sx
- fix for HID stylus descriptor and HID example
- typos, docs and generator scripts
- MTP fix
- DWC2 enumeration when EP0 size=8
- DWC2 fix for EP0 IN
- stm32 FSDEV IRQ remapping fix
- DWC2 ZLP fix

The reason we need the extra 24 commits is due to a bug with TinyUSB's
handling of zero-length-packets in the DWC2 (Synopsis) backend, which
affects the stm32 port.  That's fixed by
hathach/tinyusb#3293

Signed-off-by: Damien George <damien@micropython.org>
It's now available in the version of TinyUSB used by this repository.

Also, update to the newer `tud_cdc_configure_t` struct name and newer
`tud_cdc_configure()` function name.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the lib-tinyusb-update-0-19 branch from a8eb579 to 207562d Compare November 24, 2025 01:47
@dpgeorge

Copy link
Copy Markdown
Member Author

I've rolled this back to just update TinyUSB to 0.19.0-24. That seems the safest option for the next MicroPython release.

Can work out what the issue is with TinyUSB 0.20.0 at a later date (and it could well be just a MicroPython integration issue, not a problem with TinyUSB itself).

@dpgeorge dpgeorge merged commit 207562d into micropython:master Nov 24, 2025
74 checks passed
@dpgeorge dpgeorge deleted the lib-tinyusb-update-0-19 branch November 24, 2025 02:38
@iabdalkader

iabdalkader commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

@dpgeorge FYI the ARDUINO_NANO_33_BLE_SENSE REV2 gets stuck in a boot loop after this update I think.

Never mind, I can't get the board to work with any old release, it's probably broken.

@dpgeorge

Copy link
Copy Markdown
Member Author

I tested ARDUINO_NANO_33_BLE_SENSE REV2 again with latest master and it works OK.

@iabdalkader

Copy link
Copy Markdown
Contributor

I tested ARDUINO_NANO_33_BLE_SENSE REV2 again with latest master and it works OK.

Thanks! This confirms that my board is broken.

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

Labels

lib Relates to lib/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants