Skip to content

Bump tinyusb to include MAX3421E host startup-hang fix (#3748)#11093

Merged
dhalbert merged 6 commits into
adafruit:mainfrom
mikeysklar:tinyusb-oscok-bump
Jul 10, 2026
Merged

Bump tinyusb to include MAX3421E host startup-hang fix (#3748)#11093
dhalbert merged 6 commits into
adafruit:mainfrom
mikeysklar:tinyusb-oscok-bump

Conversation

@mikeysklar

@mikeysklar mikeysklar commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Advances lib/tinyusb from the October 2025 commit to current master so hathach/tinyusb#3748 (MAX3421E USB-host startup-hang fix) is available to build and test, per #10053.

c1bf19ed6 (0.18.0-748) → fcd5a0603 (0.21.0-31). API drift adapted:

  • XFER_RESULT_ABORTED enum → shared-module/usb/core/Device.c
  • usbd_control.c merged into usbd.csupervisor/supervisor.mk
  • TUD_AUDIO_EP_SIZE gained is_highspeed arg → tusb_config.h
  • CFG_TUD_CDC_EP_BUFSIZECFG_TUD_CDC_RX_EPSIZEusb_device.c

Tested: builds clean on adafruit_feather_esp32_v2 (espressif) and feather_m4_express (atmel-samd).

Known blocker — needs @FoamyGuy: nordic doesn't build yet. The same bump reorganized the USB Audio Class descriptor macros (TUD_AUDIO_DESC_*TUD_AUDIO10_/AUDIO20_DESC_*), and shared-module/usb_audio/usb_audio_descriptors.h still uses the old names. That migration is UAC 1.0/2.0-sensitive and wants USB-audio hardware to verify, so it's left for the module owner. (Verified there's no earlier bump point that includes #3748 without this reorg.)

@mikeysklar

mikeysklar commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

@dhalbert -

Flashed and tested USB-host drive detection (MAX3421E FeatherWing, hot-plug SanDisk/PNY/USB-storage) on real hardware with this bump:

Board Firmware Result
Feather ESP32 V2 official CI artifact (this PR) ✅ enumerates 0781:cfcb SanDisk + 154b:005b PNY across hot-swap
Feather RP2350 local build ✅ enumerates SanDisk + PNY
Feather M4 Express local build ✅ boots (device-only; MAX3421E overflows the 512 KB flash by ~11.7 KB, so no host)
Feather nRF52840 Sense local build ✅ enumerates USB-storage + PNY

espressif and atmel-samd build clean in CI as-is.

The RP2350 and nRF52 images above are local builds with CIRCUITPY_USB_AUDIO=0 disabled.

shared-module/usb_audio/usb_audio_descriptors.h still uses under the old names. These seem to be in the process of being migrated those to the TUD_AUDIO20_DESC_* family is the (cc @FoamyGuy). #11058 and #11062

nRF52 needed one more one-liner to build: tinyusb's dcd_nrf5x.c calls nrf_clock_is_running(), but CircuitPython pins nrfx v2.0.0 which only has nrf_clock_hf_is_running(NRF_CLOCK, …). Patched that one call locally to verify the hardware; the proper fix is bumping ports/nordic/nrfx (or upstream tinyusb supporting nrfx v2.0.0).

Neither the audio-disable nor the clock patch is included in this PR.

platform-testing

proof of life

hw-verify-repl-log.txt

@dhalbert

dhalbert commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

@hathach We could use hathach/tinyusb#3748, but we are well behind in circuitpython as you can see above. @mikeysklar has made good progress. Do you have any recommendations or review comments? Thanks.

@hathach

hathach commented Jul 6, 2026

Copy link
Copy Markdown
Member

all changes look good, except the audio since we don't want to haardcode it with FS. Audio HS/FS has different way of calculating timing/samples. It is updated to not hardcored since even with highspeed capable device e.g imxrt, when plugging to FS host, still need to functio as FS audio. However, since cpy mostly work with PC, we can just use the TUD_OPT_HIGH_SPEED.

Advance lib/tinyusb c1bf19ed6 -> fcd5a0603 to pull in hathach/tinyusb#3748
(adafruit#10053), and adapt to its API drift: XFER_RESULT_ABORTED
enum, usbd_control.c merged into usbd.c, TUD_AUDIO_EP_SIZE is_highspeed arg, and
CFG_TUD_CDC_EP_BUFSIZE -> RX_EPSIZE. Builds clean on espressif and atmel-samd;
nordic still needs a usb_audio descriptor macro migration (see PR).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeysklar mikeysklar force-pushed the tinyusb-oscok-bump branch from dd830f1 to 894397c Compare July 6, 2026 13:51
@mikeysklar

mikeysklar commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @hathach!

Updated: both TUD_AUDIO_EP_SIZE(...) calls in supervisor/shared/usb/tusb_config.h to now pass TUD_OPT_HIGH_SPEED instead of a hardcoded false

The audio path can't be fully CI-compiled here yet.

  • the bump also reorganized the UAC descriptor macros (TUD_AUDIO_DESC_*TUD_AUDIO20_DESC_*) and shared-module/usb_audio/usb_audio_descriptors.h

  • still uses the old names, so CIRCUITPY_USB_AUDIO boards (nordic, rp2) need that descriptor migration before this compiles clean.

cc @FoamyGuy (#11058 / #11062)

mikeysklar and others added 3 commits July 9, 2026 12:51
The tinyusb bump splits the flat UAC descriptor API into version-namespaced
UAC 1.0 and UAC 2.0 variants, so shared-module/usb_audio, which targets
UAC 2.0, no longer compiles against the old names. Three layers moved:

  descriptor macros  TUD_AUDIO_DESC_IAD    -> TUD_AUDIO20_DESC_IAD
  enum constants     AUDIO_CTRL_RW         -> AUDIO20_CTRL_RW
  C types            audio_control_cur_1_t -> audio20_control_cur_1_t

AUDIO_TERM_TYPE_* is shared between UAC 1.0 and 2.0 upstream and keeps its
old name.

Two of the renames are not a literal insertion of "20":

  TUD_AUDIO_DESC_STD_AS_INT_LEN -> TUD_AUDIO20_DESC_STD_AS_LEN
      the length macro drops _INT; the emitter keeps it.

  TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL(unitid, srcid, ch0, ch1, stridx)
      -> TUD_AUDIO20_DESC_FEATURE_UNIT(unitid, srcid, stridx, ch0, ch1)
      ONE/TWO_CHANNEL collapse into one varargs macro: stridx moves from
      last to third and the per-channel controls become trailing varargs.
      The paired length macro becomes TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(1),
      still 14 bytes, so the *_DESC_LEN totals are unchanged.

Verified by emitting the speaker/headset/mic descriptors before and after
(old source + old tinyusb vs new source + new tinyusb) and diffing the
bytes: identical at 132/230/132. Clean builds of adafruit_feather_rp2350
and feather_bluefruit_sense, both with CIRCUITPY_USB_AUDIO=1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The tinyusb bump splits the STM32 fsdev driver: fsdev_core_reset,
pma_align_buffer_size and btable_set_rx_bufsize moved out of
dcd_stm32_fsdev.c into a new fsdev_common.c. Add it to SRC_C, mirroring
the dwc2 / dwc2_common.c pattern just below.

Only STM32L433xx boards take the fsdev path, so blues_cygnet was the sole
board failing to link on the three symbols above. It now builds clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The tinyusb bump grows the binary and this board was already at 100.0% of
FLASH_FIRMWARE, so it overflowed by 232 bytes. It never opted into
usb_audio; it inherited CIRCUITPY_USB_AUDIO=1 from the rp2 port default.
Turning it off frees ~9kB.

usb_audio is the USB Audio Class device (enumerating to a host as a mic or
speaker). The board's own audio path is the I2S DAC on GPIO26/27/28 driven
by audiobusio.I2SOut, which is unaffected, as are audiocore, audiomixer,
audiomp3, audiopwmio and synthio.

The non-W pimoroni_pico_dv_base has more headroom and keeps usb_audio.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeysklar

Copy link
Copy Markdown
Collaborator Author

3 commits pushed. CI green except nordic.

80d6cae usb_audio → TUD_AUDIO20_* / AUDIO20_* (@FoamyGuy OK'd on Discord)

  • bigger than a macro rename — 3 layers moved: macros, 23 enums, 7 C types
  • AUDIO_TERM_TYPE_* is shared across UAC 1.0/2.0, keeps its name
  • FEATURE_UNIT ONE/TWO_CHANNEL → varargs TUD_AUDIO20_DESC_FEATURE_UNIT(unitid, srcid, stridx, ...)
  • descriptor bytes diffed before/after: identical (132/230/132). No HW test yet.

d4d5ad3 stm: build fsdev_common.c for STM32L433xx

  • bump split the fsdev driver; 3 symbols moved to a new file
  • mirrors the existing dwc2_common.c pattern. blues_cygnet links.

6c8a542 pimoroni_pico_dv_base_w: disable usb_audio

  • bigger tinyusb → 232 bytes over flash; board was already at 100.0% on main
  • usb_audio = USB Audio device class, not the board's I2S line-out/HDMI audio — audiobusio.I2SOut, audiocore, synthio untouched
  • board never opted in; inherited the rp2 port default. Frees ~9kB. Non-W sibling keeps it.

Remaining: 51 nordic + the windows job (same nordic build). Not caused by this PR.

@relic-se#11102 will need a rebase after this. FEATURE_UNIT_TWO_CHANNEL becomes the same varargs macro with one extra control arg; the AUDIO_* enums and audio_*_t types need the 20 too.

@FoamyGuy — the bump deletes CFG_TUD_AUDIO_FUNC_1_DESC_LEN and _N_AS_INT (the driver walks the descriptor itself now). Both are still defined in tusb_config.h, now dead, and the comment atop usb_audio_descriptors.h is stale. usb_audio_descriptor_length() is still needed by usb_desc.c. Left as-is — clean up here, or fold into the stereo work?

@dhalbert

Copy link
Copy Markdown
Collaborator

Remaining: 51 nordic + the windows job (same nordic build). Not caused by this PR.

Please wait for that to merge (I see it is not yet building successfully). We don't merge PR's with broken builds, in general.

@mikeysklar

mikeysklar commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Will wait.

The test failures were on hathach/tinyusb#3766 - hil-tinyusb.

All 33 hil-build compile jobs pass.

fcd5a0603 -> 5453ed09f. Picks up hathach/tinyusb#3766, which adds an
nrfx v2.0.0 path to hfclk_running() in dcd_nrf5x.c; without it the nordic
port does not compile, since CircuitPython pins nrfx v2.0.0 (MDK 8.29.0)
and tinyusb's v2 path called nrf_clock_is_running(), added in nrfx 2.1.0.

Only other change in the range is a docs line in AGENTS.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeysklar

mikeysklar commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

@dhalbert -

Since this bump introduces nRF52 and usb_audio changes I tested in hardware on a Feather Sense nRF52840 against (hathach/tinyusb#3766). Used this minimal code to confirm usb_audio is visible to macOS.

Adafruit CircuitPython 10.3.0-alpha.3-14-g6c8a542dd0-dirty on 2026-07-10; Adafruit Feather Bluefruit Sense with nRF52840
>>>

macOS enumerates

system_profiler SPAudioDataType
...
        CircuitPython Headset:

          Input Channels: 1
          Manufacturer: Adafruit Industries LLC
          Output Channels: 1
          Current SampleRate: 48000
          Transport: USB
          Input Source: Default
          Output Source: Default
...

boot.py

import usb_audio
import usb_hid
import usb_midi

usb_hid.disable()
usb_midi.disable()

usb_audio.enable(
    sample_rate=48000,
    channel_count=1,
    microphone=True,
    speaker=True,
)

code.py

import time
import usb_audio

print("usb_microphone:", usb_audio.usb_microphone)
print("usb_speaker:   ", usb_audio.usb_speaker)

while True:
    mic = usb_audio.usb_microphone
    spk = usb_audio.usb_speaker
    print(
        "mic connected:", getattr(mic, "connected", None),
        "| speaker connected:", getattr(spk, "connected", None),
    )
    time.sleep(2)

@FoamyGuy

Copy link
Copy Markdown
Collaborator

I tested this successfully on a CircuitPlayground Bluefruit with morse code project code: https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CPB_Morse_Code_Paddle/code.py

@mikeysklar

Copy link
Copy Markdown
Collaborator Author

@FoamyGuy - Thanks for testing!

dhalbert
dhalbert previously approved these changes Jul 10, 2026

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks ok to me!

@dhalbert

Copy link
Copy Markdown
Collaborator

the bump deletes CFG_TUD_AUDIO_FUNC_1_DESC_LEN and _N_AS_INT (the driver walks the descriptor itself now). Both are still defined in tusb_config.h, now dead, and the comment atop usb_audio_descriptors.h is stale.

@mikeysklar Is this still true? Don't leave dead or stale stuff in.

usb_audio_descriptor_length() is still needed by usb_desc.c. Left as-is — clean up here, or fold into the stereo work?

I'm not sure I understand, is that a regression, or a reminder?

@dhalbert dhalbert self-requested a review July 10, 2026 16:33
@dhalbert dhalbert dismissed their stale review July 10, 2026 16:34

see my more recent post

The UAC2 driver bump stopped reading several CFG_TUD_AUDIO_FUNC_1_*
macros (it walks the descriptor itself now). Remove the ones that went
dead: DESC_LEN, N_AS_INT, N_BYTES_PER_SAMPLE_TX/RX, N_CHANNELS_TX/RX.

CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ was silently orphaned too -- the driver
now reads CFG_TUD_AUDIO_CTRL_BUF_SZ (no _FUNC_1_), falling back to its
own default of 64. Rename ours so CP keeps setting 64 explicitly.

usb_audio_descriptor_length() stays: usb_desc.c still calls it to size
total_descriptor_length. Rewrote the stale usb_audio_descriptors.h
comment that claimed TinyUSB reads the now-removed DESC_LEN macro.

Verified with clean CIRCUITPY_USB_AUDIO=1 builds of
adafruit_feather_rp2350 and feather_bluefruit_sense.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeysklar

mikeysklar commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

@dhalbert -

Cleaned up the stale stuff.

  • DESC_LEN and N_AS_INT
  • UAC2 driver no longer reads
    • N_BYTES_PER_SAMPLE_TX/RX
    • N_CHANNELS_TX/RX
  • CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ
  • Rewrote the stale usb_audio_descriptors.h comment

usb_audio_descriptor_length() stays. My note was a reminder to not delete it.

Verified builds clean locally on CIRCUITPY_USB_AUDIO=1 builds of adafruit_feather_rp2350 and feather_bluefruit_sense.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Build is clean, let's merge!

@dhalbert dhalbert merged commit db82b25 into adafruit:main Jul 10, 2026
224 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants