From ec2101f4aa5a94d3592a9fedd1672ec896d28463 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 13:18:54 -0500 Subject: [PATCH 1/9] update tinyusb to latest --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 73896a3b71..990fb6ae5c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 73896a3b71c525a3ee4cefa7e35ce3b3a93786ef +Subproject commit 990fb6ae5c4d9d4b77c5a9ecb3a2abe899dd2712 From 0f31ba676b187d2d641eabb8cce4a298cea3ae8e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 17:40:53 -0500 Subject: [PATCH 2/9] update errata fixes for RP2040 --- ports/raspberrypi/sdk_config/pico/config_autogen.h | 2 ++ 1 file changed, 2 insertions(+) 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) From 7f10f36dfbe4b5f48371e40e66157236b696f102 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 23:18:58 -0500 Subject: [PATCH 3/9] usbh_control.c no longer exists --- supervisor/supervisor.mk | 1 - 1 file changed, 1 deletion(-) 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 From 5cb21539f295d3537a80bbf4c33266a9feab6642 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 10 Mar 2023 13:12:37 -0500 Subject: [PATCH 4/9] use revised USB host API on mimxrt10xx --- shared-module/usb/core/Device.c | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) 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); } From a651696c5c5bfdb945c06645963f3b56ad0cc9eb Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 10 Mar 2023 23:07:29 -0500 Subject: [PATCH 5/9] pick up latest tinyusb changes --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 990fb6ae5c..be21413361 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 990fb6ae5c4d9d4b77c5a9ecb3a2abe899dd2712 +Subproject commit be214133615684327b114a5f167cd052841c3acf From daa927a114148904f82604f4fb47aca84cb00df2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 12 Mar 2023 14:02:38 -0400 Subject: [PATCH 6/9] switch STM to dwc2 USB --- ports/stm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = \ From b432cf62019d40b103e1cba6fbfecb5813cd61a7 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 13 Mar 2023 21:49:01 +0700 Subject: [PATCH 7/9] fix rp2040 with new shared irq usb handler --- ports/raspberrypi/supervisor/usb.c | 11 ++--------- supervisor/shared/usb/usb.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 13 deletions(-) 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/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(); } From d85970b7a2cfb0aeb4d89575d839c91ce3e6d1ad Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 13 Mar 2023 17:53:32 -0400 Subject: [PATCH 8/9] update TinyUSB again for latest changes --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index be21413361..7cf67b2845 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit be214133615684327b114a5f167cd052841c3acf +Subproject commit 7cf67b28456f6cb8738956bd6af1fd2b8300de4f From 2497b3ea7a67c7371a857deae32ca4a5ed572dff Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 13 Mar 2023 22:11:02 -0400 Subject: [PATCH 9/9] update tinyusb --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 7cf67b2845..ea8ecea59a 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 7cf67b28456f6cb8738956bd6af1fd2b8300de4f +Subproject commit ea8ecea59aa60a1028cce16b0f15bb33918b11af