diff --git a/.github/actions/deps/external/action.yml b/.github/actions/deps/external/action.yml index 9f6dbf222a4..0624042b45b 100644 --- a/.github/actions/deps/external/action.yml +++ b/.github/actions/deps/external/action.yml @@ -40,6 +40,7 @@ runs: run: | source $IDF_PATH/export.sh echo >> $GITHUB_ENV "IDF_PYTHON_ENV_PATH=$IDF_PYTHON_ENV_PATH" + echo >> $GITHUB_ENV "ESP_IDF_VERSION=$ESP_IDF_VERSION" echo >> $GITHUB_PATH "$PATH" shell: bash diff --git a/.gitmodules b/.gitmodules index 6ac7a079035..f02565e6915 100644 --- a/.gitmodules +++ b/.gitmodules @@ -421,3 +421,6 @@ [submodule "frozen/Adafruit_CircuitPython_TAS2505"] path = frozen/Adafruit_CircuitPython_TAS2505 url = https://github.com/adafruit/Adafruit_CircuitPython_TAS2505.git +[submodule "ports/espressif/esp-hosted"] + path = ports/espressif/esp-hosted + url = https://github.com/espressif/esp-hosted-mcu.git diff --git a/ports/espressif/CMakeLists.txt b/ports/espressif/CMakeLists.txt index 608d4f4c7b3..e0901d649a4 100644 --- a/ports/espressif/CMakeLists.txt +++ b/ports/espressif/CMakeLists.txt @@ -8,7 +8,13 @@ set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf) set(COMPONENTS bt driver esp_driver_dac esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_i2s esp_driver_ledc esp_driver_pcnt esp_driver_rmt esp_driver_sdmmc esp_driver_spi esp_driver_touch_sens esp_driver_tsens esp_driver_uart esp_eth esp-tls esp_adc esp_adc_cal esp_event esp_netif esp_psram esp_security esp_wifi esptool_py freertos log lwip main mbedtls mdns pthread soc ulp wpa_supplicant esp-camera esp_lcd vfs esp_vfs_console esp_stdio sdmmc usb) set(EXTRA_COMPONENT_DIRS "esp-protocols/components/mdns" "esp-camera") +if(CIRCUITPY_ESP_HOSTED) + list(APPEND EXTRA_COMPONENT_DIRS "esp-hosted") + list(APPEND COMPONENTS esp-hosted) +endif() + include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(ENV{ESP_IDF_VERSION} "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}") project(circuitpython) idf_build_set_property(__OUTPUT_SDKCONFIG 0) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 1d713916168..978a3b0e7c0 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -6,6 +6,9 @@ include ../../py/circuitpy_mkenv.mk +# Keep dependency selection identical during automatic CMake reconfiguration. +export IDF_COMPONENT_MANAGER = 0 + ifeq ($(IDF_TARGET),esp32s3) BT_IDF_TARGET = esp32c3 else ifeq ($(IDF_TARGET),esp32c61) @@ -261,9 +264,11 @@ endif ifneq ($(CIRCUITPY_WIFI),0) ifeq ($(filter $(IDF_TARGET),esp32s2 esp32p4),) +ifneq ($(CIRCUITPY_ESP_HOSTED),1) REGISTRATION_FUNCTIONS += -u esp_coex_init_include_func endif endif +endif #Debugging/Optimization @@ -936,7 +941,7 @@ do-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h QSTR_GLOBAL_REQUIREMENTS += $(BUILD)/esp-idf/config/sdkconfig.h $(BUILD)/esp-idf/config/sdkconfig.h: boards/$(BOARD)/sdkconfig boards/$(BOARD)/mpconfigboard.mk CMakeLists.txt | $(BUILD)/esp-idf $(STEPECHO) "Create $@" - $(Q)env IDF_PATH=$(IDF_PATH) IDF_COMPONENT_MANAGER=0 cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -GNinja + $(Q)env IDF_PATH=$(IDF_PATH) IDF_COMPONENT_MANAGER=0 cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -DCIRCUITPY_ESP_HOSTED=$(CIRCUITPY_ESP_HOSTED) -GNinja $(Q)$(PYTHON) tools/check-sdkconfig.py \ CIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK) \ CIRCUITPY_STORAGE_EXTEND=$(CIRCUITPY_STORAGE_EXTEND) \ @@ -974,6 +979,7 @@ BINARY_WIFI_BLOBS = libcore.a libespnow.a libnet80211.a libpp.a libsmartconfig.a ifneq ($(IDF_TARGET),esp32p4) BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a endif +ifneq ($(CIRCUITPY_ESP_HOSTED),1) ifneq ($(CIRCUITPY_WIFI),0) BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS)) BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a @@ -982,6 +988,8 @@ ifneq ($(CIRCUITPY_WIFI),0) endif endif +endif + ifeq ($(IDF_TARGET),esp32) BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a endif @@ -1037,7 +1045,17 @@ endif # component is interface-only elsewhere, so it must not appear in the list of # components to link. ifneq ($(CIRCUITPY_WIFI),0) - ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp_security esp-tls esp_wifi lwip mdns wpa_supplicant esp_phy + ESP_IDF_COMPONENTS_LINK += esp_netif esp_security esp-tls esp_wifi lwip mbedtls mdns +ifneq ($(CIRCUITPY_ESP_HOSTED),1) +ESP_IDF_COMPONENTS_LINK += esp_coex esp_phy wpa_supplicant +endif +endif +ifeq ($(CIRCUITPY_ESP_HOSTED),1) +# ESP-IDF v6.1+ has remote Wi-Fi support built into esp_wifi, so no separate +# esp_wifi_remote component is needed. +INC := -isystem esp-hosted/host/api/include -isystem esp-hosted/host $(INC) +ESP_IDF_COMPONENTS_LINK += esp-hosted esp_http_client http_parser console +REGISTRATION_FUNCTIONS += -u esp_hosted_init endif # mdns registers handlers on ETH_EVENT, which is defined by esp_eth. On EMAC-capable # targets, esp_eth's compiled EMAC sources reference the esp_hal_emac symbols; that diff --git a/ports/espressif/boards/adafruit_metro_esp32p4/board.c b/ports/espressif/boards/adafruit_metro_esp32p4/board.c new file mode 100644 index 00000000000..85e13ed334d --- /dev/null +++ b/ports/espressif/boards/adafruit_metro_esp32p4/board.c @@ -0,0 +1,24 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2026 Limor Fried for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" +#include "esp_ldo_regulator.h" + +static esp_ldo_channel_handle_t io_ldo; + +void board_init(void) { + // Keep the rail acquired across simulated deep-sleep wakes. + if (io_ldo != NULL) { + return; + } + + // The SD card and C6 control pins (GPIO39-48) require the VO4 3.3 V rail. + const esp_ldo_channel_config_t config = { + .chan_id = 4, + .voltage_mv = 3300, + }; + ESP_ERROR_CHECK(esp_ldo_acquire_channel(&config, &io_ldo)); +} diff --git a/ports/espressif/boards/adafruit_metro_esp32p4/mpconfigboard.h b/ports/espressif/boards/adafruit_metro_esp32p4/mpconfigboard.h new file mode 100644 index 00000000000..b6675893027 --- /dev/null +++ b/ports/espressif/boards/adafruit_metro_esp32p4/mpconfigboard.h @@ -0,0 +1,30 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2026 Limor Fried for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "Adafruit Metro ESP32-P4" +#define MICROPY_HW_MCU_NAME "ESP32P4" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO23) +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO35) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO32) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO33) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO15) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO16) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO17) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO0) +#define DEFAULT_UART_BUS_TX (&pin_GPIO1) + +// USB-C shares GPIO24/25 with the ROM USB Serial/JTAG downloader. +#define CIRCUITPY_USB_DEVICE_INSTANCE 0 +#define CIRCUITPY_ESP32P4_SWAP_LSFS (1) + +// USB-A is connected to the dedicated high-speed PHY. +#define CIRCUITPY_USB_HOST_INSTANCE 1 diff --git a/ports/espressif/boards/adafruit_metro_esp32p4/mpconfigboard.mk b/ports/espressif/boards/adafruit_metro_esp32p4/mpconfigboard.mk new file mode 100644 index 00000000000..4dca7e3879a --- /dev/null +++ b/ports/espressif/boards/adafruit_metro_esp32p4/mpconfigboard.mk @@ -0,0 +1,17 @@ +USB_VID = 0x239A +USB_PID = 0x817C +USB_PRODUCT = "Adafruit Metro ESP32-P4" +USB_MANUFACTURER = "Adafruit" + +IDF_TARGET = esp32p4 + +CIRCUITPY_USB_HOST = 1 +CIRCUITPY_ESP_HOSTED = 1 + +CIRCUITPY_ESP_FLASH_SIZE = 16MB +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m + +CIRCUITPY_ESP_PSRAM_SIZE = 16MB +CIRCUITPY_ESP_PSRAM_MODE = hpi +CIRCUITPY_ESP_PSRAM_FREQ = 200m diff --git a/ports/espressif/boards/adafruit_metro_esp32p4/pins.c b/ports/espressif/boards/adafruit_metro_esp32p4/pins.c new file mode 100644 index 00000000000..ee2679ae1f0 --- /dev/null +++ b/ports/espressif/boards/adafruit_metro_esp32p4/pins.c @@ -0,0 +1,81 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2026 Limor Fried for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO49) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO50) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO51) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO52) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO53) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO54) }, + + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO32) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO33) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_HS_DP) }, + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_HS_DM) }, + { MP_ROM_QSTR(MP_QSTR_USB_HOST_POWER), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_DEBUG_TX), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_DEBUG_RX), MP_ROM_PTR(&pin_GPIO38) }, + + { MP_ROM_QSTR(MP_QSTR_SD_CLK), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_SD_CMD), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_SD_DATA0), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_SD_DATA1), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_SD_DATA2), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_SD_DATA3), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_SD_CD), MP_ROM_PTR(&pin_GPIO45) }, + + { MP_ROM_QSTR(MP_QSTR_C6_RX), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_C6_TX), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_C6_BOOT), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_C6_RESET), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_C6_WAKE), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_C6_SDIO_CLK), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_C6_SDIO_CMD), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_C6_SDIO_DATA0), MP_ROM_PTR(&pin_GPIO31) }, + { MP_ROM_QSTR(MP_QSTR_C6_SDIO_DATA1), MP_ROM_PTR(&pin_GPIO30) }, + { MP_ROM_QSTR(MP_QSTR_C6_SDIO_DATA2), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_C6_SDIO_DATA3), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_CAMERA_RESET), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO20) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/adafruit_metro_esp32p4/sdkconfig b/ports/espressif/boards/adafruit_metro_esp32p4/sdkconfig new file mode 100644 index 00000000000..a30634b1e0d --- /dev/null +++ b/ports/espressif/boards/adafruit_metro_esp32p4/sdkconfig @@ -0,0 +1,25 @@ +CONFIG_ESP32P4_SELECTS_REV_LESS_V3=y +CONFIG_ESP32P4_REV_MIN_1=y +CONFIG_ESP_WIFI_REMOTE_ENABLED=y +CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED=y +CONFIG_SLAVE_IDF_TARGET_ESP32C6=y +CONFIG_ESP_HOSTED_ENABLED=y +CONFIG_ESP_HOSTED_CP_TARGET_ESP32C6=y +CONFIG_ESP_HOSTED_P4_DEV_BOARD_NONE=y +CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE=y +CONFIG_ESP_HOSTED_SDIO_SLOT_1=y +CONFIG_ESP_HOSTED_SDIO_4_BIT_BUS=y +CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1=34 +CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1=36 +CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1=31 +CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1=30 +CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1=29 +CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1=28 +CONFIG_ESP_HOSTED_SDIO_GPIO_RESET_SLAVE=47 +CONFIG_ESP_HOSTED_SDIO_CLOCK_FREQ_KHZ=40000 + +# CONFIG_WIFI_RMT_NVS_ENABLED is not set + +# CONFIG_ESP_WIFI_NVS_ENABLED is not set + +# CONFIG_ESP32_WIFI_NVS_ENABLED is not set diff --git a/ports/espressif/common-hal/sdioio/SDCard.c b/ports/espressif/common-hal/sdioio/SDCard.c index 49a1a7340fa..2fd740e68e6 100644 --- a/ports/espressif/common-hal/sdioio/SDCard.c +++ b/ports/espressif/common-hal/sdioio/SDCard.c @@ -25,7 +25,6 @@ static const char *TAG = "SDCard.c"; static bool slot_in_use[2]; static bool never_reset_sdio[2] = { false, false }; -static bool host_initialized = false; static void common_hal_sdioio_sdcard_check_for_deinit(sdioio_sdcard_obj_t *self) { if (common_hal_sdioio_sdcard_deinited(self)) { @@ -38,9 +37,17 @@ static int check_pins(const mcu_pin_obj_t *clock, const mcu_pin_obj_t *command, // ESP32-S3 and P4 can use any pin for any SDMMC func in either slot // Default to SLOT_1 for SD cards ESP_LOGI(TAG, "Using chip with CONFIG_SOC_SDMMC_USE_GPIO_MATRIX"); - if (!slot_in_use[1]) { + if (!slot_in_use[1] + #ifdef CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE + && CONFIG_ESP_HOSTED_SDIO_SLOT != 1 + #endif + ) { return SDMMC_HOST_SLOT_1; - } else if (!slot_in_use[0]) { + } else if (!slot_in_use[0] + #ifdef CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE + && CONFIG_ESP_HOSTED_SDIO_SLOT != 0 + #endif + ) { return SDMMC_HOST_SLOT_0; } #else @@ -88,6 +95,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, esp_err_t err = ESP_OK; sdmmc_host_t host = SDMMC_HOST_DEFAULT(); + host.slot = sd_slot; host.max_freq_khz = frequency / 1000; sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); @@ -116,7 +124,6 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, if (err != ESP_OK) { mp_raise_OSError_msg_varg(MP_ERROR_TEXT("SDIO Init Error 0x%02x"), err); } - host_initialized = true; } err = sdmmc_host_init_slot(sd_slot, &slot_config); @@ -254,13 +261,10 @@ void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self) { return; } + sdmmc_host_deinit_slot(self->slot); never_reset_sdio[get_slot_index(self)] = false; slot_in_use[get_slot_index(self)] = false; - if (!slot_in_use[0] && !slot_in_use[1] && host_initialized) { - sdmmc_host_deinit(); - host_initialized = false; - } reset_pin_number(self->command); self->command = COMMON_HAL_MCU_NO_PIN; @@ -296,13 +300,12 @@ void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self) { void sdioio_reset(void) { for (size_t i = 0; i < MP_ARRAY_SIZE(slot_in_use); i++) { if (!never_reset_sdio[i]) { + if (slot_in_use[i]) { + sdmmc_host_deinit_slot(i); + } slot_in_use[i] = false; } } - if (!slot_in_use[0] && !slot_in_use[1] && host_initialized) { - sdmmc_host_deinit(); - host_initialized = false; - } return; } diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index c07e1a2d14e..cf5bedb95eb 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -25,7 +25,7 @@ #include "common-hal/socketpool/__init__.h" #include "components/esp_netif/include/esp_netif_net_stack.h" -#include "components/esp_wifi/include/esp_wifi.h" +#include "esp_wifi.h" #include "soc/soc_caps.h" #include "components/lwip/include/apps/ping/ping_sock.h" #include "lwip/sockets.h" diff --git a/ports/espressif/common-hal/wifi/ScannedNetworks.c b/ports/espressif/common-hal/wifi/ScannedNetworks.c index 0a87d3ab342..2beb6b754a3 100644 --- a/ports/espressif/common-hal/wifi/ScannedNetworks.c +++ b/ports/espressif/common-hal/wifi/ScannedNetworks.c @@ -17,7 +17,7 @@ #include "shared-bindings/wifi/Radio.h" #include "shared-bindings/wifi/ScannedNetworks.h" -#include "components/esp_wifi/include/esp_wifi.h" +#include "esp_wifi.h" #include "soc/soc_caps.h" static void wifi_scannednetworks_done(wifi_scannednetworks_obj_t *self) { diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index bfee50ffe93..59172b17851 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -17,7 +17,7 @@ #include "py/mpstate.h" #include "py/runtime.h" -#include "components/esp_wifi/include/esp_wifi.h" +#include "esp_wifi.h" #include "components/heap/include/esp_heap_caps.h" @@ -40,6 +40,11 @@ wifi_radio_obj_t common_hal_wifi_radio_obj; #include "esp_ipc.h" +#ifdef CONFIG_ESP_HOSTED_ENABLED +#include "esp_hosted.h" +#include "common-hal/microcontroller/Pin.h" +#endif + #ifdef CONFIG_IDF_TARGET_ESP32 #include "nvs_flash.h" #endif @@ -457,6 +462,19 @@ void common_hal_wifi_init(bool user_initiated) { if (!wifi_ever_inited) { ESP_ERROR_CHECK(esp_event_loop_create_default()); ESP_ERROR_CHECK(esp_netif_init()); + #ifdef CONFIG_ESP_HOSTED_ENABLED + const uint8_t pins[] = { + CONFIG_ESP_HOSTED_SDIO_PIN_CLK, CONFIG_ESP_HOSTED_SDIO_PIN_CMD, + CONFIG_ESP_HOSTED_SDIO_PIN_D0, CONFIG_ESP_HOSTED_SDIO_PIN_D1, + CONFIG_ESP_HOSTED_SDIO_PIN_D2, CONFIG_ESP_HOSTED_SDIO_PIN_D3, + CONFIG_ESP_HOSTED_SDIO_GPIO_RESET_SLAVE, + }; + for (size_t i = 0; i < MP_ARRAY_SIZE(pins); i++) { + claim_pin_number(pins[i]); + never_reset_pin_number(pins[i]); + } + ESP_ERROR_CHECK(esp_hosted_init()); + #endif wifi_ever_inited = true; } diff --git a/ports/espressif/esp-hosted b/ports/espressif/esp-hosted new file mode 160000 index 00000000000..dd0176e5fc9 --- /dev/null +++ b/ports/espressif/esp-hosted @@ -0,0 +1 @@ +Subproject commit dd0176e5fc959d79b306f6677a2f878123c58e9a diff --git a/ports/espressif/esp-idf b/ports/espressif/esp-idf index 0687c505dad..29d36039e56 160000 --- a/ports/espressif/esp-idf +++ b/ports/espressif/esp-idf @@ -1 +1 @@ -Subproject commit 0687c505dad1ace31c664de2c5494c13c08b0b1d +Subproject commit 29d36039e564db6df505d0582b94b230a17e63f3 diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 87ba43d1ebf..b635f193e1c 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -371,10 +371,12 @@ CIRCUITPY_AUDIOIO = 0 # MII is available on these targets with EMAC hardware. CIRCUITPY_MII ?= 1 -# No wifi -# TODO: Support ESP32-C6 coprocessor on some boards. +# Optional ESP-Hosted Wi-Fi coprocessor. +CIRCUITPY_ESP_HOSTED ?= 0 +CIRCUITPY_ESPNOW = 0 CIRCUITPY_BLEIO_NATIVE = 0 -CIRCUITPY_WIFI = 0 +CIRCUITPY_WIFI = $(CIRCUITPY_ESP_HOSTED) +CIRCUITPY_SSL = $(CIRCUITPY_ESP_HOSTED) # Second stage bootloader doesn't work when the factory partition is empty due to # UF2 missing. diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index c36acc26a73..c50746651b6 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -157,6 +157,16 @@ def fetch(where): cwd=mbedtls, ) + # ESP-Hosted keeps the protobuf-c runtime in a nested submodule. + esp_hosted = TOP / "ports" / "espressif" / "esp-hosted" + if (esp_hosted / ".gitmodules").exists(): + depth_maybe = "" if clone_supports_filter else "--depth 1" + run( + "Init esp-hosted nested submodules", + f"git submodule update --init {filter_maybe} {depth_maybe} common/protobuf-c", + cwd=esp_hosted, + ) + def set_output(name, value): if "GITHUB_OUTPUT" in os.environ: