Conversation
There was a problem hiding this comment.
Pull Request Overview
Update TinyUSB to 0.19.0 with new class support, MCU additions, and broad API cleanup.
- Add Media Transfer Protocol (MTP) device class, descriptors, and config flag.
- Extend MCU support (STM32WBA, ESP32H4) and refine several ports (DWC2, STM32 FSDEV).
- Normalize application callbacks: headers declare non-weak prototypes; weak stubs provided in source files. Various bug fixes and small API improvements.
Reviewed Changes
Copilot reviewed 46 out of 48 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tusb_option.h | Bump minor version to 0.19; add MCU IDs for STM32WBA, ESP32H4; add MTP config flag. |
| src/tusb.h | Include MTP device header under CFG_TUD_MTP; remove time API prototypes (moved). |
| src/tusb.c | Add weak stubs for virt/phys address translation. |
| src/portable/synopsys/dwc2/dwc2_stm32.h | Add STM32WBA support and minor PHY init behavior. |
| src/portable/synopsys/dwc2/dwc2_esp32.h | Add ESP32H4 (wrap_*) register naming and controller info. |
| src/portable/synopsys/dwc2/dwc2_common.c | Improve core reset sequence; add AHB master idle check; comments clarified. |
| src/portable/st/stm32_fsdev/fsdev_stm32.h | Define FSDEV_HAS_SBUF_ISO per STM32 family; adjust STM32U0 config. |
| src/portable/st/stm32_fsdev/fsdev_ch32.h | Define FSDEV_USE_SBUF_ISO and default double-buffer config. |
| src/portable/st/stm32_fsdev/fsdev_at32.h | Same as CH32: basic ISO/SBUF toggles. |
| src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | Conditional ISO double-buffering and SBUF_ISO handling; PMA allocation logic. |
| src/osal/osal_none.h | Remove unused osal_task_delay weak declaration. |
| src/host/usbh_pvt.h | Make usbh_app_driver_get_cb non-weak (weak stub added in .c). |
| src/host/usbh.h | Make mount/umount callbacks non-weak; keep prototypes concise. |
| src/host/usbh.c | Add weak stubs for app driver and mount/umount callbacks; casting fixes. |
| src/device/usbd_pvt.h | Make usbd_app_driver_get_cb non-weak. |
| src/device/usbd.h | Add MTP descriptor template macros. |
| src/device/usbd.c | Register MTP driver; add weak stubs (app driver, dcd_edpt_xfer_fifo). |
| src/device/dcd.h | Remove weak attribute from dcd_edpt_xfer_fifo declaration. |
| src/common/tusb_verify.h | Fix documentation examples of TU_VERIFY/TU_ASSERT semantics. |
| src/common/tusb_mcu.h | Add STM32WBA, ESP32H4 blocks; adjust RP2040 fast func attribute. |
| src/common/tusb_common.h | Add helper macro; move time and cache/addr APIs here; change to extern (non-weak). |
| src/class/video/video_device.h | Make callbacks non-weak. |
| src/class/video/video_device.c | Provide weak stubs for video callbacks. |
| src/class/usbtmc/usbtmc_device.h | Make callbacks non-weak. |
| src/class/usbtmc/usbtmc_device.c | Provide weak stubs; simplify checks. |
| src/class/msc/msc_host.h | Make mount/umount callbacks non-weak. |
| src/class/msc/msc_host.c | Provide weak stubs; remove pointer checks before invoking callbacks. |
| src/class/msc/msc_device.h | Make optional MSC callbacks non-weak. |
| src/class/msc/msc_device.c | Provide weak stubs; simplify callback invocation. |
| src/class/midi/midi_host.c | Discard malformed packets safely. |
| src/class/midi/midi_device.h | Make RX callback non-weak. |
| src/class/midi/midi_device.c | Provide weak stub for RX callback. |
| src/class/hid/hid_host.h | Make HID host callbacks non-weak. |
| src/class/hid/hid_host.c | Add weak stubs; unaligned wReportLength handling; callback invocation cleanup. |
| src/class/hid/hid.h | Add Power and Battery usage pages. |
| src/class/dfu/dfu_device.h | Make DFU callbacks non-weak. |
| src/class/dfu/dfu_device.c | Provide weak stubs; simplify callback invocation. |
| src/class/cdc/cdc_host.h | Make CDC host callbacks non-weak. |
| src/class/cdc/cdc_host.c | Provide weak stubs; remove null checks before callbacks. |
| src/class/cdc/cdc_device.h | Make CDC device callbacks non-weak. |
| src/class/cdc/cdc_device.c | Provide weak stubs; simplify callback invocation. |
| src/class/bth/bth_device.h | Make BT device callbacks non-weak. |
| src/class/bth/bth_device.c | Provide weak stubs; formatting; callback invocation cleanup. |
| src/class/audio/audio_device.h | Remove required AS interface count macros. |
| src/class/audio/audio_device.c | Rework alt-setting tracking to per-EP; control handling refactor; callbacks use alt per-EP. |
| src/arduino/webusb/Adafruit_USBD_WebUSB.cpp | Make BOS descriptor callback weak. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| uint8_t func_id; | ||
| TU_VERIFY(audiod_verify_itf_exists(itf, &func_id)); | ||
|
|
||
| // Default to 0 if interface not yet activated | ||
| uint8_t alt = 0; | ||
| #if CFG_TUD_AUDIO_ENABLE_EP_IN | ||
| if (_audiod_fct[func_id].ep_in_as_intf_num == itf) { | ||
| alt = _audiod_fct[func_id].ep_in_alt; | ||
| } | ||
| #endif | ||
| #if CFG_TUD_AUDIO_ENABLE_EP_OUT | ||
| if (_audiod_fct[func_id].ep_out_as_intf_num == itf) { | ||
| alt = _audiod_fct[func_id].ep_out_alt; | ||
| } | ||
| #endif | ||
|
|
||
| TU_VERIFY(audiod_get_AS_interface_index_global(itf, &func_id, &idxItf, &dummy)); | ||
| TU_VERIFY(tud_control_xfer(rhport, p_request, &_audiod_fct[func_id].alt_setting[idxItf], 1)); | ||
| TU_VERIFY(tud_control_xfer(rhport, p_request, &alt, 1)); | ||
|
|
||
| TU_LOG2(" Get itf: %u - current alt: %u\r\n", itf, _audiod_fct[func_id].alt_setting[idxItf]); | ||
| TU_LOG2(" Get itf: %u - current alt: %u\r\n", itf, alt); | ||
|
|
There was a problem hiding this comment.
GET_INTERFACE returns 0 for AudioStreaming interfaces that have no endpoint, because alt is only derived from ep_in_alt/ep_out_alt. This breaks setups where an AS interface without EP is set to a non-zero alternate setting. Track and return the current alt-setting per AS interface regardless of whether an EP is present (e.g., maintain a small per-interface alt map in audiod_function_t, update it in SET_INTERFACE, and read it here as the primary source).
| TU_VERIFY(audiod_verify_itf_exists(itf, &func_id)); | ||
|
|
||
| audiod_function_t *audio = &_audiod_fct[func_id]; | ||
|
|
There was a problem hiding this comment.
SET_INTERFACE updates ep_in_alt/ep_out_alt when endpoints are found later, but does not persist the alt-setting for interfaces that have no EP. Persist the alt-setting for any AS interface at the start of this handler (e.g., audio->as_itf_alt[itf] = alt), so GET_INTERFACE can report it accurately even when no EP is present.
| // Persist the alt-setting for any AS interface, so GET_INTERFACE can report it accurately even when no EP is present | |
| audio->as_itf_alt[itf] = alt; |
| // The software must check that bit 31 in this register is set to 1 (AHB Master is Idle) before starting any operation | ||
| while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) { | ||
| } | ||
|
|
There was a problem hiding this comment.
This unbounded wait can hang the system if AHBIDL never asserts (e.g., clock/reset misconfig). Add a bounded timeout (using tusb_time_millis_api or a small iteration counter) and fail gracefully (TU_ASSERT/TU_VERIFY) to avoid deadlock.
| extern void tusb_app_dcache_flush(uintptr_t addr, uint32_t data_size); | ||
|
|
||
| // invalidate data cache | ||
| TU_ATTR_WEAK extern void tusb_app_dcache_invalidate(uintptr_t addr, uint32_t data_size); | ||
| extern void tusb_app_dcache_invalidate(uintptr_t addr, uint32_t data_size); | ||
|
|
||
| // Optional physical <-> virtual address translation | ||
| TU_ATTR_WEAK extern void* tusb_app_virt_to_phys(void *virt_addr); | ||
| TU_ATTR_WEAK extern void* tusb_app_phys_to_virt(void *phys_addr); | ||
| extern void* tusb_app_virt_to_phys(void *virt_addr); | ||
| extern void* tusb_app_phys_to_virt(void *phys_addr); |
There was a problem hiding this comment.
These are declared as non-weak externs but there are no default weak definitions for the dcache functions. On ports that call them without an application override, this will cause link errors. Provide weak no-op stubs in a common C file (similar to tusb_app_virt_to_phys/phys_to_virt in tusb.c) so the optional semantics are preserved.
No description provided.