summaryrefslogtreecommitdiff
path: root/src/device/usbd.c
AgeCommit message (Collapse)Author
10 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.
10 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.
2026-08-13usbd: 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.
2026-08-12usbd: 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.
2026-08-12usbd: 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-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-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-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-04-29deprecated `usbd_control.c` and merge its functionality into `usbd.c`hathach
2026-04-17remove duplicated tu_le16toh since we have converted the endian when setup.Fan DANG
2026-03-22Simplify tud_task() like in tuh_task()Cédric Berger
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-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-01Actually exit the loop in addition to logging. ENOTENOUGHCOFFEECédric Berger
2026-02-01Limit events processed by tud_task_ext() / tuh_task_ext()Cédric Berger
2026-01-06catch deinit errorHiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2026-01-04Implement Printer Device ClassRémi Berthoz
2025-12-15Merge pull request #3364 from hathach/hcd_fsdevHa Thach
hcd: add stm32_fsdev driver
2025-12-15minor clean uphathach
2025-12-13Merge pull request #3358 from hathach/dwc2_cfgHa Thach
Add dcd_configure for dwc2 FIFO config
2025-12-13Merge branch 'refs/heads/master' into hcd_fsdevhathach
2025-12-12remove bitfield in usbd_device_t state to reduce code sizehathach
2025-12-11move host hacked bulk mps out of tu_edpt_validate()hathach
2025-12-11refactor binding ep and interface to driverhathach
2025-12-10move hwid into edpt stream for consistent APIhathach
2025-12-10minor formathathach
2025-12-10revert the usbd_edpt_xfer_fifo guardhathach
2025-12-08usbd: remove dcd_edpt_xfer_fifo ifdef guardZixun LI
Signed-off-by: Zixun LI <[email protected]>
2025-12-02Merge remote-tracking branch 'tinyusb/master' into dwc2_cfgZixun LI
2025-11-27Merge remote-tracking branch 'tinyusb/master' into hcd_fsdevZixun LI
Signed-off-by: Zixun LI <[email protected]>
2025-11-27usbd: clear state and call callback on deinitZixun LI
Signed-off-by: Zixun LI <[email protected]>
2025-11-21dcd: add tud_configure()HiFiPhile
Signed-off-by: HiFiPhile <[email protected]>
2025-11-21edpt stream support xfer_fifo for device CFG_TUD_EDPT_DEDICATED_HWFIFOhathach
cdc device omit ep buffer when hwfifo is supported
2025-11-20refactor tu_fifo, add tu_fifo_write/read/peek_n_access()hathach
2025-11-11Merge remote-tracking branch 'tinyusb/master' into ↵HiFiPhile
copilot/fix-dcd-edpt-xfer-issue Signed-off-by: HiFiPhile <[email protected]>
2025-11-07fix more alerts found by pvs-studiohathach
2025-11-04Fixed more alert found by PVS-Studiohathach
2025-10-31Merge remote-tracking branch 'tinyusb/master' into ↵HiFiPhile
copilot/fix-dcd-edpt-xfer-issue Signed-off-by: HiFiPhile <[email protected]>
2025-10-22Add is_isr parameter to usbd_edpt_xfer and usbd_edpt_xfer_fifocopilot-swe-agent[bot]
- Added bool is_isr parameter to usbd_edpt_xfer() and usbd_edpt_xfer_fifo() wrapper functions - These are called by class drivers to queue USB transfers - Updated all callers to pass false by default (non-ISR context) - Updated audiod_rx_xfer_isr() and audiod_tx_xfer_isr() to pass true (ISR context) - All 21 unit tests pass Co-authored-by: HiFiPhile <[email protected]>
2025-10-22Add is_isr parameter to dcd_edpt_xfer and dcd_edpt_xfer_fifocopilot-swe-agent[bot]
Co-authored-by: HiFiPhile <[email protected]>