From 733094aead6e84b42da54655b2b0a5d0dbd1a503 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 20 Jan 2021 16:47:18 -0800 Subject: Add initial RP2040 support The RP2040 is new microcontroller from Raspberry Pi that features two Cortex M0s and eight PIO state machines that are good for crunching lots of data. It has 264k RAM and a built in UF2 bootloader too. Datasheet: https://pico.raspberrypi.org/files/rp2040_datasheet.pdf --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/tinyusb') diff --git a/lib/tinyusb b/lib/tinyusb index cfcffe94c..b68e4e9d7 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit cfcffe94ce62f5ef1fb5aef4641924d64dc4b1c0 +Subproject commit b68e4e9d70ddef442c4d95412414c4221eef59eb -- cgit v1.2.3 From b73b30ff9f890ffd4e38d4c7ce7bcef7c92c1afb Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 21 Jan 2021 11:33:13 -0800 Subject: Switch to upstream TinyUSB --- .gitmodules | 2 +- lib/tinyusb | 2 +- ports/raspberrypi/supervisor/usb.c | 19 +++++++++++++++++-- supervisor/shared/usb/usb.c | 4 ++++ supervisor/shared/workflow.c | 4 +--- supervisor/usb.h | 3 +++ 6 files changed, 27 insertions(+), 7 deletions(-) (limited to 'lib/tinyusb') diff --git a/.gitmodules b/.gitmodules index 66fcf186f..99de2c918 100644 --- a/.gitmodules +++ b/.gitmodules @@ -75,7 +75,7 @@ url = https://github.com/adafruit/nrfx.git [submodule "lib/tinyusb"] path = lib/tinyusb - url = https://github.com/tannewt/tinyusb.git + url = https://github.com/hathach/tinyusb.git branch = master fetchRecurseSubmodules = false [submodule "tools/huffman"] diff --git a/lib/tinyusb b/lib/tinyusb index b68e4e9d7..388abe9d9 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit b68e4e9d70ddef442c4d95412414c4221eef59eb +Subproject commit 388abe9d9cc0a7c360fd902e01461a53bb7b3f42 diff --git a/ports/raspberrypi/supervisor/usb.c b/ports/raspberrypi/supervisor/usb.c index db2c298f5..1d2425aed 100644 --- a/ports/raspberrypi/supervisor/usb.c +++ b/ports/raspberrypi/supervisor/usb.c @@ -27,12 +27,27 @@ #include "lib/tinyusb/src/device/usbd.h" #include "supervisor/background_callback.h" #include "supervisor/usb.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" #include "src/rp2_common/pico_platform/include/pico/platform.h" #include "src/rp2040/hardware_regs/include/hardware/regs/intctrl.h" +static background_callback_t usb_callback; +static void usb_background_do(void* unused) { + usb_background(); +} + +static void queue_background(void) { + background_callback_add(&usb_callback, usb_background_do, NULL); +} + void init_usb_hardware(void) { } -void __isr __used isr_usbctrl(void) { - usb_irq_handler(); +void post_usb_init(void) { + irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ); + if (usb_handler) { + irq_remove_handler(USBCTRL_IRQ, usb_handler); + irq_add_shared_handler(USBCTRL_IRQ, usb_handler, PICO_DEFAULT_IRQ_PRIORITY); + } + irq_add_shared_handler(USBCTRL_IRQ, queue_background, PICO_LOWEST_IRQ_PRIORITY); } diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index ff08ade18..07c6aee6c 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -59,12 +59,16 @@ bool usb_enabled(void) { return tusb_inited(); } +MP_WEAK void post_usb_init(void) {} + void usb_init(void) { init_usb_hardware(); load_serial_number(); tusb_init(); + post_usb_init(); + #if MICROPY_KBD_EXCEPTION // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received // This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here diff --git a/supervisor/shared/workflow.c b/supervisor/shared/workflow.c index 9aac7c4d0..4986c0957 100644 --- a/supervisor/shared/workflow.c +++ b/supervisor/shared/workflow.c @@ -36,9 +36,7 @@ void supervisor_workflow_reset(void) { // Not that some chips don't notice when USB is unplugged after first being plugged in, // so this is not perfect, but tud_suspended() check helps. bool supervisor_workflow_connecting(void) { - return true; - // TODO: Use the below once we've updated TinyUSB for the RP2040. - // return tud_connected() && !tud_suspended(); + return tud_connected() && !tud_suspended(); } // Return true if host has completed connection to us (such as USB enumeration). diff --git a/supervisor/usb.h b/supervisor/usb.h index 0dead3e26..ccb35470c 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -42,6 +42,9 @@ void usb_irq_handler(void); // TinyUSB. void init_usb_hardware(void); +// Temporary hook for code after init. Only used for RP2040. +void post_usb_init(void); + // Shared implementation. bool usb_enabled(void); void usb_init(void); -- cgit v1.2.3