From fde6263d9ecdba44ca739c670d945788287a2b7c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 25 Apr 2024 15:45:01 -0700 Subject: [PATCH 1/7] Switch to -Os for all 4MB builds Enable MAX3421E support for all ESP builds. Fixes #9203 --- ports/espressif/boards/adafruit_esp32s3_camera/mpconfigboard.mk | 2 -- .../adafruit_feather_esp32s3_reverse_tft/mpconfigboard.mk | 2 -- .../boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk | 1 - .../adafruit_qtpy_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk | 1 - ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk | 2 -- ports/espressif/boards/lolin_s3/mpconfigboard.mk | 1 - ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk | 1 - ports/espressif/boards/lolin_s3_pro/mpconfigboard.mk | 1 - ports/espressif/boards/waveshare_esp32_s3_zero/mpconfigboard.mk | 1 - ports/espressif/mpconfigport.mk | 2 ++ 10 files changed, 2 insertions(+), 12 deletions(-) diff --git a/ports/espressif/boards/adafruit_esp32s3_camera/mpconfigboard.mk b/ports/espressif/boards/adafruit_esp32s3_camera/mpconfigboard.mk index a2901ae7530e..9f8acf042f67 100644 --- a/ports/espressif/boards/adafruit_esp32s3_camera/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_esp32s3_camera/mpconfigboard.mk @@ -26,5 +26,3 @@ CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_PARALLELDISPLAYBUS = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_ROTARYIO = 0 - -OPTIMIZATION_FLAGS = -Os diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/mpconfigboard.mk index 410499c7b381..0aebfea17130 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/mpconfigboard.mk @@ -16,5 +16,3 @@ CIRCUITPY_ESP_PSRAM_FREQ = 80m CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_PARALLELDISPLAYBUS = 0 - -OPTIMIZATION_FLAGS = -Os diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk index 9b8607478b4d..c7d6c33a3fd4 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk @@ -10,7 +10,6 @@ CIRCUITPY_ESP_FLASH_MODE = qio CIRCUITPY_ESP_FLASH_FREQ = 80m CIRCUITPY_ESP_FLASH_SIZE = 4MB -OPTIMIZATION_FLAGS = -Os CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_PARALLELDISPLAYBUS = 0 diff --git a/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk b/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk index 07bd67584b6e..afc6e335c1a4 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk @@ -13,7 +13,6 @@ CIRCUITPY_ESP_PSRAM_SIZE = 2MB CIRCUITPY_ESP_PSRAM_MODE = qio CIRCUITPY_ESP_PSRAM_FREQ = 80m -OPTIMIZATION_FLAGS = -Os CIRCUITPY_ESPCAMERA = 0 # Not enough pins. CIRCUITPY_PARALLELDISPLAYBUS = 0 diff --git a/ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk b/ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk index beb0c37edcd1..448ecf3a0747 100644 --- a/ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk +++ b/ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk @@ -18,5 +18,3 @@ CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_BITMAPFILTER = 0 CIRCUITPY_CODEOP = 0 CIRCUITPY_PARALLELDISPLAYBUS = 0 - -OPTIMIZATION_FLAGS = -Os diff --git a/ports/espressif/boards/lolin_s3/mpconfigboard.mk b/ports/espressif/boards/lolin_s3/mpconfigboard.mk index fce42cef8db5..fbcdece670b4 100644 --- a/ports/espressif/boards/lolin_s3/mpconfigboard.mk +++ b/ports/espressif/boards/lolin_s3/mpconfigboard.mk @@ -13,5 +13,4 @@ CIRCUITPY_ESP_PSRAM_SIZE = 8MB CIRCUITPY_ESP_PSRAM_MODE = opi CIRCUITPY_ESP_PSRAM_FREQ = 80m -OPTIMIZATION_FLAGS = -Os CIRCUITPY_ESPCAMERA = 0 diff --git a/ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk b/ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk index a161a9427b72..f58218d5e6b5 100644 --- a/ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk +++ b/ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk @@ -13,7 +13,6 @@ CIRCUITPY_ESP_PSRAM_SIZE = 2MB CIRCUITPY_ESP_PSRAM_MODE = qio CIRCUITPY_ESP_PSRAM_FREQ = 80m -OPTIMIZATION_FLAGS = -Os CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_BITMAPFILTER = 0 CIRCUITPY_CODEOP = 0 diff --git a/ports/espressif/boards/lolin_s3_pro/mpconfigboard.mk b/ports/espressif/boards/lolin_s3_pro/mpconfigboard.mk index f9e187021a4b..9df3f3580cd7 100755 --- a/ports/espressif/boards/lolin_s3_pro/mpconfigboard.mk +++ b/ports/espressif/boards/lolin_s3_pro/mpconfigboard.mk @@ -13,5 +13,4 @@ CIRCUITPY_ESP_PSRAM_SIZE = 8MB CIRCUITPY_ESP_PSRAM_MODE = opi CIRCUITPY_ESP_PSRAM_FREQ = 80m -OPTIMIZATION_FLAGS = -Os CIRCUITPY_ESPCAMERA = 0 diff --git a/ports/espressif/boards/waveshare_esp32_s3_zero/mpconfigboard.mk b/ports/espressif/boards/waveshare_esp32_s3_zero/mpconfigboard.mk index b3f6284a350d..e1f616dea12f 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_zero/mpconfigboard.mk +++ b/ports/espressif/boards/waveshare_esp32_s3_zero/mpconfigboard.mk @@ -13,7 +13,6 @@ CIRCUITPY_ESP_PSRAM_SIZE = 2MB CIRCUITPY_ESP_PSRAM_MODE = qio CIRCUITPY_ESP_PSRAM_FREQ = 80m -OPTIMIZATION_FLAGS = -Os CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_BITMAPFILTER = 0 CIRCUITPY_CODEOP = 0 diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 7488cc765030..b2fc094294ca 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -34,6 +34,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_FREQUENCYIO ?= 1 CIRCUITPY_HASHLIB ?= 1 CIRCUITPY_I2CTARGET ?= 0 +CIRCUITPY_MAX3421E ?= 1 CIRCUITPY_MEMORYMAP ?= 1 CIRCUITPY_NVM ?= 1 CIRCUITPY_PARALLELDISPLAYBUS ?= 1 @@ -139,6 +140,7 @@ endif # bitmapfilter does not fit on 4MB boards unless they are set up as camera boards ifeq ($(CIRCUITPY_ESP_FLASH_SIZE),4MB) CIRCUITPY_BITMAPFILTER ?= 0 +OPTIMIZATION_FLAGS ?= -Os endif # No room for dualbank on boards with 2MB flash From 0cbd8b2e0c973cda4acc978af935a64344b6dc39 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 26 Apr 2024 11:58:49 -0700 Subject: [PATCH 2/7] Add CIRCUITPY_USB_DEVICE config This replaces CIRCUITPY_USB and makes room for CIRCUITPY_TINYUSB when it may only be included for host support. --- lib/tinyusb | 2 +- main.c | 10 +- .../common-hal/microcontroller/Pin.c | 2 +- ports/espressif/Makefile | 26 ++- .../mpconfigboard.mk | 2 +- .../boards/makerfabs_tft7/mpconfigboard.mk | 2 +- ports/espressif/boards/makerfabs_tft7/pins.c | 2 +- .../sunton_esp32_8048S070/mpconfigboard.mk | 2 +- .../mpconfigboard.mk | 2 +- .../common-hal/microcontroller/Pin.c | 2 +- ports/espressif/mpconfigport.mk | 12 +- ports/espressif/supervisor/usb.c | 44 +++-- ports/nordic/Makefile | 4 +- ports/nordic/bluetooth/ble_drv.c | 2 +- .../espruino_banglejs2/mpconfigboard.mk | 2 +- .../boards/microbit_v2/mpconfigboard.mk | 2 +- ports/nordic/common-hal/_bleio/Adapter.c | 2 +- py/circuitpy_mpconfig.mk | 20 +- shared-bindings/supervisor/Runtime.c | 4 +- shared-module/busdisplay/BusDisplay.c | 2 +- shared-module/epaperdisplay/EPaperDisplay.c | 4 +- .../framebufferio/FramebufferDisplay.c | 2 +- shared-module/storage/__init__.c | 2 +- shared-module/storage/__init__.h | 7 +- supervisor/shared/bluetooth/bluetooth.c | 4 +- supervisor/shared/filesystem.c | 2 +- supervisor/shared/serial.c | 14 +- supervisor/shared/usb/tusb_config.h | 5 +- supervisor/shared/usb/usb.c | 182 +----------------- supervisor/shared/workflow.c | 6 +- supervisor/supervisor.mk | 21 +- supervisor/usb.h | 2 +- 32 files changed, 131 insertions(+), 266 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 5738757e2ca7..ee9ad0f18475 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 5738757e2ca73ab003df5bfbf5ec7b60850ef88b +Subproject commit ee9ad0f184752e4006ccfa6ae49b7ac83707d771 diff --git a/main.c b/main.c index 7ba7a9c09c9c..25f17d79e538 100644 --- a/main.c +++ b/main.c @@ -236,7 +236,7 @@ STATIC void stop_mp(void) { background_callback_reset(); - #if CIRCUITPY_USB + #if CIRCUITPY_TINYUSB usb_background(); #endif @@ -466,7 +466,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { start_mp(safe_mode); - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE usb_setup_with_vm(); #endif @@ -845,7 +845,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { start_mp(safe_mode); - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // Set up default USB values after boot.py VM starts but before running boot.py. usb_set_defaults(); #endif @@ -930,7 +930,7 @@ STATIC int run_repl(safe_mode_t safe_mode) { start_mp(safe_mode); - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE usb_setup_with_vm(); #endif @@ -1078,7 +1078,7 @@ int __attribute__((used)) main(void) { // By default our internal flash is readonly to local python code and // writable over USB. Set it here so that safemode.py or boot.py can change it. filesystem_set_internal_concurrent_write_protection(true); - filesystem_set_internal_writable_by_usb(CIRCUITPY_USB == 1); + filesystem_set_internal_writable_by_usb(CIRCUITPY_USB_DEVICE == 1); #if CIRCUITPY_SAFEMODE_PY // Run safemode.py if we ARE in safe mode. diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.c b/ports/atmel-samd/common-hal/microcontroller/Pin.c index 3cb9df09acaf..51c797e75e9d 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.c +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.c @@ -52,7 +52,7 @@ void reset_all_pins(void) { uint32_t pin_mask[PORT_COUNT] = PORT_OUT_IMPLEMENTED; // Do not full reset USB lines. - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE pin_mask[0] &= ~(PORT_PA24 | PORT_PA25); #endif diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 8490cbd8fa40..9eed90b71af5 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -260,22 +260,34 @@ LIBS += -lm endif # TinyUSB defines -ifeq ($(CIRCUITPY_USB),1) -ifeq ($(IDF_TARGET),esp32s2) +# Always add these because we might be doing host. +ifeq ($(IDF_TARGET),esp32) +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32 +else ifeq ($(IDF_TARGET),esp32c3) +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C3 +else ifeq ($(IDF_TARGET),esp32c6) +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C6 +else ifeq ($(IDF_TARGET),esp32h2) +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32H2 +else ifeq ($(IDF_TARGET),esp32s2) CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S2 else ifeq ($(IDF_TARGET),esp32s3) CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S3 endif +ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_OS=OPT_OS_FREERTOS \ + -DCFG_TUD_TASK_QUEUE_SZ=32 +endif +ifeq ($(CIRCUITPY_USB_DEVICE),1) +CFLAGS += \ -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ -DCFG_TUD_MSC_BUFSIZE=4096 \ -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ -DCFG_TUD_VENDOR_RX_BUFSIZE=128 \ - -DCFG_TUD_VENDOR_TX_BUFSIZE=128 \ - -DCFG_TUD_TASK_QUEUE_SZ=32 + -DCFG_TUD_VENDOR_TX_BUFSIZE=128 endif ###################################### @@ -303,7 +315,7 @@ ifneq ($(CIRCUITPY_TOUCHIO_USE_NATIVE),0) SRC_C += peripherals/touch.c endif -ifneq ($(CIRCUITPY_USB),0) +ifneq ($(CIRCUITPY_USB_DEVICE),0) SRC_C += lib/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c endif @@ -390,7 +402,7 @@ TARGET_SDKCONFIG = esp-idf-config/sdkconfig-$(IDF_TARGET).defaults ifeq ($(CIRCUITPY_ESP_FLASH_SIZE), 2MB) FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE)-no-ota-no-uf2.defaults else -UF2_BOOTLOADER ?= $(CIRCUITPY_USB) +UF2_BOOTLOADER ?= $(CIRCUITPY_USB_DEVICE) ifeq ($(UF2_BOOTLOADER), 1) FLASH_SIZE_SDKCONFIG ?= esp-idf-config/sdkconfig-flash-$(CIRCUITPY_ESP_FLASH_SIZE).defaults else @@ -503,7 +515,7 @@ endif ifneq ($(CIRCUITPY_PARALLELDISPLAYBUS),0) ESP_IDF_COMPONENTS_LINK += esp_lcd endif -ifneq ($(CIRCUITPY_USB),0) +ifneq ($(CIRCUITPY_USB_DEVICE),0) ESP_IDF_COMPONENTS_LINK += usb endif diff --git a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk index 7c330ce8afce..633cca09823d 100644 --- a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk +++ b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/mpconfigboard.mk @@ -13,7 +13,7 @@ IDF_TARGET = esp32s3 # This board doesn't have USB by default, it # instead uses a CP2102 USB-to-Serial chip -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 CIRCUITPY_ESP_FLASH_MODE = qio diff --git a/ports/espressif/boards/makerfabs_tft7/mpconfigboard.mk b/ports/espressif/boards/makerfabs_tft7/mpconfigboard.mk index 4def1e9ab00b..1797cafbce45 100644 --- a/ports/espressif/boards/makerfabs_tft7/mpconfigboard.mk +++ b/ports/espressif/boards/makerfabs_tft7/mpconfigboard.mk @@ -18,7 +18,7 @@ CIRCUITPY_DOTCLOCKFRAMEBUFFER = 1 # To build with USB disabled allowing access to I2S pins #CIRCUITPY_CREATOR_ID = 0x1A000000 #CIRCUITPY_CREATION_ID = 0x005381BF -#CIRCUITPY_USB=0 +#CIRCUITPY_USB_DEVICE=0 #CIRCUITPY_BUILD_EXTENSIONS = bin,uf2 #UF2_BOOTLOADER = 1 #CIRCUITPY_WIFI=1 diff --git a/ports/espressif/boards/makerfabs_tft7/pins.c b/ports/espressif/boards/makerfabs_tft7/pins.c index 1931e6b3ea70..d952d27d8bd2 100644 --- a/ports/espressif/boards/makerfabs_tft7/pins.c +++ b/ports/espressif/boards/makerfabs_tft7/pins.c @@ -99,7 +99,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_GPIO19), MP_ROM_PTR(&pin_GPIO19) }, // I2S pins are shared with USB D+/D-, these are only useful if USB is disabled - #if CIRCUITPY_USB == 0 + #if CIRCUITPY_USB_DEVICE == 0 { MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO20) }, { MP_ROM_QSTR(MP_QSTR_I2S_WORD_SELECT), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO19) }, diff --git a/ports/espressif/boards/sunton_esp32_8048S070/mpconfigboard.mk b/ports/espressif/boards/sunton_esp32_8048S070/mpconfigboard.mk index a136e7f898a7..45bf0116d860 100644 --- a/ports/espressif/boards/sunton_esp32_8048S070/mpconfigboard.mk +++ b/ports/espressif/boards/sunton_esp32_8048S070/mpconfigboard.mk @@ -3,7 +3,7 @@ CIRCUITPY_CREATION_ID = 0x00AA0004 # This board doesn't have USB by default, it # instead uses a CH340C USB-to-Serial chip -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 IDF_TARGET = esp32s3 diff --git a/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/mpconfigboard.mk b/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/mpconfigboard.mk index 18113bd89dda..a8ac3b5d2455 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/mpconfigboard.mk +++ b/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/mpconfigboard.mk @@ -3,7 +3,7 @@ CIRCUITPY_CREATION_ID = 0x00AB0001 # This board doesn't have USB by default, it # instead uses a CH340C USB-to-Serial chip -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 IDF_TARGET = esp32s3 diff --git a/ports/espressif/common-hal/microcontroller/Pin.c b/ports/espressif/common-hal/microcontroller/Pin.c index a14c41ef16de..fd6ec720601b 100644 --- a/ports/espressif/common-hal/microcontroller/Pin.c +++ b/ports/espressif/common-hal/microcontroller/Pin.c @@ -176,7 +176,7 @@ static const uint64_t pin_mask_reset_forbidden = #endif // ESP32H2 #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // Never ever reset USB pins. GPIO_SEL_19 | // USB D- GPIO_SEL_20 | // USB D+ diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index b2fc094294ca..1b67a8db5830 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -52,7 +52,7 @@ ifeq ($(IDF_TARGET),esp32) CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_BLEIO = 0 # Features -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 else ifeq ($(IDF_TARGET),esp32c3) # Modules @@ -73,7 +73,7 @@ CIRCUITPY_ROTARYIO = 0 CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 else ifeq ($(IDF_TARGET),esp32c6) @@ -94,7 +94,7 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0 CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 else ifeq ($(IDF_TARGET),esp32h2) @@ -113,10 +113,12 @@ CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 CIRCUITPY_HASHLIB_MBEDTLS_ONLY = 0 # Features -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 CIRCUITPY_WIFI = 0 +CIRCUITPY_MAX3421E = 0 + else ifeq ($(IDF_TARGET),esp32s2) # Modules # No BLE in hw @@ -156,7 +158,7 @@ CIRCUITPY_JPEGIO ?= $(CIRCUITPY_DISPLAYIO) CIRCUITPY_QRIO ?= $(CIRCUITPY_ESPCAMERA) # Features dependent on other features -ifneq ($(CIRCUITPY_USB),0) +ifneq ($(CIRCUITPY_USB_DEVICE),0) CIRCUITPY_BUILD_EXTENSIONS ?= bin,uf2 else CIRCUITPY_BUILD_EXTENSIONS ?= bin diff --git a/ports/espressif/supervisor/usb.c b/ports/espressif/supervisor/usb.c index 0f4f7579424a..a7eb0e454178 100644 --- a/ports/espressif/supervisor/usb.c +++ b/ports/espressif/supervisor/usb.c @@ -53,6 +53,7 @@ #include "tusb.h" +#if CIRCUITPY_USB_DEVICE #ifdef CFG_TUSB_DEBUG #define USBD_STACK_SIZE (3 * configMINIMAL_STACK_SIZE) #else @@ -80,26 +81,6 @@ STATIC void usb_device_task(void *param) { } } -void init_usb_hardware(void) { - // Configure USB PHY - usb_phy_config_t phy_conf = { - .controller = USB_PHY_CTRL_OTG, - .otg_mode = USB_OTG_MODE_DEVICE, - }; - usb_new_phy(&phy_conf, &phy_hdl); - - // Pin the USB task to the same core as CircuitPython. This way we leave - // the other core for networking. - (void)xTaskCreateStaticPinnedToCore(usb_device_task, - "usbd", - USBD_STACK_SIZE, - NULL, - 5, - usb_device_stack, - &usb_device_taskdef, - xPortGetCoreID()); -} - /** * Callback invoked when received an "wanted" char. * @param itf Interface index (for multiple cdc interfaces) @@ -124,3 +105,26 @@ void tud_cdc_rx_cb(uint8_t itf) { // Wake main task when any key is pressed. port_wake_main_task(); } +#endif // CIRCUITPY_USB_DEVICE + +void init_usb_hardware(void) { + #if CIRCUITPY_USB_DEVICE + // Configure USB PHY + usb_phy_config_t phy_conf = { + .controller = USB_PHY_CTRL_OTG, + .otg_mode = USB_OTG_MODE_DEVICE, + }; + usb_new_phy(&phy_conf, &phy_hdl); + + // Pin the USB task to the same core as CircuitPython. This way we leave + // the other core for networking. + (void)xTaskCreateStaticPinnedToCore(usb_device_task, + "usbd", + USBD_STACK_SIZE, + NULL, + 5, + usb_device_stack, + &usb_device_taskdef, + xPortGetCoreID()); + #endif +} diff --git a/ports/nordic/Makefile b/ports/nordic/Makefile index 655d00b733a3..ff7743796645 100755 --- a/ports/nordic/Makefile +++ b/ports/nordic/Makefile @@ -149,7 +149,7 @@ SRC_PERIPHERALS := \ $(patsubst %.c,$(BUILD)/%.o,$(SRC_PERIPHERALS)): CFLAGS += -Wno-missing-prototypes SRC_C += $(SRC_PERIPHERALS) -ifneq ($(CIRCUITPY_USB),0) +ifneq ($(CIRCUITPY_USB_DEVICE),0) # USB source files for nrf52840 ifeq ($(MCU_SUB_VARIANT),nrf52840) SRC_DCD = \ @@ -162,7 +162,7 @@ SRC_DCD += \ endif SRC_C += $(SRC_DCD) $(patsubst %.c,$(BUILD)/%.o,$(SRC_DCD)): CFLAGS += -Wno-missing-prototypes -endif # CIRCUITPY_USB +endif # CIRCUITPY_USB_DEVICE SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ diff --git a/ports/nordic/bluetooth/ble_drv.c b/ports/nordic/bluetooth/ble_drv.c index 2a92cffe9ce1..ae8711ce8917 100644 --- a/ports/nordic/bluetooth/ble_drv.c +++ b/ports/nordic/bluetooth/ble_drv.c @@ -121,7 +121,7 @@ void SD_EVT_IRQHandler(void) { uint32_t evt_id; while (sd_evt_get(&evt_id) != NRF_ERROR_NOT_FOUND) { switch (evt_id) { - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // usb power event case NRF_EVT_POWER_USB_DETECTED: case NRF_EVT_POWER_USB_POWER_READY: diff --git a/ports/nordic/boards/espruino_banglejs2/mpconfigboard.mk b/ports/nordic/boards/espruino_banglejs2/mpconfigboard.mk index 106b85cd7589..d400b6116609 100644 --- a/ports/nordic/boards/espruino_banglejs2/mpconfigboard.mk +++ b/ports/nordic/boards/espruino_banglejs2/mpconfigboard.mk @@ -20,6 +20,6 @@ CIRCUITPY_RAINBOWIO = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_SYNTHIO = 0 -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_BUILD_EXTENSIONS = espruino.zip diff --git a/ports/nordic/boards/microbit_v2/mpconfigboard.mk b/ports/nordic/boards/microbit_v2/mpconfigboard.mk index d0430ea40336..7586d5d9fb50 100644 --- a/ports/nordic/boards/microbit_v2/mpconfigboard.mk +++ b/ports/nordic/boards/microbit_v2/mpconfigboard.mk @@ -8,4 +8,4 @@ CIRCUITPY_BUILD_EXTENSIONS = combined.hex INTERNAL_FLASH_FILESYSTEM = 1 # USB pins aren't used. -CIRCUITPY_USB = 0 +CIRCUITPY_USB_DEVICE = 0 diff --git a/ports/nordic/common-hal/_bleio/Adapter.c b/ports/nordic/common-hal/_bleio/Adapter.c index be3ffb763e70..fd750352d295 100644 --- a/ports/nordic/common-hal/_bleio/Adapter.c +++ b/ports/nordic/common-hal/_bleio/Adapter.c @@ -381,7 +381,7 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable err_code = sd_softdevice_disable(); } - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // Re-init USB hardware init_usb_hardware(); #endif diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 5879c4ab5cc9..711b14caf3fa 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -551,8 +551,8 @@ CFLAGS += -DCIRCUITPY_TRACEBACK=$(CIRCUITPY_TRACEBACK) CIRCUITPY_UHEAP ?= 0 CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP) -CIRCUITPY_USB ?= 1 -CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB) +CIRCUITPY_USB_DEVICE ?= 1 +CFLAGS += -DCIRCUITPY_USB_DEVICE=$(CIRCUITPY_USB_DEVICE) # Compute these value once, so the shell command is not reinvoked many times. USB_NUM_ENDPOINT_PAIRS_5_OR_GREATER := $(shell expr $(USB_NUM_ENDPOINT_PAIRS) '>=' 5) @@ -567,7 +567,7 @@ CFLAGS += -DUSB_NUM_IN_ENDPOINTS=$(USB_NUM_IN_ENDPOINTS) USB_NUM_OUT_ENDPOINTS ?= $(USB_NUM_ENDPOINT_PAIRS) CFLAGS += -DUSB_NUM_OUT_ENDPOINTS=$(USB_NUM_OUT_ENDPOINTS) -CIRCUITPY_USB_CDC ?= $(CIRCUITPY_USB) +CIRCUITPY_USB_CDC ?= $(CIRCUITPY_USB_DEVICE) CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT ?= 1 CFLAGS += -DCIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT) @@ -575,7 +575,7 @@ CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT ?= 0 CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT) # HID is available by default, but is not turned on if there are fewer than 5 endpoints. -CIRCUITPY_USB_HID ?= $(CIRCUITPY_USB) +CIRCUITPY_USB_HID ?= $(CIRCUITPY_USB_DEVICE) CFLAGS += -DCIRCUITPY_USB_HID=$(CIRCUITPY_USB_HID) CIRCUITPY_USB_HID_ENABLED_DEFAULT ?= $(USB_NUM_ENDPOINT_PAIRS_5_OR_GREATER) CFLAGS += -DCIRCUITPY_USB_HID_ENABLED_DEFAULT=$(CIRCUITPY_USB_HID_ENABLED_DEFAULT) @@ -589,19 +589,23 @@ CFLAGS += -DCIRCUITPY_USB_HOST=$(CIRCUITPY_USB_HOST) CIRCUITPY_PYUSB ?= $(call enable-if-any,$(CIRCUITPY_USB_HOST) $(CIRCUITPY_MAX3421E)) CFLAGS += -DCIRCUITPY_PYUSB=$(CIRCUITPY_PYUSB) -CIRCUITPY_USB_IDENTIFICATION ?= $(CIRCUITPY_USB) +CIRCUITPY_USB_IDENTIFICATION ?= $(CIRCUITPY_USB_DEVICE) CFLAGS += -DCIRCUITPY_USB_IDENTIFICATION=$(CIRCUITPY_USB_IDENTIFICATION) -CIRCUITPY_USB_KEYBOARD_WORKFLOW ?= $(call enable-if-any,$(CIRCUITPY_USB_HOST) $(CIRCUITPY_MAX3421E)) +CIRCUITPY_TINYUSB_HOST ?= $(call enable-if-any,$(CIRCUITPY_USB_HOST) $(CIRCUITPY_MAX3421E)) +CIRCUITPY_USB_KEYBOARD_WORKFLOW ?= $(CIRCUITPY_TINYUSB_HOST) CFLAGS += -DCIRCUITPY_USB_KEYBOARD_WORKFLOW=$(CIRCUITPY_USB_KEYBOARD_WORKFLOW) +CIRCUITPY_TINYUSB ?= $(call enable-if-any,$(CIRCUITPY_TINYUSB_HOST) $(CIRCUITPY_USB_DEVICE)) +CFLAGS += -DCIRCUITPY_TINYUSB=$(CIRCUITPY_TINYUSB) + # MIDI is available by default, but is not turned on if there are fewer than 8 endpoints. -CIRCUITPY_USB_MIDI ?= $(CIRCUITPY_USB) +CIRCUITPY_USB_MIDI ?= $(CIRCUITPY_USB_DEVICE) CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI) CIRCUITPY_USB_MIDI_ENABLED_DEFAULT ?= $(USB_NUM_ENDPOINT_PAIRS_8_OR_GREATER) CFLAGS += -DCIRCUITPY_USB_MIDI_ENABLED_DEFAULT=$(CIRCUITPY_USB_MIDI_ENABLED_DEFAULT) -CIRCUITPY_USB_MSC ?= $(CIRCUITPY_USB) +CIRCUITPY_USB_MSC ?= $(CIRCUITPY_USB_DEVICE) CFLAGS += -DCIRCUITPY_USB_MSC=$(CIRCUITPY_USB_MSC) CIRCUITPY_USB_MSC_ENABLED_DEFAULT ?= $(CIRCUITPY_USB_MSC) CFLAGS += -DCIRCUITPY_USB_MSC_ENABLED_DEFAULT=$(CIRCUITPY_USB_MSC_ENABLED_DEFAULT) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 591eddd29a21..2a9d16f7f71e 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -40,7 +40,7 @@ #include "supervisor/shared/status_leds.h" #include "supervisor/shared/bluetooth/bluetooth.h" -#if (CIRCUITPY_USB) +#if CIRCUITPY_TINYUSB #include "tusb.h" #endif @@ -66,7 +66,7 @@ STATIC supervisor_run_reason_t _run_reason; //| usb_connected: bool //| """Returns the USB enumeration status (read-only).""" STATIC mp_obj_t supervisor_runtime_get_usb_connected(mp_obj_t self) { - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE return mp_obj_new_bool(tud_ready()); #else return mp_const_false; diff --git a/shared-module/busdisplay/BusDisplay.c b/shared-module/busdisplay/BusDisplay.c index c20efe7d68a6..ef76613f1731 100644 --- a/shared-module/busdisplay/BusDisplay.c +++ b/shared-module/busdisplay/BusDisplay.c @@ -315,7 +315,7 @@ STATIC bool _refresh_area(busdisplay_busdisplay_obj_t *self, const displayio_are // TODO(tannewt): Make refresh displays faster so we don't starve other // background tasks. - #if CIRCUITPY_USB + #if CIRCUITPY_TINYUSB usb_background(); #endif } diff --git a/shared-module/epaperdisplay/EPaperDisplay.c b/shared-module/epaperdisplay/EPaperDisplay.c index 9823f209d13f..96ad6e2d2ebd 100644 --- a/shared-module/epaperdisplay/EPaperDisplay.c +++ b/shared-module/epaperdisplay/EPaperDisplay.c @@ -372,7 +372,7 @@ STATIC bool epaperdisplay_epaperdisplay_refresh_area(epaperdisplay_epaperdisplay // TODO(tannewt): Make refresh displays faster so we don't starve other // background tasks. - #if CIRCUITPY_USB + #if CIRCUITPY_TINYUSB usb_background(); #endif } @@ -403,7 +403,7 @@ STATIC bool _clean_area(epaperdisplay_epaperdisplay_obj_t *self) { // TODO(tannewt): Make refresh displays faster so we don't starve other // background tasks. - #if CIRCUITPY_USB + #if CIRCUITPY_TINYUSB usb_background(); #endif } diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c index 7a5fdaa9115a..a217dc809b6d 100644 --- a/shared-module/framebufferio/FramebufferDisplay.c +++ b/shared-module/framebufferio/FramebufferDisplay.c @@ -220,7 +220,7 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t *self, const di // TODO(tannewt): Make refresh displays faster so we don't starve other // background tasks. - #if CIRCUITPY_USB + #if CIRCUITPY_TINYUSB usb_background(); #endif } diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index f3afca34a18c..31180571c45d 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -273,7 +273,7 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa } void common_hal_storage_erase_filesystem(bool extended) { - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE usb_disconnect(); #endif mp_hal_delay_ms(1000); diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index a07e2c2e0e72..d95ea851cfe5 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -24,17 +24,14 @@ * THE SOFTWARE. */ -#ifndef SHARED_MODULE_STORAGE___INIT___H -#define SHARED_MODULE_STORAGE___INIT___H +#pragma once #include "py/mpconfig.h" #include "supervisor/usb.h" -#if CIRCUITPY_USB +#if CIRCUITPY_USB_DEVICE bool storage_usb_enabled(void); void storage_usb_set_defaults(void); size_t storage_usb_descriptor_length(void); size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string); #endif - -#endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/supervisor/shared/bluetooth/bluetooth.c b/supervisor/shared/bluetooth/bluetooth.c index 1cdd6c68fac9..d61d1d9c6708 100644 --- a/supervisor/shared/bluetooth/bluetooth.c +++ b/supervisor/shared/bluetooth/bluetooth.c @@ -142,7 +142,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) { return; } bool bonded = common_hal_bleio_adapter_is_bonded_to_central(&common_hal_bleio_adapter_obj); - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // Don't advertise when we have USB instead of BLE. if (!bonded && !boot_in_discovery_mode) { return; @@ -236,7 +236,7 @@ void supervisor_bluetooth_init(void) { boot_in_discovery_mode = true; reset_state = 0x0; } - #if !CIRCUITPY_USB + #if !CIRCUITPY_USB_DEVICE // Boot into discovery if USB isn't available and we aren't bonded already. // Checking here allows us to have the status LED solidly on even if no button was // pressed. diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c index 7161859edb3e..63555203ddd5 100644 --- a/supervisor/shared/filesystem.c +++ b/supervisor/shared/filesystem.c @@ -126,7 +126,7 @@ bool filesystem_init(bool create_allowed, bool force_create) { return false; } - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // inhibit file indexing on MacOS res = f_mkdir(&vfs_fat->fatfs, "/.fseventsd"); if (res != FR_OK) { diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index bf231167c37f..5b0a62090bac 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -42,7 +42,7 @@ #include "supervisor/shared/bluetooth/serial.h" #endif -#if CIRCUITPY_USB +#if CIRCUITPY_TINYUSB #include "tusb.h" #endif @@ -63,7 +63,7 @@ byte console_uart_rx_buf[64]; #endif #endif -#if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART +#if CIRCUITPY_USB_DEVICE || CIRCUITPY_CONSOLE_UART // Flag to note whether this is the first write after connection. // Delay slightly on the first write to allow time for the host to set up things, // including turning off echo mode. @@ -176,7 +176,7 @@ void serial_early_init(void) { } void serial_init(void) { - #if CIRCUITPY_USB || CIRCUITPY_CONSOLE_UART + #if CIRCUITPY_USB_DEVICE || CIRCUITPY_CONSOLE_UART _first_write_done = false; #endif @@ -205,7 +205,7 @@ bool serial_connected(void) { if (usb_cdc_console_enabled() && tud_cdc_connected()) { return true; } - #elif CIRCUITPY_USB + #elif CIRCUITPY_USB_DEVICE if (tud_cdc_connected()) { return true; } @@ -287,7 +287,7 @@ char serial_read(void) { return -1; } #endif - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE return (char)tud_cdc_read_char(); #endif @@ -326,7 +326,7 @@ uint32_t serial_bytes_available(void) { } #endif - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE count += tud_cdc_available(); #endif @@ -384,7 +384,7 @@ void serial_write_substring(const char *text, uint32_t length) { } #endif - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // Delay the very first write if (tud_cdc_connected() && !_first_write_done) { mp_hal_delay_ms(50); diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 5857f7d157bc..ce4ebdf780a5 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -67,6 +67,9 @@ extern "C" { // DEVICE CONFIGURATION // --------------------------------------------------------------------+ +#if CIRCUITPY_USB_DEVICE +#define CFG_TUD_ENABLED 1 + #if CIRCUITPY_USB_DEVICE_INSTANCE == 0 #if USB_HIGHSPEED #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) @@ -107,7 +110,7 @@ extern "C" { // Product revision string included in Inquiry response, max 4 bytes #define CFG_TUD_MSC_PRODUCT_REV "1.0" - +#endif // --------------------------------------------------------------------+ // USB RAM PLACEMENT diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 19a2a09921e5..4905e2857029 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -25,15 +25,9 @@ */ #include "py/objstr.h" -#include "py/runtime.h" -#include "shared-bindings/microcontroller/Processor.h" -#include "shared-bindings/supervisor/__init__.h" #include "supervisor/background_callback.h" -#include "supervisor/port.h" +#include "supervisor/linker.h" #include "supervisor/usb.h" -#include "supervisor/shared/serial.h" -#include "supervisor/shared/workflow.h" -#include "shared/runtime/interrupt_char.h" #include "shared/readline/readline.h" #if CIRCUITPY_STATUS_BAR @@ -44,6 +38,10 @@ #include "shared-module/storage/__init__.h" #endif +#if CIRCUITPY_USB_DEVICE +#include "shared-bindings/supervisor/__init__.h" +#endif + #if CIRCUITPY_USB_CDC #include "shared-module/usb_cdc/__init__.h" #endif @@ -56,33 +54,12 @@ #include "shared-module/usb_midi/__init__.h" #endif - #if CIRCUITPY_USB_VIDEO #include "shared-module/usb_video/__init__.h" #endif #include "tusb.h" -#if CIRCUITPY_USB_VENDOR -#include "usb_vendor_descriptors.h" - -// The WebUSB support being conditionally added to this file is based on the -// tinyusb demo examples/device/webusb_serial. - -static bool web_serial_connected = false; - -#define URL "www.tinyusb.org/examples/webusb-serial" - -const tusb_desc_webusb_url_t desc_webusb_url = -{ - .bLength = 3 + sizeof(URL) - 1, - .bDescriptorType = 3, // WEBUSB URL type - .bScheme = 1, // 0: http, 1: https - .url = URL -}; - -#endif - bool usb_enabled(void) { return tusb_inited(); } @@ -91,7 +68,7 @@ MP_WEAK void post_usb_init(void) { } void usb_init(void) { - + #if CIRCUITPY_USB_DEVICE usb_identification_t defaults; usb_identification_t *identification; if (custom_usb_identification != NULL) { @@ -115,6 +92,7 @@ void usb_init(void) { // Only init device. Host gets inited by the `usb_host` module common-hal. tud_init(TUD_OPT_RHPORT); + #endif post_usb_init(); @@ -160,10 +138,6 @@ void usb_setup_with_vm(void) { #endif } -void usb_disconnect(void) { - tud_disconnect(); -} - void usb_background(void) { if (usb_enabled()) { #if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO @@ -200,12 +174,14 @@ void PLACE_IN_ITCM(usb_background_schedule)(void) { void PLACE_IN_ITCM(usb_irq_handler)(int instance) { #if CFG_TUSB_MCU != OPT_MCU_RP2040 + #if CIRCUITPY_USB_DEVICE // For rp2040, IRQ handler is already installed and invoked automatically if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) { tud_int_handler(instance); } + #endif #if CIRCUITPY_USB_HOST - else if (instance == CIRCUITPY_USB_HOST_INSTANCE) { + if (instance == CIRCUITPY_USB_HOST_INSTANCE) { tuh_int_handler(instance); } #endif @@ -213,141 +189,3 @@ void PLACE_IN_ITCM(usb_irq_handler)(int instance) { usb_background_schedule(); } - -// --------------------------------------------------------------------+ -// tinyusb callbacks -// --------------------------------------------------------------------+ - -// Invoked when device is mounted -void tud_mount_cb(void) { - #if CIRCUITPY_USB_MSC - usb_msc_mount(); - #endif -} - -// Invoked when device is unmounted -void tud_umount_cb(void) { - #if CIRCUITPY_USB_MSC - usb_msc_umount(); - #endif -} - -// Invoked when usb bus is suspended -// remote_wakeup_en : if host allows us to perform remote wakeup -// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus -void tud_suspend_cb(bool remote_wakeup_en) { -} - -// Invoked when usb bus is resumed -void tud_resume_cb(void) { -} - -// Invoked when cdc when line state changed e.g connected/disconnected -// Use to reset to DFU when disconnect with 1200 bps -void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { - (void)itf; // interface ID, not used - - // DTR = false is counted as disconnected - if (!dtr) { - cdc_line_coding_t coding; - // Use whichever CDC is itf 0. - tud_cdc_get_line_coding(&coding); - - if (coding.bit_rate == 1200) { - reset_to_bootloader(); - } - } else { - #if CIRCUITPY_STATUS_BAR - // We are connected, let's request a title bar update. - supervisor_status_bar_request_update(true); - #endif - } -} - -#if CIRCUITPY_USB_VENDOR -// --------------------------------------------------------------------+ -// WebUSB use vendor class -// --------------------------------------------------------------------+ - -bool tud_vendor_connected(void) { - return web_serial_connected; -} - -// Invoked when a control transfer occurred on an interface of this class -// Driver response accordingly to the request and the transfer stage (setup/data/ack) -// return false to stall control endpoint (e.g unsupported request) -bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { - // nothing to with DATA & ACK stage - if (stage != CONTROL_STAGE_SETUP) { - return true; - } - - switch (request->bRequest) - { - case VENDOR_REQUEST_WEBUSB: - // match vendor request in BOS descriptor - // Get landing page url - return tud_control_xfer(rhport, request, (void *)&desc_webusb_url, desc_webusb_url.bLength); - - case VENDOR_REQUEST_MICROSOFT: - if (request->wIndex == 7) { - // Get Microsoft OS 2.0 compatible descriptor - // let's just hope the target architecture always has the same endianness - uint16_t total_len; - memcpy(&total_len, vendor_ms_os_20_descriptor() + 8, 2); - - return tud_control_xfer(rhport, request, (void *)vendor_ms_os_20_descriptor(), total_len); - } else { - return false; - } - - case 0x22: - // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to - // connect and disconnect. - web_serial_connected = (request->wValue != 0); - - // response with status OK - return tud_control_status(rhport, request); - - default: - // stall unknown request - return false; - } - - return true; -} -#endif // CIRCUITPY_USB_VENDOR - - -#if MICROPY_KBD_EXCEPTION && CIRCUITPY_USB_CDC - -// The CDC RX buffer impacts monitoring for ctrl-c. TinyUSB will only ask for -// more from CDC if the free space in the buffer is greater than the endpoint -// size. Setting CFG_TUD_CDC_RX_BUFSIZE to the endpoint size and then sending -// any character will prevent ctrl-c from working. Require at least a 64 -// character buffer. -#if CFG_TUD_CDC_RX_BUFSIZE < CFG_TUD_CDC_EP_BUFSIZE + 64 -#error "CFG_TUD_CDC_RX_BUFSIZE must be 64 bytes bigger than endpoint size." -#endif - -/** - * Callback invoked when received an "wanted" char. - * @param itf Interface index (for multiple cdc interfaces) - * @param wanted_char The wanted char (set previously) - */ -void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { - // Workaround for using shared/runtime/interrupt_char.c - // Compare mp_interrupt_char with wanted_char and ignore if not matched - if (mp_interrupt_char == wanted_char) { - tud_cdc_n_read_flush(itf); // flush read fifo - mp_sched_keyboard_interrupt(); - } -} - -void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) { - if (usb_cdc_console_enabled() && mp_interrupt_char != -1 && itf == 0 && duration_ms > 0) { - mp_sched_keyboard_interrupt(); - } -} - -#endif diff --git a/supervisor/shared/workflow.c b/supervisor/shared/workflow.c index a328c2aceca0..0ebaca2865a3 100644 --- a/supervisor/shared/workflow.c +++ b/supervisor/shared/workflow.c @@ -40,7 +40,7 @@ #include "supervisor/shared/bluetooth/bluetooth.h" #endif -#if CIRCUITPY_USB +#if CIRCUITPY_TINYUSB || CIRCUITPY_USB_KEYBOARD_WORKFLOW #include "supervisor/usb.h" #include "tusb.h" #endif @@ -81,7 +81,7 @@ void supervisor_workflow_request_background(void) { // Return true if host has completed connection to us (such as USB enumeration). bool supervisor_workflow_active(void) { - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE // Eventually there might be other non-USB workflows, such as BLE. // tud_ready() checks for usb mounted and not suspended. return tud_ready(); @@ -92,7 +92,7 @@ bool supervisor_workflow_active(void) { void supervisor_workflow_start(void) { // Start USB after giving boot.py a chance to tweak behavior. - #if CIRCUITPY_USB + #if CIRCUITPY_TINYUSB // Setup USB connection after heap is available. // It needs the heap to build descriptors. usb_init(); diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 5848a7ed2b38..8911ef65f7d7 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -27,7 +27,7 @@ CFLAGS += -D_DEBUG=0 NO_USB ?= $(wildcard supervisor/usb.c) -ifeq ($(CIRCUITPY_USB),1) +ifeq ($(CIRCUITPY_USB_DEVICE),1) CIRCUITPY_CREATOR_ID ?= $(USB_VID) CIRCUITPY_CREATION_ID ?= $(USB_PID) endif @@ -109,19 +109,25 @@ ifeq ($(CIRCUITPY_STATUS_BAR),1) endif -ifeq ($(CIRCUITPY_USB),1) +ifeq ($(CIRCUITPY_TINYUSB),1) SRC_SUPERVISOR += \ - lib/tinyusb/src/class/cdc/cdc_device.c \ lib/tinyusb/src/common/tusb_fifo.c \ - lib/tinyusb/src/device/usbd.c \ - lib/tinyusb/src/device/usbd_control.c \ lib/tinyusb/src/tusb.c \ supervisor/usb.c \ - supervisor/shared/usb/usb_desc.c \ supervisor/shared/usb/usb.c \ + ifeq ($(CIRCUITPY_USB_DEVICE),1) + SRC_SUPERVISOR += \ + lib/tinyusb/src/device/usbd.c \ + lib/tinyusb/src/device/usbd_control.c \ + supervisor/shared/usb/usb_desc.c \ + supervisor/shared/usb/usb_device.c \ + + endif + ifeq ($(CIRCUITPY_USB_CDC), 1) SRC_SUPERVISOR += \ + lib/tinyusb/src/class/cdc/cdc_device.c \ shared-bindings/usb_cdc/__init__.c \ shared-bindings/usb_cdc/Serial.c \ shared-module/usb_cdc/__init__.c \ @@ -176,8 +182,7 @@ ifeq ($(CIRCUITPY_USB),1) endif - # This is a string comparison! - ifneq ($(CIRCUITPY_USB_HOST)$(CIRCUITPY_MAX3421E), 00) + ifeq ($(CIRCUITPY_TINYUSB_HOST), 1) SRC_SUPERVISOR += \ lib/tinyusb/src/host/hub.c \ lib/tinyusb/src/host/usbh.c \ diff --git a/supervisor/usb.h b/supervisor/usb.h index fd4d275cb0b3..8bf10fe7b268 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -80,7 +80,7 @@ void usb_setup_with_vm(void); // Propagate plug/unplug events to the MSC logic. -#if CIRCUITPY_USB_MSC +#if CIRCUITPY_USB_DEVICE && CIRCUITPY_USB_MSC void usb_msc_mount(void); void usb_msc_umount(void); bool usb_msc_ejected(void); From 8f5c6920a9d4fc6128dfae1b23609f05295ca265 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 26 Apr 2024 13:24:19 -0700 Subject: [PATCH 3/7] Fix CI USB PID check --- ports/litex/supervisor/internal_flash.c | 4 ++-- tools/ci_check_duplicate_usb_vid_pid.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ports/litex/supervisor/internal_flash.c b/ports/litex/supervisor/internal_flash.c index 3b2b5957dc66..c90b615d4d23 100644 --- a/ports/litex/supervisor/internal_flash.c +++ b/ports/litex/supervisor/internal_flash.c @@ -310,7 +310,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n uint32_t src = lba2addr(block); memcpy(dest, (uint8_t *)src, FILESYSTEM_BLOCK_SIZE * num_blocks); - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE usb_background(); #endif @@ -347,7 +347,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 src += count * FILESYSTEM_BLOCK_SIZE; num_blocks -= count; - #if CIRCUITPY_USB + #if CIRCUITPY_USB_DEVICE usb_background(); #endif } diff --git a/tools/ci_check_duplicate_usb_vid_pid.py b/tools/ci_check_duplicate_usb_vid_pid.py index b8170aa9e385..4fb48955b0e3 100644 --- a/tools/ci_check_duplicate_usb_vid_pid.py +++ b/tools/ci_check_duplicate_usb_vid_pid.py @@ -96,7 +96,8 @@ def check_vid_pid(files, clusterlist): """ usb_pattern = re.compile( - r"^CIRCUITPY_USB\s*=\s*0$|^IDF_TARGET = (esp32|esp32c3|esp32c6|esp32h2)$", flags=re.M + r"^CIRCUITPY_USB_DEVICE\s*=\s*0$|^IDF_TARGET = (esp32|esp32c3|esp32c6|esp32h2)$", + flags=re.M, ) usb_ids = defaultdict(set) From 0da83a9d374cc1dc7e6d11730a63d7720b18b066 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 26 Apr 2024 13:35:02 -0700 Subject: [PATCH 4/7] Fix silabs --- ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk | 1 - ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk | 1 - .../sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk | 1 - ports/silabs/mpconfigport.mk | 1 + tools/ci_check_duplicate_usb_vid_pid.py | 2 +- 5 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk index 58c6d15ba68a..58652a8c09b3 100644 --- a/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk +++ b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk @@ -8,7 +8,6 @@ EXTERNAL_FLASH_DEVICES = MX25R3235F MCU_SERIES = MG24 MCU_VARIANT = EFR32MG24B310F1536IM48 -CIRCUITPY_USB = 0 CIRCUITPY_SDCARDIO = 1 CIRCUITPY_CREATOR_ID = 0x19960000 diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk index 849f11ffeb17..a7add6e4f0ad 100644 --- a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk @@ -6,7 +6,6 @@ SPI_FLASH_FILESYSTEM = 0 MCU_SERIES = MG24 MCU_VARIANT = EFR32MG24B210F1536IM48 -CIRCUITPY_USB = 0 CIRCUITPY_SDCARDIO = 1 CIRCUITPY_CREATOR_ID = 0x19960000 diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk index dcfc337031c8..3a477f9e8dfd 100644 --- a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk @@ -7,7 +7,6 @@ SPI_FLASH_FILESYSTEM = 0 MCU_SERIES = MG24 MCU_VARIANT = MGM240PB32VNA -CIRCUITPY_USB = 0 CIRCUITPY_SDCARDIO = 1 CIRCUITPY_CREATOR_ID = 0x19960000 diff --git a/ports/silabs/mpconfigport.mk b/ports/silabs/mpconfigport.mk index 9fe7f042d323..7c00338955f1 100644 --- a/ports/silabs/mpconfigport.mk +++ b/ports/silabs/mpconfigport.mk @@ -12,6 +12,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_NVM ?= 1 CIRCUITPY_PWMIO ?= 1 CIRCUITPY_RTC ?= 1 +CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_WATCHDOG ?=1 ifeq ($(MCU_SERIES),MG24) diff --git a/tools/ci_check_duplicate_usb_vid_pid.py b/tools/ci_check_duplicate_usb_vid_pid.py index 4fb48955b0e3..1b432b98704a 100644 --- a/tools/ci_check_duplicate_usb_vid_pid.py +++ b/tools/ci_check_duplicate_usb_vid_pid.py @@ -96,7 +96,7 @@ def check_vid_pid(files, clusterlist): """ usb_pattern = re.compile( - r"^CIRCUITPY_USB_DEVICE\s*=\s*0$|^IDF_TARGET = (esp32|esp32c3|esp32c6|esp32h2)$", + r"^CIRCUITPY_USB_DEVICE\s*=\s*0$|^IDF_TARGET = (esp32|esp32c3|esp32c6|esp32h2)$|^MCU_SERIES = MG24$", flags=re.M, ) From 40f6d531b3723d15ab2036c6fdcf3e11dd5a19bc Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 26 Apr 2024 14:27:16 -0700 Subject: [PATCH 5/7] Add missing file --- supervisor/shared/usb/usb_device.c | 203 +++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 supervisor/shared/usb/usb_device.c diff --git a/supervisor/shared/usb/usb_device.c b/supervisor/shared/usb/usb_device.c new file mode 100644 index 000000000000..cee97a0d3a19 --- /dev/null +++ b/supervisor/shared/usb/usb_device.c @@ -0,0 +1,203 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 hathach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" +#include "supervisor/port.h" +#include "supervisor/usb.h" +#include "shared/runtime/interrupt_char.h" + +#if CIRCUITPY_STATUS_BAR +#include "supervisor/shared/status_bar.h" +#endif + +#if CIRCUITPY_USB_CDC +#include "shared-module/usb_cdc/__init__.h" +#include "lib/tinyusb/src/class/cdc/cdc_device.h" +#endif + +#if CIRCUITPY_USB_VIDEO +#include "shared-module/usb_video/__init__.h" +#endif + +#include "tusb.h" + +#if CIRCUITPY_USB_VENDOR +#include "usb_vendor_descriptors.h" + +// The WebUSB support being conditionally added to this file is based on the +// tinyusb demo examples/device/webusb_serial. + +static bool web_serial_connected = false; + +#define URL "www.tinyusb.org/examples/webusb-serial" + +const tusb_desc_webusb_url_t desc_webusb_url = +{ + .bLength = 3 + sizeof(URL) - 1, + .bDescriptorType = 3, // WEBUSB URL type + .bScheme = 1, // 0: http, 1: https + .url = URL +}; + +#endif + +void usb_disconnect(void) { + tud_disconnect(); +} + +// Invoked when device is mounted +void tud_mount_cb(void) { + #if CIRCUITPY_USB_MSC + usb_msc_mount(); + #endif +} + +// Invoked when device is unmounted +void tud_umount_cb(void) { + #if CIRCUITPY_USB_MSC + usb_msc_umount(); + #endif +} + +// Invoked when usb bus is suspended +// remote_wakeup_en : if host allows us to perform remote wakeup +// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus +void tud_suspend_cb(bool remote_wakeup_en) { +} + +// Invoked when usb bus is resumed +void tud_resume_cb(void) { +} + +// Invoked when cdc when line state changed e.g connected/disconnected +// Use to reset to DFU when disconnect with 1200 bps +void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { + (void)itf; // interface ID, not used + + // DTR = false is counted as disconnected + if (!dtr) { + cdc_line_coding_t coding; + // Use whichever CDC is itf 0. + tud_cdc_get_line_coding(&coding); + + if (coding.bit_rate == 1200) { + reset_to_bootloader(); + } + } else { + #if CIRCUITPY_STATUS_BAR + // We are connected, let's request a title bar update. + supervisor_status_bar_request_update(true); + #endif + } +} + +#if CIRCUITPY_USB_VENDOR +// --------------------------------------------------------------------+ +// WebUSB use vendor class +// --------------------------------------------------------------------+ + +bool tud_vendor_connected(void) { + return web_serial_connected; +} + +// Invoked when a control transfer occurred on an interface of this class +// Driver response accordingly to the request and the transfer stage (setup/data/ack) +// return false to stall control endpoint (e.g unsupported request) +bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { + // nothing to with DATA & ACK stage + if (stage != CONTROL_STAGE_SETUP) { + return true; + } + + switch (request->bRequest) + { + case VENDOR_REQUEST_WEBUSB: + // match vendor request in BOS descriptor + // Get landing page url + return tud_control_xfer(rhport, request, (void *)&desc_webusb_url, desc_webusb_url.bLength); + + case VENDOR_REQUEST_MICROSOFT: + if (request->wIndex == 7) { + // Get Microsoft OS 2.0 compatible descriptor + // let's just hope the target architecture always has the same endianness + uint16_t total_len; + memcpy(&total_len, vendor_ms_os_20_descriptor() + 8, 2); + + return tud_control_xfer(rhport, request, (void *)vendor_ms_os_20_descriptor(), total_len); + } else { + return false; + } + + case 0x22: + // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to + // connect and disconnect. + web_serial_connected = (request->wValue != 0); + + // response with status OK + return tud_control_status(rhport, request); + + default: + // stall unknown request + return false; + } + + return true; +} +#endif // CIRCUITPY_USB_VENDOR + + +#if MICROPY_KBD_EXCEPTION && CIRCUITPY_USB_CDC + +// The CDC RX buffer impacts monitoring for ctrl-c. TinyUSB will only ask for +// more from CDC if the free space in the buffer is greater than the endpoint +// size. Setting CFG_TUD_CDC_RX_BUFSIZE to the endpoint size and then sending +// any character will prevent ctrl-c from working. Require at least a 64 +// character buffer. +#if CFG_TUD_CDC_RX_BUFSIZE < CFG_TUD_CDC_EP_BUFSIZE + 64 +#error "CFG_TUD_CDC_RX_BUFSIZE must be 64 bytes bigger than endpoint size." +#endif + +/** + * Callback invoked when received an "wanted" char. + * @param itf Interface index (for multiple cdc interfaces) + * @param wanted_char The wanted char (set previously) + */ +void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { + // Workaround for using shared/runtime/interrupt_char.c + // Compare mp_interrupt_char with wanted_char and ignore if not matched + if (mp_interrupt_char == wanted_char) { + tud_cdc_n_read_flush(itf); // flush read fifo + mp_sched_keyboard_interrupt(); + } +} + +void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) { + if (usb_cdc_console_enabled() && mp_interrupt_char != -1 && itf == 0 && duration_ms > 0) { + mp_sched_keyboard_interrupt(); + } +} + +#endif From d4a46ba1536cb889cd5158243e7a069c346382c5 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 26 Apr 2024 15:36:46 -0700 Subject: [PATCH 6/7] Always define CFG_TUD_ENABLED --- supervisor/shared/usb/tusb_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index ce4ebdf780a5..bebeee4b53a1 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -67,8 +67,9 @@ extern "C" { // DEVICE CONFIGURATION // --------------------------------------------------------------------+ +#define CFG_TUD_ENABLED CIRCUITPY_USB_DEVICE + #if CIRCUITPY_USB_DEVICE -#define CFG_TUD_ENABLED 1 #if CIRCUITPY_USB_DEVICE_INSTANCE == 0 #if USB_HIGHSPEED From 5fa40ccc22ce3e20aa543a7f60704079e4144187 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 26 Apr 2024 15:59:51 -0700 Subject: [PATCH 7/7] Fix cyw43 and build with usb_cdc --- ports/raspberrypi/cyw43_configport.h | 2 +- supervisor/supervisor.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/cyw43_configport.h b/ports/raspberrypi/cyw43_configport.h index b76480482134..f6f6626fec0c 100644 --- a/ports/raspberrypi/cyw43_configport.h +++ b/ports/raspberrypi/cyw43_configport.h @@ -37,7 +37,7 @@ #define CYW43_NETUTILS (1) -#if CIRCUITPY_USB +#if CIRCUITPY_USB_DEVICE #include "supervisor/usb.h" #define CYW43_EVENT_POLL_HOOK usb_background(); #else diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 8911ef65f7d7..50ce3f4c1816 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -118,6 +118,7 @@ ifeq ($(CIRCUITPY_TINYUSB),1) ifeq ($(CIRCUITPY_USB_DEVICE),1) SRC_SUPERVISOR += \ + lib/tinyusb/src/class/cdc/cdc_device.c \ lib/tinyusb/src/device/usbd.c \ lib/tinyusb/src/device/usbd_control.c \ supervisor/shared/usb/usb_desc.c \ @@ -127,7 +128,6 @@ ifeq ($(CIRCUITPY_TINYUSB),1) ifeq ($(CIRCUITPY_USB_CDC), 1) SRC_SUPERVISOR += \ - lib/tinyusb/src/class/cdc/cdc_device.c \ shared-bindings/usb_cdc/__init__.c \ shared-bindings/usb_cdc/Serial.c \ shared-module/usb_cdc/__init__.c \