From 1f4d1cff853e177228bd1736886f6cda3fe740d2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 22 Apr 2025 11:38:17 -0700 Subject: [PATCH] Update tinyusb to improve direct USB host These changes improve direct USB host on RP2350 in particular. --- lib/tinyusb | 2 +- ports/raspberrypi/lib/Pico-PIO-USB | 2 +- shared-module/usb/core/Device.c | 33 +++++++++++++++++++----------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 60e6d53d10082..542e5b4550a01 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 60e6d53d10082df884819c3958e621a2e1e0a214 +Subproject commit 542e5b4550a01d034b78308d77c408ed89427513 diff --git a/ports/raspberrypi/lib/Pico-PIO-USB b/ports/raspberrypi/lib/Pico-PIO-USB index 7e1c086ba865a..032a469e79f6a 160000 --- a/ports/raspberrypi/lib/Pico-PIO-USB +++ b/ports/raspberrypi/lib/Pico-PIO-USB @@ -1 +1 @@ -Subproject commit 7e1c086ba865aa5918419193bb19855cd69ffc30 +Subproject commit 032a469e79f6a4ba40760d7868e6db26e15002d7 diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 0a52b925facf1..c9df0cf73805f 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -154,33 +154,42 @@ mp_obj_t common_hal_usb_core_device_get_manufacturer(usb_core_device_obj_t *self mp_int_t common_hal_usb_core_device_get_bus(usb_core_device_obj_t *self) { - hcd_devtree_info_t devtree; - hcd_devtree_get_info(self->device_address, &devtree); - return devtree.rhport; + tuh_bus_info_t bus_info; + if (!tuh_bus_info_get(self->device_address, &bus_info)) { + return 0; + } + return bus_info.rhport; } mp_obj_t common_hal_usb_core_device_get_port_numbers(usb_core_device_obj_t *self) { - hcd_devtree_info_t devtree; - hcd_devtree_get_info(self->device_address, &devtree); - if (devtree.hub_addr == 0) { + tuh_bus_info_t bus_info; + if (!tuh_bus_info_get(self->device_address, &bus_info)) { + return mp_const_none; + } + if (bus_info.hub_addr == 0) { return mp_const_none; } // USB allows for 5 hubs deep chaining. So we're at most 5 ports deep. mp_obj_t ports[5]; size_t port_count = 0; - while (devtree.hub_addr != 0 && port_count < MP_ARRAY_SIZE(ports)) { + tuh_bus_info_t current_bus_info = bus_info; + while (current_bus_info.hub_addr != 0 && port_count < MP_ARRAY_SIZE(ports)) { // Reverse the order of the ports so most downstream comes last. - ports[MP_ARRAY_SIZE(ports) - 1 - port_count] = MP_OBJ_NEW_SMALL_INT(devtree.hub_port); + ports[MP_ARRAY_SIZE(ports) - 1 - port_count] = MP_OBJ_NEW_SMALL_INT(current_bus_info.hub_port); port_count++; - hcd_devtree_get_info(devtree.hub_addr, &devtree); + if (!tuh_bus_info_get(current_bus_info.hub_addr, ¤t_bus_info)) { + break; + } } return mp_obj_new_tuple(port_count, ports + (MP_ARRAY_SIZE(ports) - port_count)); } mp_int_t common_hal_usb_core_device_get_speed(usb_core_device_obj_t *self) { - hcd_devtree_info_t devtree; - hcd_devtree_get_info(self->device_address, &devtree); - switch (devtree.speed) { + tuh_bus_info_t bus_info; + if (!tuh_bus_info_get(self->device_address, &bus_info)) { + return 0; + } + switch (bus_info.speed) { case TUSB_SPEED_HIGH: return PYUSB_SPEED_HIGH; case TUSB_SPEED_FULL: