summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-08-21 13:56:36 +1000
committerDamien George <damien@micropython.org>2025-09-08 12:30:53 +1000
commitc7c0ad222ee017435ba24eeb82ba90a30dc8ae2b (patch)
treedee2612097513563a4cd0923bdfc56acf10d7b1b
parent123f66b2598e0feb96993fe19d98568517addc3b (diff)
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: https://github.com/alifsemi/tinyusb/commit/fc40ea7fc6e6bd49baad6b504c88bb6a37c7a191 Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/alif/tinyusb_port/tusb_alif_dcd.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ports/alif/tinyusb_port/tusb_alif_dcd.c b/ports/alif/tinyusb_port/tusb_alif_dcd.c
index 9a990cedb..cae0be8d8 100644
--- a/ports/alif/tinyusb_port/tusb_alif_dcd.c
+++ b/ports/alif/tinyusb_port/tusb_alif_dcd.c
@@ -249,7 +249,11 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
{
LOG("%010u >%s", DWT->CYCCNT, __func__);
- udev->dcfg_b.devaddr = dev_addr;
+ // Device address is set from the ISR when SETUP packet is received
+ // By point TinyUSB calls this function, the address has already been
+ // set and STATUS sent back to the host. Xfer call below is purely for
+ // internal TinyUSB state to conclude transaction and issue next SETUP req.
+
dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
}
@@ -571,6 +575,9 @@ static void _dcd_handle_depevt(uint8_t ep, uint8_t evt, uint8_t sts, uint16_t pa
// XferNotReady NotActive for status stage
if ((1 == ep) && (0b0010 == (sts & 0b1011))) {
+ if (0x00 == _ctrl_buf[0] && TUSB_REQ_SET_ADDRESS == _ctrl_buf[1]) {
+ udev->dcfg_b.devaddr = _ctrl_buf[2];
+ }
_dcd_start_xfer(1, NULL, 0, TRBCTL_CTL_STAT2);
break;
}