From e6f1f7871380950657947a64f6ba0ae724258dc0 Mon Sep 17 00:00:00 2001 From: Vincent1-python Date: Fri, 15 Aug 2025 17:26:05 +0800 Subject: [PATCH] esp32: Add support for ESP32-P4. This commit adds support for ESP32-P4 SoCs. Signed-off-by: Vincent1-python Signed-off-by: Angus Gratton Signed-off-by: Damien George --- ports/esp32/README.md | 2 +- ports/esp32/boards/make-pins.py | 4 +- ports/esp32/boards/sdkconfig.p4 | 15 +++ ports/esp32/boards/sdkconfig.p4_wifi_c5 | 2 + ports/esp32/boards/sdkconfig.p4_wifi_c6 | 2 + ports/esp32/boards/sdkconfig.p4_wifi_common | 59 ++++++++++++ ports/esp32/esp32_common.cmake | 3 +- ports/esp32/lockfiles/dependencies.lock.esp32 | 2 +- .../esp32/lockfiles/dependencies.lock.esp32c2 | 2 +- .../esp32/lockfiles/dependencies.lock.esp32c3 | 2 +- .../esp32/lockfiles/dependencies.lock.esp32c5 | 2 +- .../esp32/lockfiles/dependencies.lock.esp32c6 | 2 +- .../esp32/lockfiles/dependencies.lock.esp32p4 | 93 +++++++++++++++++++ .../esp32/lockfiles/dependencies.lock.esp32s2 | 2 +- .../esp32/lockfiles/dependencies.lock.esp32s3 | 2 +- ports/esp32/machine_adc.c | 15 +++ ports/esp32/machine_hw_spi.c | 4 + ports/esp32/machine_pin.c | 2 + ports/esp32/machine_pin.h | 60 ++++++++++++ ports/esp32/machine_timer.c | 3 + ports/esp32/machine_touchpad.c | 67 ++++++++++++- ports/esp32/machine_uart.c | 8 ++ ports/esp32/main.c | 3 +- ports/esp32/main/idf_component.yml | 11 ++- ports/esp32/modesp32.c | 4 +- ports/esp32/modmachine.c | 9 ++ ports/esp32/mpconfigport.h | 21 ++++- ports/esp32/network_lan.c | 10 +- ports/esp32/uart.c | 4 + ports/esp32/usb.c | 7 +- shared/tinyusb/tusb_config.h | 2 +- 31 files changed, 393 insertions(+), 31 deletions(-) create mode 100644 ports/esp32/boards/sdkconfig.p4 create mode 100644 ports/esp32/boards/sdkconfig.p4_wifi_c5 create mode 100644 ports/esp32/boards/sdkconfig.p4_wifi_c6 create mode 100644 ports/esp32/boards/sdkconfig.p4_wifi_common create mode 100644 ports/esp32/lockfiles/dependencies.lock.esp32p4 diff --git a/ports/esp32/README.md b/ports/esp32/README.md index 55964febea..b5cd1c2a8c 100644 --- a/ports/esp32/README.md +++ b/ports/esp32/README.md @@ -6,7 +6,7 @@ microcontrollers. It uses the ESP-IDF framework and MicroPython runs as a task under FreeRTOS. Currently supports ESP32, ESP32-C2 (aka ESP8684), ESP32-C3, ESP32-C5, ESP32-C6, -ESP32-S2 and ESP32-S3. ESP8266 is supported by a separate MicroPython port. +ESP32-P4, ESP32-S2 and ESP32-S3. ESP8266 is supported by a separate MicroPython port. Supported features include: - REPL (Python prompt) over UART0 and/or the integrated USB peripheral. diff --git a/ports/esp32/boards/make-pins.py b/ports/esp32/boards/make-pins.py index 49b10f0ce1..c7375e67d6 100755 --- a/ports/esp32/boards/make-pins.py +++ b/ports/esp32/boards/make-pins.py @@ -7,8 +7,8 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../tools")) import boardgen -# Pins start at zero, and the highest pin index on any ESP32* chip is 48. -NUM_GPIOS = 49 +# Pins start at zero, and the highest pin index on any ESP32* chip is 54. +NUM_GPIOS = 55 class Esp32Pin(boardgen.Pin): diff --git a/ports/esp32/boards/sdkconfig.p4 b/ports/esp32/boards/sdkconfig.p4 new file mode 100644 index 0000000000..3ec0ff7057 --- /dev/null +++ b/ports/esp32/boards/sdkconfig.p4 @@ -0,0 +1,15 @@ +# Flash +CONFIG_FLASHMODE_QIO=y +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y + +# Memory +CONFIG_SPIRAM=y +CONFIG_SPIRAM_MEMTEST= +CONFIG_SPIRAM_IGNORE_NOTFOUND=y +CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y +CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=50768 + +# ULP: not fixed +CONFIG_SOC_ULP_SUPPORTED=n +CONFIG_ULP_COPROC_ENABLED=n +CONFIG_ULP_COPROC_TYPE_FSM=n diff --git a/ports/esp32/boards/sdkconfig.p4_wifi_c5 b/ports/esp32/boards/sdkconfig.p4_wifi_c5 new file mode 100644 index 0000000000..bee529f9b1 --- /dev/null +++ b/ports/esp32/boards/sdkconfig.p4_wifi_c5 @@ -0,0 +1,2 @@ +# Most settings are in sdkconfig.p4_wifi_common +CONFIG_SLAVE_IDF_TARGET_ESP32C5=y diff --git a/ports/esp32/boards/sdkconfig.p4_wifi_c6 b/ports/esp32/boards/sdkconfig.p4_wifi_c6 new file mode 100644 index 0000000000..4a80725c53 --- /dev/null +++ b/ports/esp32/boards/sdkconfig.p4_wifi_c6 @@ -0,0 +1,2 @@ +# Most settings are in sdkconfig.p4_wifi_common +CONFIG_SLAVE_IDF_TARGET_ESP32C6=y diff --git a/ports/esp32/boards/sdkconfig.p4_wifi_common b/ports/esp32/boards/sdkconfig.p4_wifi_common new file mode 100644 index 0000000000..b7bd0bffa0 --- /dev/null +++ b/ports/esp32/boards/sdkconfig.p4_wifi_common @@ -0,0 +1,59 @@ +# This sdkconfig file has the common settings for an ESP32-P4 +# host with an external ESP-Hosted Wi-Fi/BT interface. + +# Wifi +CONFIG_ESP_HOSTED_ENABLED=y +CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16 +CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=64 +CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64 +CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y +CONFIG_ESP_WIFI_TX_BA_WIN=32 +CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y +CONFIG_ESP_WIFI_RX_BA_WIN=32 + +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534 +CONFIG_LWIP_TCP_WND_DEFAULT=65534 +CONFIG_LWIP_TCP_RECVMBOX_SIZE=64 +CONFIG_LWIP_UDP_RECVMBOX_SIZE=64 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64 + +CONFIG_LWIP_TCP_SACK_OUT=y + +# Bluetooth Support +CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID=y +CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y +CONFIG_ESP_HOSTED_NIMBLE_HCI_VHCI=y +CONFIG_ESP_WIFI_REMOTE_ENABLED=y +CONFIG_SLAVE_SOC_WIFI_SUPPORTED=y +CONFIG_SLAVE_SOC_WIFI_WAPI_SUPPORT=y +CONFIG_SLAVE_SOC_WIFI_CSI_SUPPORT=y +CONFIG_SLAVE_SOC_WIFI_MESH_SUPPORT=y +CONFIG_SLAVE_SOC_WIFI_LIGHT_SLEEP_CLK_WIDTH=12 +CONFIG_SLAVE_SOC_WIFI_HW_TSF=y +CONFIG_SLAVE_SOC_WIFI_FTM_SUPPORT=y +CONFIG_SLAVE_FREERTOS_UNICORE=y +CONFIG_SLAVE_SOC_WIFI_GCMP_SUPPORT=y +CONFIG_SLAVE_IDF_TARGET_ARCH_RISCV=y +CONFIG_SLAVE_SOC_WIFI_HE_SUPPORT=y +CONFIG_SLAVE_SOC_WIFI_MAC_VERSION_NUM=2 +CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED=y + +CONFIG_ESP_HOSTED_P4_DEV_BOARD_FUNC_BOARD=y + +# BLE +CONFIG_ESP_ENABLE_BT=y +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_CONTROLLER_DISABLED=y +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_TRANSPORT_UART=n +CONFIG_BT_NIMBLE_LOG_LEVEL_ERROR=y + +CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME="MPY ESP32" +CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4 + +CONFIG_BT_HCI_LOG_DEBUG_EN=y + +# Increase NimBLE task stack size from the default, because Python code +# (BLE IRQ handlers) will most likely run on this task. +CONFIG_BT_NIMBLE_TASK_STACK_SIZE=6144 diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake index 807d712830..a52498a7fe 100644 --- a/ports/esp32/esp32_common.cmake +++ b/ports/esp32/esp32_common.cmake @@ -23,7 +23,7 @@ if(CONFIG_IDF_TARGET_ARCH_RISCV) endif() if(NOT DEFINED MICROPY_PY_TINYUSB) - if(CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3) + if(CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3 OR CONFIG_IDF_TARGET_ESP32P4) set(MICROPY_PY_TINYUSB ON) endif() endif() @@ -167,6 +167,7 @@ list(APPEND IDF_COMPONENTS esp_adc esp_app_format esp_common + esp_driver_touch_sens esp_eth esp_event esp_hw_support diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32 b/ports/esp32/lockfiles/dependencies.lock.esp32 index 4b0b2d9729..3f3a416671 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32 @@ -30,6 +30,6 @@ direct_dependencies: - espressif/lan867x - espressif/mdns - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32 version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32c2 b/ports/esp32/lockfiles/dependencies.lock.esp32c2 index 5c5cea0c9a..9530e74e97 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32c2 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32c2 @@ -16,6 +16,6 @@ dependencies: direct_dependencies: - espressif/mdns - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32c2 version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32c3 b/ports/esp32/lockfiles/dependencies.lock.esp32c3 index 4c4c869c27..5edbe537d8 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32c3 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32c3 @@ -16,6 +16,6 @@ dependencies: direct_dependencies: - espressif/mdns - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32c3 version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32c5 b/ports/esp32/lockfiles/dependencies.lock.esp32c5 index 6f24d01347..3b52c82b14 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32c5 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32c5 @@ -16,6 +16,6 @@ dependencies: direct_dependencies: - espressif/mdns - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32c5 version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32c6 b/ports/esp32/lockfiles/dependencies.lock.esp32c6 index b7435e1076..1c84d5bfd5 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32c6 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32c6 @@ -16,6 +16,6 @@ dependencies: direct_dependencies: - espressif/mdns - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32c6 version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32p4 b/ports/esp32/lockfiles/dependencies.lock.esp32p4 new file mode 100644 index 0000000000..8923760482 --- /dev/null +++ b/ports/esp32/lockfiles/dependencies.lock.esp32p4 @@ -0,0 +1,93 @@ +dependencies: + espressif/eppp_link: + component_hash: 41f6519edda527ec6a0553c872ebaf8fc6d3812523c9d4c8d1660ad21c720abe + dependencies: + - name: espressif/esp_serial_slave_link + registry_url: https://components.espressif.com + require: private + version: ^1.1.0 + - name: idf + require: private + version: '>=5.2' + source: + registry_url: https://components.espressif.com + type: service + version: 1.1.3 + espressif/esp_hosted: + component_hash: f32400eec7f35652052ae79ecb301148d4011769e94eb8d47262fb22fce933d2 + dependencies: + - name: idf + require: private + version: '>=5.3' + source: + registry_url: https://components.espressif.com/ + type: service + version: 2.2.4 + espressif/esp_serial_slave_link: + component_hash: ac1776806de0a6e371c84e87898bb983e19ce62aa7f1e2e5c4a3b0234a575d2c + dependencies: + - name: idf + require: private + version: '>=5.0' + source: + registry_url: https://components.espressif.com + type: service + version: 1.1.2 + espressif/esp_wifi_remote: + component_hash: 4ed1ebe454d63ddb4a91bbd8db74a6f883c85a863db1f79770c57fbd2e5c134c + dependencies: + - name: espressif/eppp_link + registry_url: https://components.espressif.com + require: private + version: '>=0.1' + - name: espressif/esp_hosted + registry_url: https://components.espressif.com + require: private + rules: + - if: target in [esp32h2, esp32p4] + version: '>=0.0.6' + - name: idf + require: private + version: '>=5.3' + source: + registry_url: https://components.espressif.com/ + type: service + version: 0.15.2 + espressif/mdns: + component_hash: 46ee81d32fbf850462d8af1e83303389602f6a6a9eddd2a55104cb4c063858ed + dependencies: + - name: idf + require: private + version: '>=5.0' + source: + registry_url: https://components.espressif.com/ + type: service + version: 1.1.0 + espressif/tinyusb: + component_hash: ee1c962cff61eb975d508258d509974d58031cc27ff0d6c4117a67a613a49594 + dependencies: + - name: idf + version: '>=5.0' + source: + git: https://github.com/micropython/tinyusb-espressif.git + path: . + type: git + targets: + - esp32s2 + - esp32s3 + - esp32p4 + - esp32h4 + version: e4c0ec3caab3d9c25374de7047653b9ced8f14ff + idf: + source: + type: idf + version: 5.5.1 +direct_dependencies: +- espressif/esp_hosted +- espressif/esp_wifi_remote +- espressif/mdns +- espressif/tinyusb +- idf +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 +target: esp32p4 +version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32s2 b/ports/esp32/lockfiles/dependencies.lock.esp32s2 index a13d9fd401..a7bb041539 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32s2 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32s2 @@ -32,6 +32,6 @@ direct_dependencies: - espressif/mdns - espressif/tinyusb - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32s2 version: 2.0.0 diff --git a/ports/esp32/lockfiles/dependencies.lock.esp32s3 b/ports/esp32/lockfiles/dependencies.lock.esp32s3 index d5e7045b77..9a8b179f72 100644 --- a/ports/esp32/lockfiles/dependencies.lock.esp32s3 +++ b/ports/esp32/lockfiles/dependencies.lock.esp32s3 @@ -32,6 +32,6 @@ direct_dependencies: - espressif/mdns - espressif/tinyusb - idf -manifest_hash: da32add5eb5e196ac97a99eb579025222ec572f5db4038873fbf9d3b9d6ed5a3 +manifest_hash: cc42b6ea8bc1d77d04370604f0b1c1a93a4f2c9b9200690722458faedaee68a4 target: esp32s3 version: 2.0.0 diff --git a/ports/esp32/machine_adc.c b/ports/esp32/machine_adc.c index 432df3d3a2..ff80762ebd 100644 --- a/ports/esp32/machine_adc.c +++ b/ports/esp32/machine_adc.c @@ -136,6 +136,21 @@ static const machine_adc_obj_t madc_obj[] = { {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_7, GPIO_NUM_18}, {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_8, GPIO_NUM_19}, {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_9, GPIO_NUM_20}, + #elif CONFIG_IDF_TARGET_ESP32P4 + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_16}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_17}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_2, GPIO_NUM_18}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_3, GPIO_NUM_19}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_4, GPIO_NUM_20}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_5, GPIO_NUM_21}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_6, GPIO_NUM_22}, + {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_7, GPIO_NUM_23}, + {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_0, GPIO_NUM_49}, + {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_1, GPIO_NUM_50}, + {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_2, GPIO_NUM_51}, + {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_3, GPIO_NUM_52}, + {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_4, GPIO_NUM_53}, + {{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_5, GPIO_NUM_54}, #endif }; diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index dcf8b3942a..aea6bd00fe 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -73,6 +73,10 @@ #define MICROPY_HW_SPI2_SCK (36) #define MICROPY_HW_SPI2_MOSI (35) #define MICROPY_HW_SPI2_MISO (37) +#elif CONFIG_IDF_TARGET_ESP32P4 +#define MICROPY_HW_SPI2_SCK (43) +#define MICROPY_HW_SPI2_MOSI (44) +#define MICROPY_HW_SPI2_MISO (39) #endif #endif diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c index efe6733194..74ee15a24a 100644 --- a/ports/esp32/machine_pin.c +++ b/ports/esp32/machine_pin.c @@ -55,6 +55,8 @@ #define GPIO_FIRST_NON_OUTPUT (34) #elif CONFIG_IDF_TARGET_ESP32S2 #define GPIO_FIRST_NON_OUTPUT (46) +#elif CONFIG_IDF_TARGET_ESP32P4 +#define GPIO_FIRST_NON_OUTPUT (54) #endif // Return the gpio_num_t index for a given machine_pin_obj_t pointer. diff --git a/ports/esp32/machine_pin.h b/ports/esp32/machine_pin.h index 9e247a7367..4e21b032e6 100644 --- a/ports/esp32/machine_pin.h +++ b/ports/esp32/machine_pin.h @@ -216,6 +216,66 @@ #define MICROPY_HW_ENABLE_GPIO47 (1) #define MICROPY_HW_ENABLE_GPIO48 (1) #endif +#elif CONFIG_IDF_TARGET_ESP32P4 +#define MICROPY_HW_ENABLE_GPIO0 (1) +#define MICROPY_HW_ENABLE_GPIO1 (1) +#define MICROPY_HW_ENABLE_GPIO2 (1) +#define MICROPY_HW_ENABLE_GPIO3 (1) +#define MICROPY_HW_ENABLE_GPIO4 (1) +#define MICROPY_HW_ENABLE_GPIO5 (1) +#define MICROPY_HW_ENABLE_GPIO6 (1) +#define MICROPY_HW_ENABLE_GPIO7 (1) +#define MICROPY_HW_ENABLE_GPIO8 (1) +#define MICROPY_HW_ENABLE_GPIO9 (1) +#define MICROPY_HW_ENABLE_GPIO10 (1) +#define MICROPY_HW_ENABLE_GPIO11 (1) +#define MICROPY_HW_ENABLE_GPIO12 (1) +#define MICROPY_HW_ENABLE_GPIO13 (1) +#define MICROPY_HW_ENABLE_GPIO14 (1) +#define MICROPY_HW_ENABLE_GPIO15 (1) +#define MICROPY_HW_ENABLE_GPIO16 (1) +#define MICROPY_HW_ENABLE_GPIO17 (1) +#define MICROPY_HW_ENABLE_GPIO18 (1) +#define MICROPY_HW_ENABLE_GPIO19 (1) +#define MICROPY_HW_ENABLE_GPIO20 (1) +#define MICROPY_HW_ENABLE_GPIO21 (1) +#define MICROPY_HW_ENABLE_GPIO22 (1) +#define MICROPY_HW_ENABLE_GPIO23 (1) +#if !MICROPY_HW_ESP_USB_SERIAL_JTAG +// Note: ESP32-P4 can switch USJ to 26/27 instead, but +// this isn't supported +#define MICROPY_HW_ENABLE_GPIO24 (1) +#define MICROPY_HW_ENABLE_GPIO25 (1) +#endif +#define MICROPY_HW_ENABLE_GPIO26 (1) +#define MICROPY_HW_ENABLE_GPIO27 (1) +#define MICROPY_HW_ENABLE_GPIO28 (1) +#define MICROPY_HW_ENABLE_GPIO29 (1) +#define MICROPY_HW_ENABLE_GPIO30 (1) +#define MICROPY_HW_ENABLE_GPIO31 (1) +#define MICROPY_HW_ENABLE_GPIO32 (1) +#define MICROPY_HW_ENABLE_GPIO33 (1) +#define MICROPY_HW_ENABLE_GPIO34 (1) +#define MICROPY_HW_ENABLE_GPIO35 (1) +#define MICROPY_HW_ENABLE_GPIO36 (1) +#define MICROPY_HW_ENABLE_GPIO37 (1) +#define MICROPY_HW_ENABLE_GPIO38 (1) +#define MICROPY_HW_ENABLE_GPIO39 (1) +#define MICROPY_HW_ENABLE_GPIO40 (1) +#define MICROPY_HW_ENABLE_GPIO41 (1) +#define MICROPY_HW_ENABLE_GPIO42 (1) +#define MICROPY_HW_ENABLE_GPIO43 (1) +#define MICROPY_HW_ENABLE_GPIO44 (1) +#define MICROPY_HW_ENABLE_GPIO45 (1) +#define MICROPY_HW_ENABLE_GPIO46 (1) +#define MICROPY_HW_ENABLE_GPIO47 (1) +#define MICROPY_HW_ENABLE_GPIO48 (1) +#define MICROPY_HW_ENABLE_GPIO49 (1) +#define MICROPY_HW_ENABLE_GPIO50 (1) +#define MICROPY_HW_ENABLE_GPIO51 (1) +#define MICROPY_HW_ENABLE_GPIO52 (1) +#define MICROPY_HW_ENABLE_GPIO53 (1) +#define MICROPY_HW_ENABLE_GPIO54 (1) #endif diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c index ea9ce5469b..b9cd80f48e 100644 --- a/ports/esp32/machine_timer.c +++ b/ports/esp32/machine_timer.c @@ -47,6 +47,9 @@ #define TIMER_FLAGS 0 +#if CONFIG_IDF_TARGET_ESP32P4 +static uint8_t __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); +#endif const mp_obj_type_t machine_timer_type; static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); diff --git a/ports/esp32/machine_touchpad.c b/ports/esp32/machine_touchpad.c index 299c489f5a..88b34d64ff 100644 --- a/ports/esp32/machine_touchpad.c +++ b/ports/esp32/machine_touchpad.c @@ -41,8 +41,11 @@ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32 only #include "driver/touch_pad.h" -#elif SOC_TOUCH_SENSOR_VERSION == 2 // All other SoCs with touch, to date +#elif SOC_TOUCH_SENSOR_VERSION == 2 // most ESP32 #include "driver/touch_sensor.h" +#elif SOC_TOUCH_SENSOR_VERSION == 3 // At present, it can only be used on ESP32P4. +#include "driver/touch_sens.h" +#include "soc/touch_sensor_channel.h" #else #error "Unknown touch hardware version" #endif @@ -50,9 +53,18 @@ typedef struct _mtp_obj_t { mp_obj_base_t base; gpio_num_t gpio_id; + #if SOC_TOUCH_SENSOR_VERSION == 1 || SOC_TOUCH_SENSOR_VERSION == 2 touch_pad_t touchpad_id; + #elif SOC_TOUCH_SENSOR_VERSION == 3 + int touchpad_id; + #endif } mtp_obj_t; +#if SOC_TOUCH_SENSOR_VERSION == 3 +static touch_sensor_handle_t touch_sens_handle; +static touch_channel_handle_t touch_chan_handle[15]; +#endif + static const mtp_obj_t touchpad_obj[] = { #if CONFIG_IDF_TARGET_ESP32 {{&machine_touchpad_type}, GPIO_NUM_4, TOUCH_PAD_NUM0}, @@ -80,6 +92,21 @@ static const mtp_obj_t touchpad_obj[] = { {{&machine_touchpad_type}, GPIO_NUM_12, TOUCH_PAD_NUM12}, {{&machine_touchpad_type}, GPIO_NUM_13, TOUCH_PAD_NUM13}, {{&machine_touchpad_type}, GPIO_NUM_14, TOUCH_PAD_NUM14}, + #elif CONFIG_IDF_TARGET_ESP32P4 + {{&machine_touchpad_type}, GPIO_NUM_2, TOUCH_PAD_GPIO2_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_3, TOUCH_PAD_GPIO3_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_4, TOUCH_PAD_GPIO4_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_5, TOUCH_PAD_GPIO5_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_6, TOUCH_PAD_GPIO6_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_7, TOUCH_PAD_GPIO7_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_8, TOUCH_PAD_GPIO8_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_9, TOUCH_PAD_GPIO9_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_10, TOUCH_PAD_GPIO10_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_11, TOUCH_PAD_GPIO11_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_12, TOUCH_PAD_GPIO12_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_13, TOUCH_PAD_GPIO13_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_14, TOUCH_PAD_GPIO14_CHANNEL}, + {{&machine_touchpad_type}, GPIO_NUM_15, TOUCH_PAD_GPIO15_CHANNEL}, #else #error "Please add GPIO mapping for this SoC" #endif @@ -102,14 +129,45 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ static int initialized = 0; if (!initialized) { + #if SOC_TOUCH_SENSOR_VERSION == 1 || SOC_TOUCH_SENSOR_VERSION == 2 touch_pad_init(); touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + #elif SOC_TOUCH_SENSOR_VERSION == 3 + touch_sensor_sample_config_t sample_cfg[1] = { + TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(1, 1, 1), + }; + touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(1, sample_cfg); + check_esp_err(touch_sensor_new_controller(&sens_cfg, &touch_sens_handle)); + touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG(); + check_esp_err(touch_sensor_config_filter(touch_sens_handle, &filter_cfg)); + #endif initialized = 1; } + #if SOC_TOUCH_SENSOR_VERSION == 3 + else { + // Stop the touch controller so a new channel can be added. + check_esp_err(touch_sensor_stop_continuous_scanning(touch_sens_handle)); + check_esp_err(touch_sensor_disable(touch_sens_handle)); + } + #endif #if SOC_TOUCH_SENSOR_VERSION == 1 esp_err_t err = touch_pad_config(self->touchpad_id, 0); #elif SOC_TOUCH_SENSOR_VERSION == 2 esp_err_t err = touch_pad_config(self->touchpad_id); + #elif SOC_TOUCH_SENSOR_VERSION == 3 + touch_channel_config_t chan_cfg = { + .active_thresh = {1000}, + }; + esp_err_t err = ESP_OK; + if (touch_chan_handle[self->touchpad_id] != NULL) { + err = touch_sensor_del_channel(touch_chan_handle[self->touchpad_id]); + touch_chan_handle[self->touchpad_id] = NULL; + } + if (err == ESP_OK) { + err = touch_sensor_new_channel(touch_sens_handle, self->touchpad_id, &chan_cfg, &touch_chan_handle[self->touchpad_id]); + } + check_esp_err(touch_sensor_enable(touch_sens_handle)); + check_esp_err(touch_sensor_start_continuous_scanning(touch_sens_handle)); #endif if (err == ESP_OK) { #if SOC_TOUCH_SENSOR_VERSION == 2 @@ -121,6 +179,7 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ mp_raise_ValueError(MP_ERROR_TEXT("Touch pad error")); } +#if SOC_TOUCH_SENSOR_VERSION == 1 || SOC_TOUCH_SENSOR_VERSION == 2 static mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) { mtp_obj_t *self = self_in; #if SOC_TOUCH_SENSOR_VERSION == 1 @@ -135,6 +194,7 @@ static mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) { mp_raise_ValueError(MP_ERROR_TEXT("Touch pad error")); } MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config); +#endif static mp_obj_t mtp_read(mp_obj_t self_in) { mtp_obj_t *self = self_in; @@ -144,6 +204,9 @@ static mp_obj_t mtp_read(mp_obj_t self_in) { #elif SOC_TOUCH_SENSOR_VERSION == 2 uint32_t value; esp_err_t err = touch_pad_read_raw_data(self->touchpad_id, &value); + #elif SOC_TOUCH_SENSOR_VERSION == 3 + uint32_t value; + esp_err_t err = touch_channel_read_data(touch_chan_handle[self->touchpad_id], TOUCH_CHAN_DATA_TYPE_SMOOTH, &value); #endif if (err == ESP_OK) { return MP_OBJ_NEW_SMALL_INT(value); @@ -154,7 +217,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(mtp_read_obj, mtp_read); static const mp_rom_map_elem_t mtp_locals_dict_table[] = { // instance methods + #if SOC_TOUCH_SENSOR_VERSION == 1 || SOC_TOUCH_SENSOR_VERSION == 2 { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&mtp_config_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mtp_read_obj) }, }; diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index ea403f4221..a2034b7492 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -293,6 +293,14 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, self->tx = 5; break; #endif + #if SOC_UART_HP_NUM > 3 + case UART_NUM_3: + break; + #endif + #if SOC_UART_HP_NUM > 4 + case UART_NUM_4: + break; + #endif case UART_NUM_MAX: assert(0); // Range is checked in mp_machine_uart_make_new, value should be unreachable } diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 7460bf3593..12835f313e 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -108,7 +108,8 @@ void mp_task(void *pvParameter) { #endif #if MICROPY_HW_ESP_USB_SERIAL_JTAG usb_serial_jtag_init(); - #elif MICROPY_HW_ENABLE_USBDEV + #endif + #if MICROPY_HW_ENABLE_USBDEV usb_phy_init(); #endif #if MICROPY_HW_ENABLE_UART_REPL diff --git a/ports/esp32/main/idf_component.yml b/ports/esp32/main/idf_component.yml index 77904865ba..cb75296fe5 100644 --- a/ports/esp32/main/idf_component.yml +++ b/ports/esp32/main/idf_component.yml @@ -1,13 +1,20 @@ -## IDF Component Manager Manifest File dependencies: espressif/mdns: "~1.1.0" espressif/tinyusb: rules: - - if: "target in [esp32s2, esp32s3]" + - if: "target in [esp32s2, esp32s3, esp32p4]" # Temporary workaround for https://github.com/hathach/tinyusb/issues/3154 # Can be removed once fix is released in espressif/tinyusb git: https://github.com/micropython/tinyusb-espressif.git version: cherrypick/dwc2_zlp_fix + espressif/esp_hosted: + rules: + - if: "target == esp32p4" + version: "2.2.4" + espressif/esp_wifi_remote: + rules: + - if: "target == esp32p4" + version: "0.15.2" espressif/lan867x: version: "~1.0.0" rules: diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c index 1d002fc84b..a2ad9267cb 100644 --- a/ports/esp32/modesp32.c +++ b/ports/esp32/modesp32.c @@ -196,7 +196,7 @@ static mp_obj_t esp32_wake_on_gpio(size_t n_args, const mp_obj_t *pos_args, mp_m } static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_gpio_obj, 0, esp32_wake_on_gpio); -#if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP +#if SOC_GPIO_SUPPORT_HOLD_IO_IN_DSLP && !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP static mp_obj_t esp32_gpio_deep_sleep_hold(const mp_obj_t enable) { if (mp_obj_is_true(enable)) { gpio_deep_sleep_hold_en(); @@ -331,7 +331,7 @@ static const mp_rom_map_elem_t esp32_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_wake_on_ulp), MP_ROM_PTR(&esp32_wake_on_ulp_obj) }, #endif { MP_ROM_QSTR(MP_QSTR_wake_on_gpio), MP_ROM_PTR(&esp32_wake_on_gpio_obj) }, - #if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP + #if SOC_GPIO_SUPPORT_HOLD_IO_IN_DSLP && !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP { MP_ROM_QSTR(MP_QSTR_gpio_deep_sleep_hold), MP_ROM_PTR(&esp32_gpio_deep_sleep_hold_obj) }, #endif #if CONFIG_IDF_TARGET_ESP32 diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index 62f0bf73cf..ec972bfc68 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -260,8 +260,12 @@ static mp_int_t mp_machine_reset_cause(void) { } #if MICROPY_ESP32_USE_BOOTLOADER_RTC +#if !CONFIG_IDF_TARGET_ESP32P4 #include "soc/rtc_cntl_reg.h" #include "usb.h" +#else +#include "soc/lp_system_reg.h" +#endif #if CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/usb/usb_dc.h" #include "esp32s3/rom/usb/usb_persist.h" @@ -274,8 +278,13 @@ MP_NORETURN static void machine_bootloader_rtc(void) { usb_dc_prepare_persist(); chip_usb_set_persist_flags(USBDC_BOOT_DFU); #endif + #if !CONFIG_IDF_TARGET_ESP32P4 REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); esp_restart(); + #else + REG_WRITE(LP_SYSTEM_REG_SYS_CTRL_REG, LP_SYSTEM_REG_FORCE_DOWNLOAD_BOOT); + esp_restart(); + #endif } #endif diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index c0bd4516e5..55503ff0ba 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -180,6 +180,8 @@ #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c5" #elif CONFIG_IDF_TARGET_ESP32C6 #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32c6" +#elif CONFIG_IDF_TARGET_ESP32P4 +#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32p4" #endif #endif #define MICROPY_PY_NETWORK_INCLUDEFILE "ports/esp32/modnetwork.h" @@ -257,6 +259,17 @@ #define MICROPY_HW_USB_PRODUCT_FS_STRING "Espressif Device" #endif +#if CONFIG_IDF_TARGET_ESP32P4 +// By default, ESP32-P4 uses the HS USB PHY (RHPORT1) for TinyUSB +// and configures the full speed USB port as USB Serial/JTAG device +#ifndef MICROPY_HW_USB_HS +#define MICROPY_HW_USB_HS 1 +#endif // MICROPY_HW_USB_HS +#if MICROPY_HW_USB_HS && !defined(CFG_TUSB_RHPORT0_MODE) && !defined(CFG_TUSB_RHPORT1_MODE) +#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) +#endif +#endif + #endif // MICROPY_HW_ENABLE_USBDEV // Enable stdio over native USB peripheral CDC via TinyUSB @@ -265,14 +278,14 @@ #endif // Enable stdio over USB Serial/JTAG peripheral +// (SOC_USB_OTG_PERIPH_NUM is only 2 on the ESP32-P4, which supports both native USB & Serial/JTAG simultaneously) #ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG -#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC) +#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && (!MICROPY_HW_USB_CDC || SOC_USB_OTG_PERIPH_NUM > 1)) #endif -#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG +#if MICROPY_HW_USB_CDC && MICROPY_HW_ESP_USB_SERIAL_JTAG && (SOC_USB_OTG_PERIPH_NUM <= 1) #error "Invalid build config: Can't enable both native USB and USB Serial/JTAG peripheral" #endif - // type definitions for the specific machine #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p))) @@ -351,7 +364,7 @@ typedef long mp_off_t; #ifndef MICROPY_BOARD_ENTER_BOOTLOADER // RTC has a register to trigger bootloader on these targets -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32P4 #define MICROPY_ESP32_USE_BOOTLOADER_RTC (1) #define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) machine_bootloader_rtc() #endif diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index 309ee0b14a..37f72c2634 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -182,13 +182,13 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar } eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - #if CONFIG_IDF_TARGET_ESP32 + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4 eth_esp32_emac_config_t esp32_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); #endif esp_eth_mac_t *mac = NULL; - #if CONFIG_IDF_TARGET_ESP32 + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4 // Dynamic ref_clk configuration. if (args[ARG_ref_clk_mode].u_int != -1) { // Map the GPIO_MODE constants to EMAC_CLK constants. @@ -223,7 +223,7 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar #endif switch (args[ARG_phy_type].u_int) { - #if CONFIG_IDF_TARGET_ESP32 + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4 case PHY_LAN8710: case PHY_LAN8720: self->phy = esp_eth_phy_new_lan87xx(&phy_config); @@ -251,7 +251,7 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar self->phy = esp_eth_phy_new_generic(&phy_config); break; #endif - #endif // CONFIG_IDF_TARGET_ESP32 + #endif // CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4 #if CONFIG_ETH_USE_SPI_ETHERNET #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL case PHY_KSZ8851SNL: { @@ -286,7 +286,7 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar #endif } - #if CONFIG_IDF_TARGET_ESP32 + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4 if (!IS_SPI_PHY(args[ARG_phy_type].u_int)) { if (self->mdc_pin == -1 || self->mdio_pin == -1) { mp_raise_ValueError(MP_ERROR_TEXT("mdc and mdio must be specified")); diff --git a/ports/esp32/uart.c b/ports/esp32/uart.c index 491314e04d..6e00fa3aa2 100644 --- a/ports/esp32/uart.c +++ b/ports/esp32/uart.c @@ -40,6 +40,10 @@ static void uart_irq_handler(void *arg); +#if CONFIG_IDF_TARGET_ESP32P4 +static uint8_t __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); +#endif + // Declaring the HAL structure on the stack saves a tiny amount of static RAM #define REPL_HAL_DEFN() { .dev = UART_LL_GET_HW(MICROPY_HW_UART_REPL) } diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index b90f53aa49..bca2305f19 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -42,18 +42,17 @@ void usb_phy_init(void) { // ref: https://github.com/espressif/esp-usb/blob/4b6a798d0bed444fff48147c8dcdbbd038e92892/device/esp_tinyusb/tinyusb.c // Configure USB PHY - usb_phy_config_t phy_conf = { + static const usb_phy_config_t phy_conf = { .controller = USB_PHY_CTRL_OTG, .otg_mode = USB_OTG_MODE_DEVICE, + .target = USB_PHY_TARGET_INT, }; - // Internal USB PHY - phy_conf.target = USB_PHY_TARGET_INT; // Init ESP USB Phy usb_new_phy(&phy_conf, &phy_hdl); } -#if CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 void usb_usj_mode(void) { // Switch the USB PHY back to Serial/Jtag mode, disabling OTG support // This should be run before jumping to bootloader. diff --git a/shared/tinyusb/tusb_config.h b/shared/tinyusb/tusb_config.h index 40cb00ca48..8abd021548 100644 --- a/shared/tinyusb/tusb_config.h +++ b/shared/tinyusb/tusb_config.h @@ -59,7 +59,7 @@ #define MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING "1.00" #endif -#ifndef CFG_TUSB_RHPORT0_MODE +#if !defined(CFG_TUSB_RHPORT0_MODE) && !defined(CFG_TUSB_RHPORT1_MODE) #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) #endif