From 7cfb1cb60faa0481bd77f20112c9f0f01c88bfa4 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 8 Dec 2025 16:19:15 -0800 Subject: [PATCH] Fix USB on P4 EV mpconfigport.h can't set a default to override circuitpy_mpconfig.h So, when using the high speed device we need to set two defines. Also, fix warning from IDF about selecting UTMI with high speed. --- .../boards/espressif_esp32p4_function_ev/mpconfigboard.h | 1 + ports/espressif/mpconfigport.h | 8 -------- ports/espressif/supervisor/usb.c | 4 ++++ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h b/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h index 1bbf3a250fcd2..89a103e619625 100644 --- a/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h +++ b/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h @@ -21,5 +21,6 @@ // Use the second USB device (numbered 0 and 1) #define CIRCUITPY_USB_DEVICE_INSTANCE 1 +#define CIRCUITPY_USB_DEVICE_HIGH_SPEED (1) #define CIRCUITPY_USB_HOST_INSTANCE 0 diff --git a/ports/espressif/mpconfigport.h b/ports/espressif/mpconfigport.h index 6b85100608c65..7f1a581571eb2 100644 --- a/ports/espressif/mpconfigport.h +++ b/ports/espressif/mpconfigport.h @@ -69,14 +69,6 @@ extern portMUX_TYPE background_task_mutex; #define CIRCUITPY_WIFI_DEFAULT_TX_POWER (20) #endif -#ifndef CIRCUITPY_USB_DEVICE_HIGH_SPEED -#if defined(CONFIG_IDF_TARGET_ESP32P4) && CIRCUITPY_USB_DEVICE_INSTANCE == 1 -#define CIRCUITPY_USB_DEVICE_HIGH_SPEED (1) -#else -#define CIRCUITPY_USB_DEVICE_HIGH_SPEED (0) -#endif -#endif - #ifndef CIRCUITPY_ESP32P4_SWAP_LSFS #define CIRCUITPY_ESP32P4_SWAP_LSFS (0) #endif diff --git a/ports/espressif/supervisor/usb.c b/ports/espressif/supervisor/usb.c index 56042fce1b7f5..62feea6981e05 100644 --- a/ports/espressif/supervisor/usb.c +++ b/ports/espressif/supervisor/usb.c @@ -66,7 +66,11 @@ void init_usb_hardware(void) { // Configure USB PHY usb_phy_config_t phy_conf = { .controller = USB_PHY_CTRL_OTG, + #if defined(CONFIG_IDF_TARGET_ESP32P4) && CIRCUITPY_USB_DEVICE_INSTANCE == 1 + .target = USB_PHY_TARGET_UTMI, + #else .target = USB_PHY_TARGET_INT, + #endif .otg_mode = USB_OTG_MODE_DEVICE, #if defined(CONFIG_IDF_TARGET_ESP32P4) && CIRCUITPY_USB_DEVICE_INSTANCE == 0 .otg_speed = USB_PHY_SPEED_FULL,