Skip to content

Patch TinyUSB CDC TX persistence bug - #19606

Open
dpgeorge wants to merge 3 commits into
micropython:masterfrom
dpgeorge:shared-tinyusb-patch-cdc-device
Open

Patch TinyUSB CDC TX persistence bug#19606
dpgeorge wants to merge 3 commits into
micropython:masterfrom
dpgeorge:shared-tinyusb-patch-cdc-device

Conversation

@dpgeorge

Copy link
Copy Markdown
Member

Summary

We recently updated to TinyUSB 0.21.0. At the time of updating we didn't realise that they changed how CDC TX persistence is configured -- from runtime configuration to a static macro configuration.

But in the process of changing that, and their updating to a new streams FIFO, the CDC TX persistence got broken.

This PR aims to patch that bug in tinyusb by applying a small .patch file as part of the build process:

  • exclude original cdc_device.c from the build
  • copy original cdc_device.c to build-BOARD/cdc_device.c
  • patch that file
  • add the patched file back to the build
  • build as usual

Both CMake (rp2 port) and make (everything else) are covered.

Testing

Tested on RPI_PICO and TEENSY40: the REPL banner now appears correctly after a hard reset (prior to this patch it was corrupted).

Trade-offs and Alternatives

This slightly complicates the build by patching during the build process.

Alternatives:

  • fork TinyUSB to fix it
  • wait for TinyUSB to fix it and release a new (patch) version
  • not fix it and accept that after a hard reset the REPL output is corrupt (and some chars are copied to the input stream)

Generative AI

I used Gemini to give me hints on how to wrangle CMake into getting this to work, but wrote everything myself.

The runtime config was replaced with simpler static macro config in TinyUSB
commit 222af862aa2b3898980e3ed8f28e70fe6c9a7ee9.

Signed-off-by: Damien George <damien@micropython.org>
See hathach/tinyusb#3807

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added this to the release-1.29.0 milestone Aug 12, 2026
@dpgeorge dpgeorge added ports Relates to multiple ports, or a new/proposed port shared Relates to shared/ directory in source labels Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.55%. Comparing base (b006887) to head (94c17a9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19606      +/-   ##
==========================================
- Coverage   98.59%   98.55%   -0.04%     
==========================================
  Files         182      182              
  Lines       23320    23320              
  Branches        5        5              
==========================================
- Hits        22992    22984       -8     
- Misses        327      335       +8     
  Partials        1        1              
Flag Coverage Δ
unix-coverage-32bit 98.55% <ø> (-0.05%) ⬇️
unix-coverage-64bit 98.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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 Aug 12, 2026

Copy link
Copy Markdown

Code size report:

Reference:  unix/mpconfigport: Use setjmp GC helper on macOS for Intel. [b006887]
Comparison: ports: Apply TinyUSB patch for CDC TX persistence. [merge of 94c17a9]
  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
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:   -32 -0.008% TEENSY40
        rp2:   -16 -0.002% RPI_PICO_W
       samd:   -32 -0.012% ADAFRUIT_ITSYBITSY_M4_EXPRESS[incl -12(bss)]
  qemu rv32:    +0 +0.000% VIRT_RV32

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge
dpgeorge force-pushed the shared-tinyusb-patch-cdc-device branch from 27cd3af to 94c17a9 Compare August 12, 2026 03:20
@octoprobe-bot

Copy link
Copy Markdown

Octoprobe PR report

Test Tests
passed
Tests
skipped
Tests
xfailed
Tests
failed
format flash 9 3
run-tests.py 16447 2571 15
run-tests.py --via-mpy --emit native 16212 2794 18 9
run-tests.py --via-mpy 13531 2217 12
run-perfbench.py 280 8
run-natmodtests.py 595 100 11
run-mpremote-tests.sh 21 6
run-tests.py --test-dirs=extmod_hardware 114 192 54
run-tests.py --test-dirs=extmod_hardware --emit-native 107 182 51
Total 47316 8067 161 15
Failures

Group: run-mpremote-tests.sh

Test stm32
7b21-
PYBV11-
DP
test_unicode.sh FAIL FAIL FAIL
test_mount.sh FAIL FAIL FAIL

Group: run-tests.py --via-mpy --emit native

Test mimxrt
1133-
TEENSY40
nrf
3c2a-
ARDUINO_NANO_33
rp2
5334-
RPI_PICO2
rp2
5334-
RPI_PICO2-
RISCV
rp2
552b-
RPI_PICO2_W
rp2
5f2c-
RPI_PICO_W
samd
5f2a-
ADA_ITSYBITSY_M0
stm32
2b35-
NUCLEO_WB55
stm32
7b21-
PYBV11
stm32
7b21-
PYBV11-
DP
stm32
3a21-
PYBV11-
DP_THREAD
stm32
7b21-
PYBV11-
THREAD
extmod/machine_timer.py pass skip skip skip pass pass pass pass FAIL FAIL FAIL pass pass pass pass pass pass pass
micropython/viper_ptr8_load_boundary.py pass pass pass pass pass pass pass pass FAIL FAIL FAIL pass pass pass pass pass pass pass
stress/qstr_limit.py pass pass pass pass pass pass pass pass FAIL FAIL FAIL pass pass pass pass pass pass pass

@dpgeorge

Copy link
Copy Markdown
Member Author

I made an alternative fix in #19607 which forks TinyUSB.

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

Labels

ports Relates to multiple ports, or a new/proposed port shared Relates to shared/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants