Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to ESP-IDF 5.1 and add C6 and H2 support #8424

Merged
merged 8 commits into from
Sep 22, 2023
Merged
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
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
[submodule "ports/espressif/esp-idf"]
path = ports/espressif/esp-idf
url = https://github.com/adafruit/esp-idf.git
branch = circuitpython-v5.1
[submodule "ports/espressif/esp-protocols"]
path = ports/espressif/esp-protocols
url = https://github.com/espressif/esp-protocols.git
Expand All @@ -151,7 +152,7 @@
url = https://github.com/espressif/esp-iot-solution.git
[submodule "ports/espressif/esp-camera"]
path = ports/espressif/esp-camera
url = https://github.com/espressif/esp32-camera.git
url = https://github.com/adafruit/esp32-camera.git
branch = circuitpython
[submodule "frozen/Adafruit_CircuitPython_ST7789"]
path = frozen/Adafruit_CircuitPython_ST7789
Expand Down
105 changes: 88 additions & 17 deletions ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ include ../../py/circuitpy_mkenv.mk
ifeq ($(IDF_TARGET),esp32c3)
IDF_TARGET_ARCH = riscv
CROSS_COMPILE = riscv32-esp-elf-
else ifeq ($(IDF_TARGET),esp32c6)
IDF_TARGET_ARCH = riscv
CROSS_COMPILE = riscv32-esp-elf-
else ifeq ($(IDF_TARGET),esp32h2)
IDF_TARGET_ARCH = riscv
CROSS_COMPILE = riscv32-esp-elf-
else
IDF_TARGET_ARCH = xtensa
CROSS_COMPILE = xtensa-$(IDF_TARGET)-elf-
endif

ifeq ($(IDF_TARGET),esp32s3)
BT_IDF_TARGET = esp32c3
else
BT_IDF_TARGET = $(IDF_TARGET)
endif

#######################################
# CFLAGS
#######################################
Expand All @@ -52,23 +64,35 @@ INC += \
-isystem esp-idf/components/app_update/include \
-isystem esp-idf/components/bootloader_support/include \
-isystem esp-idf/components/bootloader_support/bootloader_flash/include \
-isystem esp-idf/components/bt/include/$(IDF_TARGET)/include \
-isystem esp-idf/components/bt/include/$(BT_IDF_TARGET)/include \
-isystem esp-idf/components/bt/host/nimble/esp-hci/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/controller/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/gap/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/util/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/transport/include \
-isystem esp-idf/components/bt/host/nimble/nimble/porting/nimble/include \
-isystem esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include \
-isystem esp-idf/components/bt/host/nimble/port/include \
-isystem esp-idf/components/driver/include \
-isystem esp-idf/components/driver/deprecated \
-isystem esp-idf/components/driver/dac/include \
-isystem esp-idf/components/driver/gpio/include \
-isystem esp-idf/components/driver/i2c/include \
-isystem esp-idf/components/driver/i2s/include \
-isystem esp-idf/components/driver/$(IDF_TARGET)/include \
-isystem esp-idf/components/driver/ledc/include \
-isystem esp-idf/components/driver/spi/include \
-isystem esp-idf/components/driver/temperature_sensor/include \
-isystem esp-idf/components/driver/touch_sensor/include \
-isystem esp-idf/components/driver/touch_sensor/$(IDF_TARGET)/include \
-isystem esp-idf/components/driver/twai/include \
-isystem esp-idf/components/efuse/include \
-isystem esp-idf/components/efuse/$(IDF_TARGET)/include \
-isystem esp-idf/components/$(IDF_TARGET)/include \
-isystem esp-idf/components/esp_adc/deprecated/include \
-isystem esp-idf/components/esp_adc/include \
-isystem esp-idf/components/esp_adc/$(IDF_TARGET)/include \
-isystem esp-idf/components/esp_app_format/include \
-isystem esp-idf/components/esp_common/include \
-isystem esp-idf/components/esp_event/include \
Expand All @@ -85,6 +109,7 @@ INC += \
-isystem esp-idf/components/esp_wifi/include \
-isystem esp-idf/components/freertos/esp_additions/include \
-isystem esp-idf/components/freertos/esp_additions/include/freertos \
-isystem esp-idf/components/freertos/esp_additions/arch/$(IDF_TARGET_ARCH)/include \
-isystem esp-idf/components/freertos/FreeRTOS-Kernel/include \
-isystem esp-idf/components/freertos/FreeRTOS-Kernel/include/freertos \
-isystem esp-idf/components/freertos/FreeRTOS-Kernel/portable/$(IDF_TARGET_ARCH)/include \
Expand All @@ -95,7 +120,9 @@ INC += \
-isystem esp-idf/components/log/include \
-isystem esp-idf/components/lwip/include \
-isystem esp-idf/components/lwip/lwip/src/include \
-isystem esp-idf/components/lwip/port/esp32/include \
-isystem esp-idf/components/lwip/port/include \
-isystem esp-idf/components/lwip/port/esp32xx/include \
-isystem esp-idf/components/lwip/port/freertos/include \
-isystem esp-idf/components/mbedtls/esp_crt_bundle/include \
-isystem esp-idf/components/mbedtls/mbedtls/include \
-isystem esp-idf/components/mbedtls/port/include \
Expand Down Expand Up @@ -153,12 +180,13 @@ CFLAGS += $(INC) -Werror -Wall -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_D
# Most current ESPs have nano versions of newlib in ROM so we use them.
ifneq ($(IDF_TARGET),esp32c6)
CFLAGS += --specs=nano.specs
LDFLAGS += -T$(IDF_TARGET).rom.newlib-nano.ld
endif

ifeq ($(IDF_TARGET_ARCH),xtensa)
CFLAGS += -mlongcalls
else ifeq ($(IDF_TARGET_ARCH),riscv)
CFLAGS += -march=rv32imc
CFLAGS += -march=rv32imac_zicsr_zifencei
endif

LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref -Wl,--undefined=uxTopUsedPriority
Expand All @@ -173,7 +201,6 @@ LDFLAGS += \
-T$(IDF_TARGET).rom.ld \
-T$(IDF_TARGET).rom.api.ld \
-T$(IDF_TARGET).rom.libgcc.ld \
-T$(IDF_TARGET).rom.newlib-nano.ld \
-Wl,-Bstatic \
-Wl,--no-warn-mismatch \
-Wl,--build-id=none \
Expand All @@ -189,6 +216,20 @@ LDFLAGS += \
-Tesp32c3.rom.newlib.ld \
-Tesp32c3.rom.version.ld \
-Tesp32c3.rom.eco3.ld
else ifeq ($(IDF_TARGET),esp32c6)
LDFLAGS += \
-Tesp32c6.rom.phy.ld \
-Tesp32c6.rom.pp.ld \
-Tesp32c6.rom.net80211.ld \
-Tesp32c6.rom.newlib.ld \
-Tesp32c6.rom.coexist.ld \
-Tesp32c6.rom.heap.ld \
-Tesp32c6.rom.wdt.ld
else ifeq ($(IDF_TARGET),esp32h2)
LDFLAGS += \
-Tesp32h2.rom.heap.ld \
-Tesp32h2.rom.newlib.ld \
-Tesp32h2.rom.wdt.ld
else ifeq ($(IDF_TARGET),esp32s2)
LDFLAGS += \
-T$(IDF_TARGET).rom.newlib-data.ld \
Expand All @@ -203,7 +244,7 @@ endif
LIBS := -lgcc -lc -lstdc++

# Use toolchain libm if we're not using our own.
ifndef INTERNAL_LIBM
ifneq ($(INTERNAL_LIBM),1)
LIBS += -lm
endif

Expand Down Expand Up @@ -243,12 +284,16 @@ SRC_C += \

