diff --git a/lib/tinyusb b/lib/tinyusb index 73896a3b71..ea8ecea59a 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 73896a3b71c525a3ee4cefa7e35ce3b3a93786ef +Subproject commit ea8ecea59aa60a1028cce16b0f15bb33918b11af diff --git a/ports/raspberrypi/sdk_config/pico/config_autogen.h b/ports/raspberrypi/sdk_config/pico/config_autogen.h index a29ccb458a..ee99b1c609 100644 --- a/ports/raspberrypi/sdk_config/pico/config_autogen.h +++ b/ports/raspberrypi/sdk_config/pico/config_autogen.h @@ -18,6 +18,8 @@ #define PICO_NO_HARDWARE (0) #define PICO_ON_DEVICE (1) #define PICO_PRINTF_ALWAYS_INCLUDED (1) +#define PICO_RP2040_USB_DEVICE_ENUMERATION_FIX (1) +#define PICO_RP2040_USB_DEVICE_UFRAME_FIX (1) #define PICO_STDIO_IGNORE_NESTED_STDOUT (0) #define PICO_USE_CRT_PRINTF (0) #define PICO_USE_OPTIMISTIC_SBRK (0) diff --git a/ports/raspberrypi/supervisor/usb.c b/ports/raspberrypi/supervisor/usb.c index d0e9b2e466..fb4f72134d 100644 --- a/ports/raspberrypi/supervisor/usb.c +++ b/ports/raspberrypi/supervisor/usb.c @@ -39,15 +39,8 @@ STATIC void _usb_irq_wrapper(void) { } void post_usb_init(void) { - irq_set_enabled(USBCTRL_IRQ, false); - - irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ); - if (usb_handler) { - irq_remove_handler(USBCTRL_IRQ, usb_handler); - } - irq_set_exclusive_handler(USBCTRL_IRQ, _usb_irq_wrapper); - - irq_set_enabled(USBCTRL_IRQ, true); + irq_add_shared_handler(USBCTRL_IRQ, _usb_irq_wrapper, + PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY); // There is a small window where the USB interrupt may be handled by the // pico-sdk instead of CircuitPython. If that is the case, then we'll have diff --git a/ports/stm/Makefile b/ports/stm/Makefile index 325b13b1bc..d6afeb5f29 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -215,7 +215,7 @@ ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0) endif ifneq ($(CIRCUITPY_USB),0) -SRC_C += lib/tinyusb/src/portable/st/synopsys/dcd_synopsys.c +SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c endif SRC_S = \ diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 81431d5d7a..706c94eec3 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -61,12 +61,9 @@ uint16_t common_hal_usb_core_device_get_idProduct(usb_core_device_obj_t *self) { } STATIC xfer_result_t _get_string_result; -STATIC bool _transfer_done_cb(uint8_t daddr, tusb_control_request_t const *request, xfer_result_t result) { - // Store the result so we stop waiting for the transfer. We don't need the other data for now. - (void)daddr; - (void)request; - _get_string_result = result; - return true; +STATIC void _transfer_done_cb(tuh_xfer_t *xfer) { + // Store the result so we stop waiting for the transfer. + _get_string_result = xfer->result; } STATIC void _wait_for_callback(void) { @@ -89,7 +86,7 @@ STATIC mp_obj_t _get_string(const uint16_t *temp_buf) { mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *self) { _get_string_result = 0xff; uint16_t temp_buf[127]; - if (!tuh_descriptor_string_serial_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) { + if (!tuh_descriptor_get_serial_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) { return mp_const_none; } _wait_for_callback(); @@ -99,7 +96,7 @@ mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *sel mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) { _get_string_result = 0xff; uint16_t temp_buf[127]; - if (!tuh_descriptor_string_product_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) { + if (!tuh_descriptor_get_product_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) { return mp_const_none; } _wait_for_callback(); @@ -109,7 +106,7 @@ mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) { mp_obj_t common_hal_usb_core_device_get_manufacturer(usb_core_device_obj_t *self) { _get_string_result = 0xff; uint16_t temp_buf[127]; - if (!tuh_descriptor_string_manufacturer_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) { + if (!tuh_descriptor_get_manufacturer_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) { return mp_const_none; } _wait_for_callback(); @@ -125,11 +122,8 @@ mp_obj_t common_hal_usb_core_device_read(usb_core_device_obj_t *self, mp_int_t e } xfer_result_t control_result; -STATIC bool _control_complete_cb(uint8_t dev_addr, tusb_control_request_t const *request, xfer_result_t result) { - (void)dev_addr; - (void)request; - control_result = result; - return true; +STATIC void _control_complete_cb(tuh_xfer_t *xfer) { + control_result = xfer->result; } mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, @@ -145,11 +139,17 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, .wIndex = wIndex, .wLength = len }; + tuh_xfer_t xfer = { + .daddr = self->device_number, + .ep_addr = 0, + .setup = &request, + .buffer = buffer, + .complete_cb = _control_complete_cb, + }; + control_result = XFER_RESULT_STALLED; - bool result = tuh_control_xfer(self->device_number, - &request, - buffer, - _control_complete_cb); + + bool result = tuh_control_xfer(&xfer); if (!result) { mp_raise_usb_core_USBError(NULL); } diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index fa85cddb83..5ac8454312 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -225,13 +225,17 @@ void usb_background_schedule(void) { } void usb_irq_handler(int instance) { + #if CFG_TUSB_MCU != OPT_MCU_RP2040 + // For rp2040, IRQ handler is already installed and invoked automatically if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) { tud_int_handler(instance); - } else if (instance == CIRCUITPY_USB_HOST_INSTANCE) { - #if CIRCUITPY_USB_HOST - tuh_int_handler(instance); - #endif } + #if CIRCUITPY_USB_HOST + else if (instance == CIRCUITPY_USB_HOST_INSTANCE) { + tuh_int_handler(instance); + } + #endif + #endif usb_background_schedule(); } diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 801025f41a..c461c5353f 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -163,7 +163,6 @@ ifeq ($(CIRCUITPY_USB),1) SRC_SUPERVISOR += \ lib/tinyusb/src/host/hub.c \ lib/tinyusb/src/host/usbh.c \ - lib/tinyusb/src/host/usbh_control.c \ endif endif