Skip to content

Commit c7c0ad2

Browse files
committed
alif/tinyusb_port: Fix setting of USB device addr for fast hosts.
A fast host (eg Mac M4) may request the status for the SET_ADDRESS before TinyUSB gets to process it. This is because TinyUSB does not handle events inside the USB ISR, rather it waits for the top-level thread to process them. Fix that by setting the USB device address as soon as TUSB_REQ_SET_ADDRESS comes in. This patch follows the corresponding upstream fix: alifsemi/tinyusb@fc40ea7 Signed-off-by: Damien George <[email protected]>
1 parent 123f66b commit c7c0ad2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ports/alif/tinyusb_port/tusb_alif_dcd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
249249
{
250250
LOG("%010u >%s", DWT->CYCCNT, __func__);
251251

252-
udev->dcfg_b.devaddr = dev_addr;
252+
// Device address is set from the ISR when SETUP packet is received
253+
// By point TinyUSB calls this function, the address has already been
254+
// set and STATUS sent back to the host. Xfer call below is purely for
255+
// internal TinyUSB state to conclude transaction and issue next SETUP req.
256+
253257
dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
254258
}
255259

@@ -571,6 +575,9 @@ static void _dcd_handle_depevt(uint8_t ep, uint8_t evt, uint8_t sts, uint16_t pa
571575

572576
// XferNotReady NotActive for status stage
573577
if ((1 == ep) && (0b0010 == (sts & 0b1011))) {
578+
if (0x00 == _ctrl_buf[0] && TUSB_REQ_SET_ADDRESS == _ctrl_buf[1]) {
579+
udev->dcfg_b.devaddr = _ctrl_buf[2];
580+
}
574581
_dcd_start_xfer(1, NULL, 0, TRBCTL_CTL_STAT2);
575582
break;
576583
}

0 commit comments

Comments
 (0)