SRC_C += $(wildcard common-hal/espidf/*.c)

ifeq ($(IDF_TARGET),esp32c3)
ifneq ($(CIRCUITPY_ESP_USB_SERIAL_JTAG),0)
SRC_C += supervisor/usb_serial_jtag.c
else
SRC_C += \
peripherals/pcnt.c \
peripherals/touch.c
endif

ifneq ($(CIRCUITPY_COUNTIO),0)
SRC_C += peripherals/pcnt.c
endif

ifneq ($(CIRCUITPY_TOUCHIO_USE_NATIVE),0)
SRC_C += peripherals/touch.c
endif

ifneq ($(CIRCUITPY_USB),0)
Expand Down Expand Up @@ -408,21 +453,42 @@ update-all-sdkconfigs: $(BUILD)/esp-idf/config/sdkconfig.h
update-board-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h
python tools/update_sdkconfig.py --board=$(BOARD) --debug=$(DEBUG)

BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a
BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
BINARY_WIFI_BLOBS = libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a
BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a
ifneq ($(CIRCUITPY_WIFI),0)
BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
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) app_update bootloader_support driver efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_netif esp_partition esp_phy esp_pm esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls mdns newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) app_update bootloader_support driver efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_phy esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs
ifneq ($(CIRCUITPY_WIFI),0)
ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant
endif
ifneq ($(CIRCUITPY_BLEIO),0)
BLE_IMPL_esp32 := esp32
BLE_IMPL_esp32s3 := esp32c3
BLE_IMPL_esp32c2 := libble
BLE_IMPL_esp32c3 := esp32c3
BLE_IMPL_esp32c6 := libble
BLE_IMPL_esp32h2 := libble
BLE_IMPL = $(BLE_IMPL_$(IDF_TARGET))

ESP_IDF_COMPONENTS_LINK += bt
ifeq ($(IDF_TARGET),esp32)
BINARY_BLOBS += esp-idf/components/bt/controller/lib_esp32/$(IDF_TARGET)/libbtdm_app.a
else
ifeq ($(BLE_IMPL),esp32)
BINARY_BLOBS += esp-idf/components/bt/controller/lib_esp32/$(IDF_TARGET)/libbtdm_app.a
endif

ifeq ($(BLE_IMPL),esp32c3)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libbtbb.a \
esp-idf/components/bt/controller/lib_esp32c3_family/$(IDF_TARGET)/libbtdm_app.a
endif

ifeq ($(BLE_IMPL),libble)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libbtbb.a \
esp-idf/components/bt/controller/lib_$(IDF_TARGET)/$(IDF_TARGET)-bt-lib/libble_app.a
endif
endif
ifneq ($(CIRCUITPY_ESPULP),0)
ESP_IDF_COMPONENTS_LINK += ulp
Expand Down Expand Up @@ -450,11 +516,16 @@ ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/esp-camera/libesp-camera
endif

ifneq ($(VALID_BOARD),)
# From esp-idf/components/bootloader/Kconfig.projbuild
# BOOTLOADER_OFFSET is determined by chip type, based on the ROM bootloader, and is not changeable.
ifeq ($(IDF_TARGET),esp32)
BOOTLOADER_OFFSET = 0x1000
else ifeq ($(IDF_TARGET),esp32h2)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32c3)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32c6)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32s3)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32s2)
Expand Down
6 changes: 4 additions & 2 deletions ports/espressif/bindings/espnow/Peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ STATIC mp_obj_t espnow_peer_make_new(const mp_obj_type_t *type, size_t n_args, s
self->peer_info.ifidx = (wifi_interface_t)mp_arg_validate_int_range(args[ARG_interface].u_int, 0, 1, MP_QSTR_interface);

self->peer_info.encrypt = args[ARG_encrypted].u_bool;
self->lmk_set = false;

const mp_obj_t lmk = args[ARG_lmk].u_obj;
if (lmk != mp_const_none) {
self->lmk_set = true;
memcpy(self->peer_info.lmk, common_hal_espnow_get_bytes_len(lmk, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN);
} else if (self->peer_info.encrypt && !self->peer_info.lmk) {
} else if (self->peer_info.encrypt) {
mp_raise_ValueError_varg(translate("%q is %q"), MP_QSTR_lmk, MP_QSTR_None);
}

Expand Down Expand Up @@ -196,7 +198,7 @@ STATIC mp_obj_t espnow_peer_set_encrypted(const mp_obj_t self_in, const mp_obj_t

self->peer_info.encrypt = mp_obj_is_true(value);

if (!self->peer_info.lmk) {
if (!self->lmk_set) {
mp_raise_ValueError_varg(translate("%q is %q"), MP_QSTR_lmk, MP_QSTR_None);
}

Expand Down
1 change: 1 addition & 0 deletions ports/espressif/bindings/espnow/Peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
typedef struct {
mp_obj_base_t base;
esp_now_peer_info_t peer_info;
bool lmk_set;
} espnow_peer_obj_t;

extern const mp_obj_type_t espnow_peer_type;
2 changes: 0 additions & 2 deletions ports/espressif/boards/01space_lcd042_esp32c3/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@

// For entering safe mode
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)

#define CIRCUITPY_ESP_USB_SERIAL_JTAG (1)
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ IDF_TARGET = esp32c3
CIRCUITPY_ESP_FLASH_MODE = dio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

CIRCUITPY_BLEIO = 0
2 changes: 1 addition & 1 deletion ports/espressif/boards/adafruit_feather_esp32_v2/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"

Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/boards/adafruit_feather_esp32s2/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"

Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/boards/adafruit_matrixportal_s3/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"

Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/boards/adafruit_qtpy_esp32_pico/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"

Expand Down
2 changes: 0 additions & 2 deletions ports/espressif/boards/adafruit_qtpy_esp32c3/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@

// For entering safe mode
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)

#define CIRCUITPY_ESP_USB_SERIAL_JTAG (1)
4 changes: 4 additions & 0 deletions ports/espressif/boards/adafruit_qtpy_esp32c3/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ IDF_TARGET = esp32c3
CIRCUITPY_ESP_FLASH_MODE = dio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

CIRCUITPY_ESP_USB_SERIAL_JTAG = 1

CIRCUITPY_BLEIO = 0
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO18)

// UART pins attached to the USB-serial converter chip
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO43)
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO44)

#define MICROPY_HW_NEOPIXEL (&pin_GPIO4) // also DBLTAP

#define DOUBLE_TAP_PIN (&pin_GPIO4) // also NEOPIXEL
Expand Down
14 changes: 0 additions & 14 deletions ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
#
# Component config
#

#
# ESP System Settings
#
CONFIG_ESP_CONSOLE_UART_CUSTOM=y
# CONFIG_ESP_CONSOLE_NONE is not set
CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0=y
CONFIG_ESP_CONSOLE_UART_NUM=0
CONFIG_ESP_CONSOLE_UART_TX_GPIO=43
CONFIG_ESP_CONSOLE_UART_RX_GPIO=44
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
# end of ESP System Settings

#
# LWIP
#
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/boards/ai_thinker_esp32-c3s-2m/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/board.h"

#include "components/driver/include/driver/gpio.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "soc/usb_serial_jtag_struct.h"

void board_init(void) {
Expand Down
Loading