10598 Commits

Author SHA1 Message Date
4c87db341e Merge pull request #3571 from sauloverissimo/feat/midi2-device-host-driver
feat: Add USB-MIDI 2.0 Device and Host class drivers
2026-05-19 22:12:28 +02:00
dad8c0ae51 midi2_host: convert TX to raw FIFO mirroring midi2_device refactor 2026-05-19 16:34:42 -03:00
b54c8666ec update example
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-18 23:08:03 +02:00
4baf1883c1 midi2: convert to raw Tx FIFO for better segmentation handling, add count to packet api
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-18 23:07:49 +02:00
aaca323bd3 midi2: boundary-aware drain in xfer_cb to keep UMP packets intact 2026-05-18 11:42:34 -03:00
b31e7cdbbe midi2: drain pattern for RX FIFO
Default RX/TX buffers to EPSIZE for both device and host. Document
drain-in-loop on ump_read; example device callback drains until
empty.
2026-05-17 19:56:04 -03:00
287096f733 midi2: scale device buffers with EPSIZE
Match midi2_host pattern. Literal 256 underran HS endpoints (512B).
2026-05-17 13:07:21 -03:00
4b729bfb92 midi2: per-interface weak callbacks for UMP Stream config
Lets each instance return different NUM_GROUPS, NUM_FUNCTION_BLOCKS,
EP_NAME and PRODUCT_ID. Defaults fall back to the macros.
2026-05-17 12:19:45 -03:00
5ac6346dd4 midi2: peek 4 bytes for MT, restore 256 buffers
MT is in byte 3 of the UMP word in LE memory, not byte 0. Buffers
at mps blocked RX xfer re-arm on partial packets.
2026-05-17 11:31:12 -03:00
e00ac15b7f midi2: use hwfifo if supported
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-17 14:35:34 +02:00
3f209e2a00 midi2: move config to class header
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-17 14:11:53 +02:00
116395a1b2 bsp: fix tcpp0203 lto uninit error
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-17 14:05:03 +02:00
2a58e8256e midi2: skip.txt comments 2026-05-16 22:54:25 -03:00
7cf579dd49 midi2: skip 3 more boards with same tcpp0203 BSP bug
stm32h573i_dk, stm32n657nucleo and stm32n6570dk have the same
pre-existing uninitialized io_ctx.GetTick in their board.h that we
already skip on stm32h7s3nucleo. Trips with Make+LTO; CMake passes.
2026-05-16 22:37:45 -03:00
478e04778b midi2: remove unused ump_noop helper
arm-clang fails with -Werror=unused-function; arm-gcc was silently
omitting it via LTO. The helper was never called.
2026-05-16 21:44:22 -03:00
7c214f9d4f midi2: add sources to TINYUSB_SRC_C, skip family
Make build was missing midi2_device.c/midi2_host.c from
src/tinyusb.mk. Skip stm32h7s3nucleo board which exposes a
pre-existing uninitialized warning in its board.h (board_init2)
under Make+LTO.
2026-05-16 21:35:21 -03:00
214de5181c midi2: fix CI matrix with only.txt and skip.txt
Restrict midi2_host build to MCUs with USB host support (cloned from
midi_rx) and skip SAMD11 from midi2_device (ROM overflow on link).
2026-05-16 20:39:20 -03:00
3efac1b28c midi2: host example - simplify and rename to midi2_host
Drop Feather-specific scaffolding (SSD1306 display, font, PIO-USB pin
override) and rename the directory to midi2_host. The example is now a
single main.c + tusb_config.h pair following the midi_rx pattern, with a
printf-only UMP decoder for Channel Voice messages.

Build-tested on adafruit_feather_rp2040_usb_host, daisyseed (stm32h7),
mimxrt1010_evk, stm32f407disco, raspberry_pi_pico2, b_u585i_iot2a,
portenta_c33, stm32h503nucleo, stlinkv3mini, feather_stm32f405.

Ref #3571
2026-05-16 13:00:30 -03:00
43a72cb614 midi2: device example - portable, add protocol fallback
Remove the rp2040-only guard; the example now follows the audio_test
pattern (only Espressif uses its own build system). Add CMakePresets.json
and generic product strings.

The runtime fallback picks the path that matches the host state, per
message, mirroring the idea behind the UAC examples:
  Alt 0                   USB-MIDI 1.0 32-bit Event Packets (packet_write)
  Alt 1 + MIDI 1.0 negotiated   UMP MT 0x2 (ump_write)
  Alt 1 + MIDI 2.0 negotiated   UMP MT 0x4 (ump_write)

Build-tested on rp2040, rp2350, stm32f0/f1/f2/f3/f4/f7/g0/g4/h5/h7/l0/l4/u0/u5/wb/c0,
samd2x_l2x, samd5x_e5x, same7x, nrf, imxrt, lpc17, lpc55, mcx, ra,
da1469x, efm32.

Ref #3571
2026-05-16 13:00:05 -03:00
840f3e0a62 midi2: prevent UMP packet split across USB transfers
The edpt_stream auto-flush is byte-oriented and could cut an UMP message
in half when the FIFO reached wMaxPacketSize, corrupting the peer's RX
context. Pre-flush whole packets before writing one that would cross the
boundary on both device (tud_midi2_n_ump_write) and host
(tuh_midi2_ump_write) paths. Host write also becomes packet-aware
instead of word-by-word.

Ref #3571
2026-05-16 12:59:44 -03:00
0af0665ed6 midi2: reject UMP read/write API on alt setting 0
Alt 0 carries USB-MIDI 1.0 32-bit Event Packets, not UMP words; calling
the UMP API there would misinterpret the stream. Expose MIDI_PROTOCOL_MIDI1
and MIDI_PROTOCOL_MIDI2 in the public header so applications can branch on
the negotiated protocol.

Ref #3571
2026-05-16 12:59:03 -03:00
90c0884c71 Merge pull request #3644 from bdolgov/fix/rp2040-hcd-set-report-pid
rp2040 host: fix SET_REPORT (and any OUT-data control xfer) sending DATA0 instead of DATA1
2026-05-16 16:34:07 +02:00
72e09788e4 rp2040: fix host SET_REPORT (and any OUT-data control xfer) sending DATA0 instead of DATA1
hcd_edpt_xfer() previously reset ep->next_pid to 1 only when the control
endpoint direction changed between stages. That handled IN-data control
transfers (e.g. GET_REPORT, GET_DESCRIPTOR) where SETUP is OUT and DATA is
IN, but not OUT-data class requests like SET_REPORT, where SETUP and DATA
are both OUT and the direction-change check is false. ep->next_pid was
left at 0 from hcd_edpt_open(), so the DATA stage went on the wire as
DATA0 when the device expected DATA1. Strict devices (observed: Elgato
Stream Deck) treat this as a protocol violation and disconnect.

Key off "endpoint 0" instead of "direction changed", restoring the
previous behavior. Interrupt/bulk endpoints take the ep->interrupt_num > 0
branch above and never reach this code, so they are unaffected.
2026-05-15 21:28:21 +02:00
7f146c9ff6 Merge pull request #3641 from wjklimek1/mtp-get-partial-object
Add GetPartialObject to MTP example
2026-05-14 13:34:27 +02:00
09f8208f5b Add GetPartialObject to MTP example
Added support for GetPartialObject for better compatibility with Linux file explorers.
2026-05-13 22:27:57 +02:00
e1cb1b5b6f Merge pull request #3640 from hathach/dwc2_iso_in
dcd/dwc2: fix ISO IN endpoint become disabled after incomplete transfer
2026-05-13 15:27:47 +02:00
460ce56f40 hil: add audio test, optimize log print
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-12 22:18:05 +02:00
08f9855e3d Merge pull request #3639 from michael-membrowse/membrowse_map_support
ci: MemBrowse - add libraries mapping support
2026-05-12 20:06:17 +02:00
1f662779c4 dcd/dwc2: fix ISO IN endpoint become disabled after incomplete transfer
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-12 19:57:09 +02:00
0a18f30a6e support map files 2026-05-12 17:15:33 +01:00
97852816e8 midi2: align descriptors with USB-MIDI 2.0 spec
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-12 11:07:45 -03:00
0c68ca8c1d midi2: align ep_buf allocation with other stream-based classes
Keep the MIDI 2.0 drivers fully self-contained, with no changes to
shared or generic stack code.

Allocate the per-endpoint buffer in both midi2_host and midi2_device,
following the convention used by cdc, midi, vendor, and printer.

The class buffer struct is declared unconditionally and passed to
tu_edpt_stream_init on every init, so the streaming helpers operate
on the same shape across all classes.
2026-05-12 11:07:45 -03:00
b4880761bc refactor: replace midi2_host (Waveshare) with midi2_host_feather
Remove the Waveshare RP2350-USB-A host example and board definition.
The Feather RP2040 USB Host is the TinyUSB reference board for
PIO-USB host and does not require the CFG_TUSB_DEBUG workaround
needed by the Waveshare (R13 pull-up issue).

One host example is sufficient for the PR. The Feather variant has
an improved display with splash, spinner, and 6-line live view.
2026-05-12 11:07:45 -03:00
c4847006db fix: skip midi2_host_feather build on non-RP2040 platforms
The Makefile was missing the FAMILY=rp2040 guard, causing CI failures
on stm32h7rs and other non-RP2040 targets. Matches the approach used
by midi2_host.
2026-05-12 11:07:44 -03:00
13c6f6a2c7 example: add MIDI 2.0 Host example for Adafruit Feather RP2040 USB Host
Board-specific variant of midi2_host targeting the Adafruit Feather
RP2040 with USB Type A Host (product 5723).

Hardware differences from the Waveshare RP2350-USB-A example:
- PIO-USB on GP16/GP17 (vs GP12/GP13)
- I2C1 via STEMMA QT on GP2/GP3 (vs I2C0 GP4/GP5)
- USB Host 5V power enable on GP18

Display uses three phases: splash screen, spinner while waiting for
a device, then live scrolling UMP message view with 6 visible lines.

Tested board-to-board: RP2040 Pico (Device) to Feather RP2040 (Host),
SSD1306 128x64 OLED showing decoded MIDI 2.0 messages in real time.
2026-05-12 11:07:44 -03:00
f8a5fc37f3 fix: CI build failures on non-RP2040 platforms
- Use UINT32_C(1) instead of 1u for bit shifts >= 16 in
  midi2_device.c to avoid shift-count-overflow on 16-bit
  platforms (MSP430)
- Add Makefiles for midi2_device and midi2_host examples with
  family guard (skip if FAMILY != rp2040). These examples
  require Pico SDK and board-specific hardware
- Restrict midi2_device CMakeLists.txt to rp2040 family
  (matching midi2_host)
2026-05-12 11:07:44 -03:00
fa9edeff9c fix: address PR review feedback for MIDI 2.0 drivers
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-12 11:07:44 -03:00
d5c5ac586b example: add MIDI 2.0 Host example with display (midi2_host)
Add Host example that receives UMP from a MIDI 2.0 Device via PIO-USB
and displays received messages on a SSD1306 OLED (I2C, 128x64).

Features:
- Boot checklist on display (PWR, TinyUSB, USB bus, Device, Descriptor,
  Alt Setting UMP, Mount, Receiving)
- Decode and display all MIDI 2.0 Channel Voice messages
- PIO-USB Host on rhport 1 (GP12/GP13 for Waveshare RP2350-USB-A)
- SSD1306 display via I2C0 (GP4=SDA, GP5=SCL)

Also add board definition for Waveshare RP2350-USB-A.

Tested: Waveshare RP2350-USB-A (Host) receiving UMP from Raspberry Pi
Pico (Device) via USB cable, notes displayed on SSD1306 OLED
2026-05-12 11:07:44 -03:00
290470bda3 example: add MIDI 2.0 Device example (midi2_device)
Add Device example that plays Twinkle Twinkle Little Star using native
UMP format. Demonstrates all MIDI 2.0 Channel Voice message types:
16-bit velocity, 32-bit CC, 32-bit pitch bend, 32-bit channel/poly
pressure, per-note management, program change with bank select, and
JR timestamps.

USB descriptor exposes both Alt Setting 0 (MIDI 1.0) and Alt Setting 1
(UMP) per USB-MIDI 2.0 specification.

Tested on: Raspberry Pi Pico (RP2040), Linux (ALSA), Windows (MIDI
Services)
2026-05-12 11:07:44 -03:00
77cef83304 test: add MIDI 2.0 Device and Host unit tests
Add unit tests for MIDI 2.0 drivers:
- Device: UMP word count (all 16 message types), descriptor macro
  validation (length, byte layout, alt settings, endpoints),
  CS endpoint subtypes, traversal integrity
- Host: UMP word count, callback struct validation, CS endpoint
  subtypes

Also add Sphinx documentation for MIDI 2.0 class drivers (Device
and Host API reference, lifecycle, configuration, examples).

Tests: 60/60 PASS (FIFO 26/26, USBD 5/5, MIDI2 Device 18/18,
MIDI2 Host 6/6, USBD internal 5/5)
2026-05-12 11:07:44 -03:00
7750e51ce1 feat: add MIDI 2.0 Host class driver (USB-MIDI 2.0)
Add native USB-MIDI 2.0 Host class driver to TinyUSB. Implements
reactive architecture: enumerate, detect MIDI 2.0 capability, inform
application via callbacks.

Driver features:
- Parse both Alt Setting 0 (MIDI 1.0) and Alt Setting 1 (UMP)
- Detect bcdMSC version from descriptor
- Auto-select highest protocol (Alt 1 preferred if available)
- UMP read/write via endpoint streams
- Proper Audio Control interface skip (loop-based, following
  midi_host.c pattern)
- Endpoint open with tuh_edpt_open/tu_edpt_stream_open/clear
- usbh_driver_set_config_complete for USBH state machine
- Handle Audio Control itf_num in set_config gracefully
- 5 weak callback stubs (descriptor, mount, unmount, rx, tx)

Build system:
- Register midih2_* in usbh.c driver table
- Add midi2_host.h include to tusb.h
- Add CFG_TUH_MIDI2_LOG_LEVEL to tusb_option.h

All changes guarded by #if CFG_TUH_MIDI2 (default 0). Zero impact on
existing drivers and examples.

Tested: Waveshare RP2350-USB-A (Host) receiving UMP from Raspberry Pi
Pico (Device) via PIO-USB, board-to-board
2026-05-12 11:07:44 -03:00
bc8ce76ae8 feat: add MIDI 2.0 Device class driver (USB-MIDI 2.0)
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-12 11:07:44 -03:00
4e64f3e91c Merge pull request #3632 from hathach/msc_os
hcd/dwc2: fix txfifo full check
2026-05-11 16:02:50 +02:00
dcd2a4bd0f Merge pull request #3630 from nminaylov/ncm_packet_filter
NCM: support for SetEthernetPacketFilter and SetNTBInputSize request
2026-05-10 00:49:14 +02:00
040ee395d4 reduce NTM size
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-08 18:57:09 +02:00
216d7c43f1 lpc55 works with net_lwip
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-08 18:16:04 +02:00
439e0975e1 fix iperf server is always excluded
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-08 18:15:40 +02:00
de112b06a1 Merge pull request #3633 from hathach/fix/nrf5x-hfclk-wait-post-sd
nrf5x: request HFCLK in USB_EVT_READY to fix post-SoftDevice deadlock
2026-05-08 21:59:40 +07:00
6af4ee2c50 nrf5x: request HFCLK in USB_EVT_READY to fix post-SoftDevice deadlock
USB_EVT_DETECTED runs hfclk_enable() which, when SoftDevice is not yet
enabled, starts HFXO via direct CLOCK register access. After
sd_softdevice_enable() takes over CLOCK, HFXO is physically off again
and SD's HFCLK reference count is 0.

If USB_EVT_READY is fired post-SD (e.g. on nRF52 via Bluefruit's
usb_softdevice_post_enable() when the pre-SD nrfx_power READY callback
didn't get to run before nrfx_power was uninited), the wait loop
'while (!hfclk_running()) {}' calls sd_clock_hfclk_is_running() which
returns false forever -> deadlock that blocks both USB enumeration and
any further app code on the calling thread.

Call hfclk_enable() right before the wait so HFCLK is requested in
whichever context (SD or direct) is current. hfclk_enable() is
idempotent.

Reproduces reliably with bleuart on Feather nRF52840 Express flashed
via JLink: chip wedges in sd_clock_hfclk_is_running SVC, no USB
enumeration, no BLE advertising. With the fix, USB enumerates and BLE
advertises as expected.
2026-05-08 21:27:53 +07:00
2471cbc286 fixup
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-08 13:53:09 +02:00