summaryrefslogtreecommitdiff
path: root/src/device
AgeCommit message (Collapse)Author
4 daysusbd: handle a refused transfer without halting, and report ithathach
A refused transfer is a recoverable condition - a new setup superseding a control response, for instance - rather than a bug, but every failure path treated it as one. TU_ASSERT carries TU_BREAKPOINT, which is gated on a debugger being attached rather than on CFG_TUSB_DEBUG, so on a rig where a probe is always attached it halted the CPU even in release builds. Use TU_VERIFY on the control transfer paths, including the multi-packet data stage continuation, and drop the breakpoint from the endpoint transfer failure arm, which already marks the endpoint ready again so the next transfer can proceed. The result of usbd_control_xfer_cb() was separately dropped on the floor, leaving EP0 neither armed nor stalled and nothing recorded. It is logged now, and deliberately not stalled: a DCD refuses an EP0 prime when a newer setup is already latched, and EP0 stalls are cleared by hardware when that setup arrives, so a stall issued here would land after the auto-clear and stall the transfer that superseded this one. The pending setup re-drives EP0 by itself.
4 daysusbd: split bus reset into start/end edge eventshathach
A driver that can see reset signalling begin has no way to say so: the only event carries the negotiated speed, which does not exist until the reset ends. On ChipIdea that left the stack believing it was still configured for the whole reset window - 3 ms at minimum, tens of milliseconds in practice - while the controller had already torn its endpoints down, so a class driver writing in that window primed a disabled endpoint over a zeroed queue head. Add DCD_EVENT_BUS_RESET_START for the leading edge and rename the existing event to DCD_EVENT_BUS_RESET_END, keeping DCD_EVENT_BUS_RESET as an alias. START is optional and END stays self-sufficient, so every other driver and the unit tests are untouched.
9 daysusbd: clear endpoint busy/claimed when a completion event is droppedhathach
An XFER_COMPLETE dropped by a full event queue leaves its endpoint's BUSY|CLAIMED state set forever - the consumer that normally clears it never sees the event, so usbd_edpt_claim()/usbd_edpt_xfer() fail from then on and the class never re-arms the endpoint. Clear both flags when the enqueue fails: the completion is lost either way, but the endpoint stays usable. Unit test: arm a bulk endpoint, drop its completion against a full queue, verify the endpoint can be claimed and re-armed.
10 daysusbd: clear the queued-setup counter on bus resethathach
A SETUP counted before a bus reset must not be carried across it: the consumer would either skip a post-reset SETUP (count drained by the stale entry) or, if the count leaked high for any other reason, skip them all. usbd_reset() now zeroes the counter; the consumer already guards on zero, and any pre-reset SETUP still in the queue is stale by definition and correctly discarded.
10 daysusbd: don't leak the queued-setup counter when the event queue is fullhathach
A SETUP arriving while the event queue is full is silently dropped by queue_event(), but _usbd_queued_setup has already been incremented. The leaked count makes the event handler skip every subsequent SETUP ("Skipped since there is other SETUP in queue") forever: EP0 stays deaf until tud_init() while the device otherwise looks alive - enumerated, endpoints armed. Undo the increment when the enqueue fails. Unit test: fill the queue so a SETUP is dropped, then verify the next SETUP still completes a GET_DESCRIPTOR control transfer.
2026-07-26TU_MIN suggestionTenGui
2026-07-23fix narrowing, add castTenGui
2026-07-09usbd: forward vendor EP0 requests; clear ep state on iso activatehathach
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HeF2gZ1M7GWkz6Av4BpKPg
2026-07-05Fix usbd empty builtin driver warning v2HiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2026-07-05Fix usbd empty builtin driver warningaineoae86-sys
Generated-by: OpenAI Codex Signed-off-by: aineoae86-sys <[email protected]>
2026-07-02license: use SPDX identifiers for src/ headers (#3749)Ha Thach
* license: use SPDX identifiers for src/ headers Replace the full ~20-line MIT license boilerplate on every src/ file with a two-line SPDX tag (SPDX-FileCopyrightText + SPDX-License-Identifier), following the REUSE convention used by CircuitPython and the Linux kernel. Removes ~3500 lines of duplicated boilerplate.
2026-06-22Merge remote-tracking branch 'tinyusb/master' into pr-osal-spin-deinitHiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2026-06-22usbd: add osal_spin_deinit() to tud_deinit()HiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2026-06-16device: clamp EP0 OUT data copy to the control transfer buffer (#3705)Ha Thach
* device: clamp EP0 OUT data copy to the control transfer buffer usbd_control_xfer_cb() copied xferred_bytes from the EP0 bounce buffer into the requester's buffer with no bound. A non-compliant host that sends an OUT data packet larger than the control transfer's data_len (= min(len, wLength), the buffer capacity) would overflow that buffer and over-count total_xferred. Clamp xferred_bytes to the remaining buffer space before the memcpy and accounting.
2026-05-12midi2: align descriptors with USB-MIDI 2.0 specSaulo Veríssimo
Brings the MIDI 2.0 device driver into full conformance with USB Device Class Definition for MIDI Devices v2.0 (USB-IF, May 2020). - Alt 1 MS Interface Header wTotalLength now reports 0x0007 per Table 5-2 ("set to match bLength"), replacing the prior 0x0011 carried over from USB-MIDI 1.0 conventions. - GET_DESCRIPTOR class request now validates bmRequestType direction, type and recipient plus wIndex and wValue high byte per Section 6. - iBlockItem in the default Group Terminal Block is driven by CFG_TUD_MIDI2_BLOCK_STRIDX so applications can attach a UI string descriptor to the block per Table 5-6. - UMP word byte order assumption (little-endian host per Section 3.2.2) is documented inline so future big-endian ports know where to wrap access with tu_htole32 / tu_le32toh. Validated on RP2040 and ESP32-P4 under Linux kernel 6.17: lsusb -v reports wTotalLength = 0x0007 on Alt 1 MS Header (raw bytes 07 24 01 00 02 07 00). amidi -l enumerates Group Terminals exposed via the class-specific GET_DESCRIPTOR response.
2026-05-12fix: address PR review feedback for MIDI 2.0 driversSaulo Veríssimo
Host driver (midi2_host.c): - midih2_open() now returns actual parsed length instead of max_len, preventing composite device interface conflicts - Parsers (alt0/alt1) refactored to return const uint8_t* end pointer following midi_host.c switch/case pattern - Alt 1 CS Endpoint now parses MIDI 2.0 layout (bNumGrpTrmBlk at offset 3 with MIDI_CS_ENDPOINT_GENERAL_2_0 subtype check) instead of reusing MIDI 1.0 struct (bNumEmbMIDIJack) - midih2_set_config() now issues SET_INTERFACE control request via tuh_interface_set() before completing configuration. Falls back to alt 0 if SET_INTERFACE fails - Extracted midih2_set_config_complete() and midih2_set_interface_cb() for async SET_INTERFACE handling Device driver (midi2_device.c): - midi2d_open() skip loop now checks bInterfaceNumber, stopping at interfaces that belong to other functions in composite devices - SET_INTERFACE handler now rejects alt > 1 (returns false/stall) - Named constants for GTB descriptor types and MIDI protocol values Descriptor macros (usbd.h): - TUD_MIDI2_DESC_ALT1_HEAD: iInterface set to 0 (consistent with Alt 0), wTotalLength now uses TUD_MIDI2_DESC_ALT1_CS_LEN to cover all Alt 1 class-specific descriptors - TUD_MIDI2_DESC_ALT1_EP: now accepts GTB ID list via variadic args, emitting complete CS endpoint descriptor Host example: - CMakeLists.txt restricted to rp2040 family (display.c requires Pico SDK headers) - display.c: null terminator after strncpy in log scroll Documentation: - class_drivers.rst updated to reflect SET_INTERFACE behavior and auto-select with fallback Addresses: Codex P1 (#1, #2, #3), Copilot (#4-#9)
2026-05-12feat: add MIDI 2.0 Device class driver (USB-MIDI 2.0)Saulo Veríssimo
Add native USB-MIDI 2.0 Device class driver to TinyUSB. Implements the USB-MIDI 2.0 specification with both Alt Setting 0 (MIDI 1.0 fallback) and Alt Setting 1 (UMP native) descriptor support. Driver features: - UMP (Universal MIDI Packet) read/write with atomic message framing - Protocol negotiation: Endpoint Discovery, Config Request/Notify, Function Block Discovery (embedded in driver) - Group Terminal Block descriptor via GET_DESCRIPTOR - Alt Setting switch handler with endpoint re-arm - Static allocation, no dynamic memory, ISR-safe Build system: - Register midi2d_* in usbd.c driver table - Add TUD_MIDI2_DESCRIPTOR macros to usbd.h - Add config defaults (CFG_TUD_MIDI2_*) to tusb_option.h - Add midi2_ump_word_count() to midi.h (shared by Device and Host) - Add midi2_device.c/h to family.cmake and CMakeLists.txt - Add midi2_device.h include to tusb.h All changes guarded by #if CFG_TUD_MIDI2 (default 0). Zero impact on existing drivers and examples. Tested: Raspberry Pi Pico (RP2040), Linux ALSA, Windows MIDI Services
2026-05-08Merge remote-tracking branch 'tinyusb/master' into ncm_packet_filterHiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2026-05-05Merge pull request #3627 from hathach/merge-usbd-controlHa Thach
Refactor USB control transfer handling into `usbd.c`
2026-05-04fix usbd control to support wLength hackhathach
2026-05-04refactor: replace `tu_edpt_state_t` struct with `uint8_t` and update all ↵hathach
endpoint state handling methods and accesses
2026-05-04refactor `usbd.c`: extract `process_std_device_request` for clarityhathach
2026-05-04refactor `usbd.c`: centralize control transfer state management into ↵hathach
`_usbd_dev` structure and remove `usbd_control_reset`
2026-05-03Merge branch 'master' into copilot/upgrade-net-lwip-webserver-descriptorsZixun LI
2026-05-01Merge remote-tracking branch 'origin/master' into ncm_packet_filterHiFiPHile
2026-05-01ncm: implement GetNtbInputSize requestZixun LI
Signed-off-by: HiFiPHile <[email protected]>
2026-04-30refactor capabilityZixun LI
Signed-off-by: Zixun LI <[email protected]>
2026-04-29deprecated `usbd_control.c` and merge its functionality into `usbd.c`hathach
2026-04-29clean uphathach
2026-04-28Merge branch 'master' into fork/kira-live/masterhathach
# Conflicts: # src/device/usbd_control.c
2026-04-27Merge branch 'master' into ncm_packet_filternminaylov
2026-04-27NCM caps enumnminaylov
2026-04-26usbd_control: consolidate status stage ep selectionhathach
Extract the "which endpoint is the Status stage on" rule into a single TU_ATTR_ALWAYS_INLINE helper, and use it from both status_stage_xact() and the completion callback. Replaces the two-operand wLength/direction check with a direct endpoint-match comparison, matching the first operand's pattern. Per USB 2.0 §9.3.1, when wLength == 0 the bmRequestType Direction bit is ignored and the Status stage is always IN; otherwise the Status stage is opposite to the Data stage direction. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-04-25Merge branch 'master' into musb-followup-3594hathach
# Conflicts: # src/common/tusb_types.h # src/portable/mentor/musb/dcd_musb.c
2026-04-25clean uphathach
2026-04-24NCM packet filter supportnminaylov
2026-04-24fix zero wLength request in control requestakari
2026-04-23Merge upstream master into net descriptor-based ep_size branchcopilot-swe-agent[bot]
- Resolve .gitignore conflict: incorporate upstream's .worktrees entry and expand dependency path patterns to cover all tools/get_deps.py fetched dirs (lib/, tools/linkermap, tools/uf2, hw/mcu/*) instead of listing only a few - Auto-merged upstream changes: build system cleanups, BSP updates, portability fixes, new boards (nrf54lm20dk, stm32h743_weact), fatfs relocation, and many other upstream improvements - Net driver changes (ecm_rndis_device.c, ncm_device.c, net_device.h, usbd.h, usb_descriptors.c) retain our PR's descriptor-based ep_size approach as our branch takes precedence Co-authored-by: HiFiPhile <[email protected]>
2026-04-17remove duplicated tu_le16toh since we have converted the endian when setup.Fan DANG
2026-04-13fix(device): big-endian host support for SETUP packet handlingFan DANG
1. Add TU_LITTLE_ENDIAN_BITFIELD / TU_BIG_ENDIAN_BITFIELD macros in tusb_compiler.h (GCC and IAR), following Linux kernel style. 2. Update bmAttributes (tusb_desc_endpoint_t) and bmRequestType_bit (tusb_control_request_t) in tusb_types.h to use these macros with explicit #error fallback if undefined. 3. Add tu_le16toh() conversion in dcd_event_setup_received() for wValue/wIndex/wLength. Tested on CIU98320B (big-endian ARM Cortex-M, full-speed HID keyboard).
2026-03-22net: upgrade net_lwip_webserver to separate FS/HS descriptors and add ↵copilot-swe-agent[bot]
bInterval to TUD_CDC_NCM_DESCRIPTOR Co-authored-by: HiFiPhile <[email protected]> Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/e212b526-e279-4a83-88bf-a742df293165
2026-03-22Simplify tud_task() like in tuh_task()Cédric Berger
2026-03-11refactor(usbd): replace `_usbd_ctrl_epbuf` with `usbd_get_ctrl_buf()` for ↵hathach
cleaner abstraction and consistency across modules
2026-03-11Merge branch 'master' into ep0_directhathach
# Conflicts: # hw/bsp/same7x/boards/same70_qmtech/board.cmake # hw/bsp/same7x/boards/same70_xplained/board.cmake # hw/bsp/same7x/family.cmake
2026-03-06replace printer_to_hid example with printer_to_cdc examplehathach
fix printer GET_DEVICE_ID request weird wIndex (interface high, alt low)
2026-03-06update printer class: enhance descriptors, buffer sizes, and callbackshathach
2026-03-06Merge branch 'refs/heads/master' into fork/remiberthoz/device-class-printerhathach
2026-02-27Merge remote-tracking branch 'tinyusb/master' into dwc2_deinitHiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2026-02-13use CFG_TUD_CONFIGURE_DWC2_DEFAULT to make it easier to add more valuehathach
2026-02-13add CFG_TUD_VBUS_SENSE, that could allow to skip tud_configure() for fixed ↵hathach
vbus sensing simplify dwc2_stm32_gccfg_cfg() using guid value