Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,9 @@
[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
[submodule "ports/espressif/esp-wifi-remote"]
path = ports/espressif/esp-wifi-remote
url = https://github.com/espressif/esp-wifi-remote.git
6 changes: 6 additions & 0 deletions ports/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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-tls esp_adc esp_event esp_netif esp_psram esp_security esp_wifi esptool_py freertos log lwip main mbedtls mdns pthread soc ulp wpa_supplicant esp_lcd vfs esp_stdio sdmmc esp-camera)
set(EXTRA_COMPONENT_DIRS "esp-protocols/components/mdns" "esp-camera")

if(CIRCUITPY_ESP_HOSTED)
list(APPEND EXTRA_COMPONENT_DIRS "esp-hosted" "esp-wifi-remote/components/esp_wifi_remote")
list(APPEND COMPONENTS esp-hosted esp_wifi_remote)
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)
24 changes: 22 additions & 2 deletions ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -254,9 +257,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
Expand Down Expand Up @@ -885,7 +890,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) \
Expand Down Expand Up @@ -923,6 +928,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
Expand All @@ -931,13 +937,27 @@ ifneq ($(CIRCUITPY_WIFI),0)
endif
endif

endif

ifeq ($(IDF_TARGET),esp32)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
endif

ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_dma esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_gdbstub esp_hal_ana_conv esp_hal_clock esp_hal_gpio esp_hal_gpspi esp_hal_i2c esp_hal_ledc esp_hal_mspi esp_hal_security esp_hal_timg esp_hal_uart esp_hal_wdt esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log esp_libc nvs_flash nvs_sec_provider pthread soc spi_flash vfs esp_stdio
ifneq ($(CIRCUITPY_WIFI),0)
ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp_security esp-tls esp_wifi lwip mbedtls 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)
export ESP_IDF_VERSION := $(shell sed -nE 's/set\(IDF_VERSION_(MAJOR|MINOR) ([0-9]+)\)/\2/p' esp-idf/tools/cmake/version.cmake | paste -sd.)
INC := -isystem esp-wifi-remote/components/esp_wifi_remote/idf_v$(ESP_IDF_VERSION)/include/injected \
-isystem esp-wifi-remote/components/esp_wifi_remote/idf_v$(ESP_IDF_VERSION)/include \
-isystem esp-wifi-remote/components/esp_wifi_remote/include \
-isystem esp-hosted/host/api/include -isystem esp-hosted/host $(INC)
ESP_IDF_COMPONENTS_LINK += esp_wifi_remote esp-hosted esp_http_client http_parser console
REGISTRATION_FUNCTIONS += -u esp_hosted_init
endif
ifneq ($(CIRCUITPY_BLEIO_NATIVE),0)
BLE_IMPL_esp32 := esp32
Expand Down
12 changes: 10 additions & 2 deletions ports/espressif/common-hal/sdioio/SDCard.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,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
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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"
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/wifi/ScannedNetworks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 19 additions & 1 deletion ports/espressif/common-hal/wifi/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions ports/espressif/esp-hosted
Submodule esp-hosted added at dd0176
1 change: 1 addition & 0 deletions ports/espressif/esp-wifi-remote
Submodule esp-wifi-remote added at 896c12
9 changes: 5 additions & 4 deletions ports/espressif/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,12 @@ else ifeq ($(IDF_TARGET),esp32p4)
# No DAC
CIRCUITPY_AUDIOIO = 0

# 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_SSL = 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.
Expand Down
Loading