Fix bugs in FSDEV HCD/DCD and MIDI host stream write#3559
Conversation
Size Difference ReportBecause TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds. Note: If there is no change, only one value is shown. Changes >1% in sizeNo entries. Changes <1% in sizeNo entries. No changes
|
f738d9f to
cd3b98c
Compare
- hcd_edpt_clear_stall: use ep_addr instead of hardcoded 0 (control endpoint) - hcd: add TUP_USBIP_FSDEV_DRD define for MCUs with host support (C0, G0, H5, U3, U5) and use it in hcd compile guard instead of enumerating MCUs - dcd_edpt_close_all: use FSDEV_EP_COUNT instead of CFG_TUD_ENDPPOINT_MAX for PMA btable offset to match handle_bus_reset - midi host tuh_midi_stream_write: add missing cable_num to system messages, SysEx, and real-time MIDI packets. Add 0xF mask for SysEx CIN checks. Aligns with midi_device.c tud_midi_n_stream_write implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cd3b98c to
8819605
Compare
|
There was a problem hiding this comment.
Pull request overview
This PR fixes several correctness issues across the STM32 FSDEV USB host/device drivers and the MIDI host stream writer to improve endpoint handling, PMA allocation consistency, and USB-MIDI packet formatting.
Changes:
- Fix FSDEV HCD stall-clear endpoint lookup and broaden host compile gating to DRD-capable STM32 FSDEV MCUs (including STM32U3).
- Correct FSDEV DCD PMA allocation reset logic to use the hardware endpoint count for BTABLE sizing.
- Fix MIDI host stream write to consistently include the cable number and properly detect SysEx state via CIN masking.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/portable/st/stm32_fsdev/hcd_stm32_fsdev.c |
Fixes hcd_edpt_clear_stall() to clear stalls on the intended endpoint; updates compile guard to TUP_USBIP_FSDEV_DRD. |
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c |
Resets PMA allocation using FSDEV_EP_COUNT to match hardware BTABLE sizing and bus-reset behavior. |
src/common/tusb_mcu.h |
Defines TUP_USBIP_FSDEV_DRD for additional STM32 FSDEV families to enable host builds where supported. |
src/class/midi/midi_host.c |
Updates tuh_midi_stream_write() to include cable number for more message types and masks CIN for SysEx checks. |
Comments suppressed due to low confidence (1)
src/class/midi/midi_host.c:468
streamrtis stack-allocated and onlybuffer[0]/buffer[1]are initialized, but the code writes 4 bytes to the endpoint stream. This can send uninitialized garbage bytes inbuffer[2]/buffer[3](and potentially leak stack data) for real-time MIDI messages. Initialize the whole struct (e.g., zero it) or explicitly set the remaining bytes to 0 before callingtu_edpt_stream_write.
midi_driver_stream_t streamrt;
streamrt.buffer[0] = (uint8_t)((cable_num << 4) | MIDI_CIN_SYSEX_END_1BYTE);
streamrt.buffer[1] = data;
streamrt.index = 2;
streamrt.total = 2;
const uint32_t count = tu_edpt_stream_write(&p_midi->ep_stream.tx, streamrt.buffer, 4);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Summary
OPT_MCU_STM32U3to enable USB host mode on STM32U3 (all infrastructure already in place)FSDEV_EP_COUNTinstead ofCFG_TUD_ENDPPOINT_MAXfor PMA btable offset, matchinghandle_bus_resettuh_midi_stream_write: add missing cable number to system messages, SysEx, and real-time MIDI packets; add& 0xFmask for SysEx CIN checks — aligns with device-sidetud_midi_n_stream_writeTest plan
stm32f072disco(16-bit FSDEV, 1KB PMA) — OKstm32g0b1nucleo(32-bit FSDEV, 2KB PMA) — OKstm32g491nucleo(16-bit FSDEV, 1KB PMA) — OKstm32l476disco(16-bit FSDEV, 1KB PMA) — OKstm32f723disco(DWC2, MIDI host compiled) — OKstm32h743nucleo(DWC2, DMA) — OK🤖 Generated with Claude Code