Skip to content

Commit 8819605

Browse files
hathachclaude
authored andcommitted
fix bugs in fsdev hcd, dcd and midi host stream write
- 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>
1 parent 151a5ad commit 8819605

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/class/midi/midi_host.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ uint32_t tuh_midi_stream_write(uint8_t idx, uint8_t cable_num, uint8_t const *bu
461461
if (data >= MIDI_STATUS_SYSREAL_TIMING_CLOCK) {
462462
// real-time messages need to be sent right away
463463
midi_driver_stream_t streamrt;
464-
streamrt.buffer[0] = MIDI_CIN_SYSEX_END_1BYTE;
464+
streamrt.buffer[0] = (uint8_t)((cable_num << 4) | MIDI_CIN_SYSEX_END_1BYTE);
465465
streamrt.buffer[1] = data;
466466
streamrt.index = 2;
467467
streamrt.total = 2;
@@ -476,9 +476,9 @@ uint32_t tuh_midi_stream_write(uint8_t idx, uint8_t cable_num, uint8_t const *bu
476476
stream->buffer[1] = data;
477477

478478
// Check to see if we're still in a SysEx transmit.
479-
if (stream->buffer[0] == MIDI_CIN_SYSEX_START) {
479+
if ((stream->buffer[0] & 0xF) == MIDI_CIN_SYSEX_START) {
480480
if (data == MIDI_STATUS_SYSEX_END) {
481-
stream->buffer[0] = MIDI_CIN_SYSEX_END_1BYTE;
481+
stream->buffer[0] = (uint8_t)((cable_num << 4) | MIDI_CIN_SYSEX_END_1BYTE);
482482
stream->total = 2;
483483
} else {
484484
stream->total = 4;
@@ -506,6 +506,7 @@ uint32_t tuh_midi_stream_write(uint8_t idx, uint8_t cable_num, uint8_t const *bu
506506
stream->buffer[0] = MIDI_CIN_SYSEX_END_1BYTE;
507507
stream->total = 2;
508508
}
509+
stream->buffer[0] |= (uint8_t)(cable_num << 4);
509510
} else {
510511
// Pack individual bytes if we don't support packing them into words.
511512
stream->buffer[0] = (uint8_t) (cable_num << 4 | 0xf);
@@ -520,8 +521,8 @@ uint32_t tuh_midi_stream_write(uint8_t idx, uint8_t cable_num, uint8_t const *bu
520521
stream->buffer[stream->index] = data;
521522
stream->index++;
522523
// See if this byte ends a SysEx.
523-
if (stream->buffer[0] == MIDI_CIN_SYSEX_START && data == MIDI_STATUS_SYSEX_END) {
524-
stream->buffer[0] = MIDI_CIN_SYSEX_START + (stream->index - 1);
524+
if ((stream->buffer[0] & 0xF) == MIDI_CIN_SYSEX_START && data == MIDI_STATUS_SYSEX_END) {
525+
stream->buffer[0] = (uint8_t)((cable_num << 4) | (MIDI_CIN_SYSEX_START + (stream->index - 1)));
525526
stream->total = stream->index;
526527
}
527528
}

src/common/tusb_mcu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
#elif TU_CHECK_MCU(OPT_MCU_STM32C0)
203203
#define TUP_USBIP_FSDEV
204204
#define TUP_USBIP_FSDEV_STM32
205+
#define TUP_USBIP_FSDEV_DRD
205206
#define CFG_TUSB_FSDEV_PMA_SIZE 2048u
206207

207208
#elif TU_CHECK_MCU(OPT_MCU_STM32F0)
@@ -278,6 +279,7 @@
278279
#elif TU_CHECK_MCU(OPT_MCU_STM32G0)
279280
#define TUP_USBIP_FSDEV
280281
#define TUP_USBIP_FSDEV_STM32
282+
#define TUP_USBIP_FSDEV_DRD
281283
#define CFG_TUSB_FSDEV_PMA_SIZE 2048u
282284

283285
#elif TU_CHECK_MCU(OPT_MCU_STM32G4)
@@ -293,6 +295,7 @@
293295
#elif TU_CHECK_MCU(OPT_MCU_STM32H5)
294296
#define TUP_USBIP_FSDEV
295297
#define TUP_USBIP_FSDEV_STM32
298+
#define TUP_USBIP_FSDEV_DRD
296299
#define CFG_TUSB_FSDEV_PMA_SIZE 2048u
297300

298301
#elif TU_CHECK_MCU(OPT_MCU_STM32H7)
@@ -366,13 +369,15 @@
366369
#elif TU_CHECK_MCU(OPT_MCU_STM32U3)
367370
#define TUP_USBIP_FSDEV
368371
#define TUP_USBIP_FSDEV_STM32
372+
#define TUP_USBIP_FSDEV_DRD
369373
#define CFG_TUSB_FSDEV_PMA_SIZE 2048u
370374

371375
#elif TU_CHECK_MCU(OPT_MCU_STM32U5)
372376
// U535/545 use fsdev
373377
#if defined(STM32U535xx) || defined(STM32U545xx)
374378
#define TUP_USBIP_FSDEV
375379
#define TUP_USBIP_FSDEV_STM32
380+
#define TUP_USBIP_FSDEV_DRD
376381
#define CFG_TUSB_FSDEV_PMA_SIZE 2048u
377382
#else
378383
#define TUP_USBIP_DWC2

src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ void dcd_edpt_close_all(uint8_t rhport) {
612612
dcd_int_enable(rhport);
613613

614614
// Reset PMA allocation
615-
ep_buf_ptr = FSDEV_BTABLE_BASE + 8 * CFG_TUD_ENDPPOINT_MAX + 2 * CFG_TUD_ENDPOINT0_SIZE;
615+
ep_buf_ptr = FSDEV_BTABLE_BASE + 8 * FSDEV_EP_COUNT + 2 * CFG_TUD_ENDPOINT0_SIZE;
616616
}
617617

618618
bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {

src/portable/st/stm32_fsdev/hcd_stm32_fsdev.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838

3939
#include "tusb_option.h"
4040

41-
#if CFG_TUH_ENABLED && defined(TUP_USBIP_FSDEV) && \
42-
TU_CHECK_MCU(OPT_MCU_STM32C0, OPT_MCU_STM32G0, OPT_MCU_STM32H5, OPT_MCU_STM32U5)
41+
#if CFG_TUH_ENABLED && defined(TUP_USBIP_FSDEV) && defined(TUP_USBIP_FSDEV_DRD)
4342

4443
#include "host/hcd.h"
4544
#include "host/usbh.h"
@@ -672,10 +671,8 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
672671
// Clear stall, data toggle is also reset to DATA0
673672
bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {
674673
(void) rhport;
675-
(void) dev_addr;
676-
(void) ep_addr;
677674

678-
uint8_t const ep_id = endpoint_find(dev_addr, 0);
675+
uint8_t const ep_id = endpoint_find(dev_addr, ep_addr);
679676
TU_ASSERT(ep_id != TUSB_INDEX_INVALID_8);
680677

681678
hcd_endpoint_t *edpt = &_hcd_data.edpt[ep_id];

0 commit comments

Comments
 (0)