Skip to content

Commit e336045

Browse files
hathachclaude
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 OPT_MCU_STM32U3 to compile guard to enable host mode on STM32U3 - 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 e336045

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
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/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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "tusb_option.h"
4040

4141
#if CFG_TUH_ENABLED && defined(TUP_USBIP_FSDEV) && \
42-
TU_CHECK_MCU(OPT_MCU_STM32C0, OPT_MCU_STM32G0, OPT_MCU_STM32H5, OPT_MCU_STM32U5)
42+
TU_CHECK_MCU(OPT_MCU_STM32C0, OPT_MCU_STM32G0, OPT_MCU_STM32H5, OPT_MCU_STM32U3, OPT_MCU_STM32U5)
4343

4444
#include "host/hcd.h"
4545
#include "host/usbh.h"
@@ -672,10 +672,8 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
672672
// Clear stall, data toggle is also reset to DATA0
673673
bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {
674674
(void) rhport;
675-
(void) dev_addr;
676-
(void) ep_addr;
677675

678-
uint8_t const ep_id = endpoint_find(dev_addr, 0);
676+
uint8_t const ep_id = endpoint_find(dev_addr, ep_addr);
679677
TU_ASSERT(ep_id != TUSB_INDEX_INVALID_8);
680678

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

0 commit comments

Comments
 (0)