Skip to content

esp32: Switch to IDF v5.0 #11528

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

Merged
merged 12 commits into from
Jun 23, 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
13 changes: 2 additions & 11 deletions .github/workflows/ports_esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@ concurrency:
cancel-in-progress: true

jobs:
build_idf402:
build_idf50:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install packages
run: source tools/ci.sh && ci_esp32_idf402_setup
- name: Build
run: source tools/ci.sh && ci_esp32_build

build_idf44:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install packages
run: source tools/ci.sh && ci_esp32_idf44_setup
run: source tools/ci.sh && ci_esp32_idf50_setup
- name: Build
run: source tools/ci.sh && ci_esp32_build
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ used during the build process and is not part of the compiled source code.
/hal (BSD-3-clause)
/simplelink (BSD-3-clause)
/FreeRTOS (GPL-2.0 with FreeRTOS exception)
/esp32
/ppp_set_auth.* (Apache-2.0)
/stm32
/usbd*.c (MCD-ST Liberty SW License Agreement V2)
/stm32_it.* (MIT + BSD-3-clause)
Expand Down
19 changes: 0 additions & 19 deletions docs/esp32/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ The :mod:`esp32` module::

import esp32

esp32.hall_sensor() # read the internal hall sensor
esp32.raw_temperature() # read the internal temperature of the MCU, in Fahrenheit
esp32.ULP() # access to the Ultra-Low-Power Co-processor

Expand Down Expand Up @@ -137,19 +136,11 @@ The keyword arguments for the constructor defining the PHY type and interface ar
or output. Suitable values are Pin.IN and Pin.OUT.
- ref_clk=pin-object # defines the Pin used for ref_clk.

The options ref_clk_mode and ref_clk require at least esp-idf version 4.4. For
earlier esp-idf versions, these parameters must be defined by kconfig board options.

These are working configurations for LAN interfaces of popular boards::

# Olimex ESP32-GATEWAY: power controlled by Pin(5)
# Olimex ESP32 PoE and ESP32-PoE ISO: power controlled by Pin(12)

lan = network.LAN(mdc=machine.Pin(23), mdio=machine.Pin(18), power=machine.Pin(5),
phy_type=network.PHY_LAN8720, phy_addr=0)

# or with dynamic ref_clk pin configuration

lan = network.LAN(mdc=machine.Pin(23), mdio=machine.Pin(18), power=machine.Pin(5),
phy_type=network.PHY_LAN8720, phy_addr=0,
ref_clk=machine.Pin(17), ref_clk_mode=machine.Pin.OUT)
Expand All @@ -164,16 +155,6 @@ These are working configurations for LAN interfaces of popular boards::
lan = network.LAN(id=0, mdc=Pin(23), mdio=Pin(18), power=Pin(5),
phy_type=network.PHY_IP101, phy_addr=1)

A suitable definition of the PHY interface in a sdkconfig.board file is::

CONFIG_ETH_PHY_INTERFACE_RMII=y
CONFIG_ETH_RMII_CLK_OUTPUT=y
CONFIG_ETH_RMII_CLK_OUT_GPIO=17
CONFIG_LWIP_LOCAL_HOSTNAME="ESP32_POE"

The value assigned to CONFIG_ETH_RMII_CLK_OUT_GPIO may vary depending on the
board's wiring.

Delay and timing
----------------

Expand Down
4 changes: 0 additions & 4 deletions docs/library/esp32.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ Functions

Read the raw value of the internal temperature sensor, returning an integer.

.. function:: hall_sensor()

Read the raw value of the internal Hall sensor, returning an integer.

.. function:: idf_heap_info(capabilities)

Returns information about the ESP-IDF heap memory regions. One of them contains
Expand Down
5 changes: 2 additions & 3 deletions docs/library/machine.WDT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ Constructors
Create a WDT object and start it. The timeout must be given in milliseconds.
Once it is running the timeout cannot be changed and the WDT cannot be stopped either.

Notes: On the esp32 the minimum timeout is 1 second. On the esp8266 a timeout
cannot be specified, it is determined by the underlying system. On rp2040 devices,
the maximum timeout is 8388 ms.
Notes: On the esp8266 a timeout cannot be specified, it is determined by the underlying system.
On rp2040 devices, the maximum timeout is 8388 ms.

Methods
-------
Expand Down
25 changes: 25 additions & 0 deletions extmod/modbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@
#include <stdio.h>
#include <errno.h> // for declaration of global errno variable
#include <fcntl.h>

// Undefine queue macros that will be defined in berkeley-db-1.xx headers
// below, in case they clash with system ones defined in headers above.
#undef LIST_HEAD
#undef LIST_ENTRY
#undef LIST_INIT
#undef LIST_INSERT_AFTER
#undef LIST_INSERT_HEAD
#undef LIST_REMOVE
#undef TAILQ_HEAD
#undef TAILQ_ENTRY
#undef TAILQ_INIT
#undef TAILQ_INSERT_HEAD
#undef TAILQ_INSERT_TAIL
#undef TAILQ_INSERT_AFTER
#undef TAILQ_REMOVE
#undef CIRCLEQ_HEAD
#undef CIRCLEQ_ENTRY
#undef CIRCLEQ_INIT
#undef CIRCLEQ_INSERT_AFTER
#undef CIRCLEQ_INSERT_BEFORE
#undef CIRCLEQ_INSERT_HEAD
#undef CIRCLEQ_INSERT_TAIL
#undef CIRCLEQ_REMOVE

#include <db.h>
#include <../../btree/btree.h>

Expand Down
4 changes: 2 additions & 2 deletions extmod/modhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);

#if MICROPY_SSL_MBEDTLS

#if MBEDTLS_VERSION_NUMBER < 0x02070000
#if MBEDTLS_VERSION_NUMBER < 0x02070000 || MBEDTLS_VERSION_NUMBER >= 0x03000000
#define mbedtls_sha256_starts_ret mbedtls_sha256_starts
#define mbedtls_sha256_update_ret mbedtls_sha256_update
#define mbedtls_sha256_finish_ret mbedtls_sha256_finish
Expand Down Expand Up @@ -203,7 +203,7 @@ STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) {

#if MICROPY_SSL_MBEDTLS

#if MBEDTLS_VERSION_NUMBER < 0x02070000
#if MBEDTLS_VERSION_NUMBER < 0x02070000 || MBEDTLS_VERSION_NUMBER >= 0x03000000
#define mbedtls_sha1_starts_ret mbedtls_sha1_starts
#define mbedtls_sha1_update_ret mbedtls_sha1_update
#define mbedtls_sha1_finish_ret mbedtls_sha1_finish
Expand Down
2 changes: 2 additions & 0 deletions extmod/modplatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#define MICROPY_PLATFORM_ARCH "x86"
#elif defined(__xtensa__)
#define MICROPY_PLATFORM_ARCH "xtensa"
#elif defined(__riscv)
#define MICROPY_PLATFORM_ARCH "riscv"
#else
#define MICROPY_PLATFORM_ARCH ""
#endif
Expand Down
4 changes: 4 additions & 0 deletions extmod/modssl_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
size_t key_len;
const byte *key = (const byte *)mp_obj_str_get_data(args->key.u_obj, &key_len);
// len should include terminating null
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
ret = mbedtls_pk_parse_key(&o->pkey, key, key_len + 1, NULL, 0, mbedtls_ctr_drbg_random, &o->ctr_drbg);
#else
ret = mbedtls_pk_parse_key(&o->pkey, key, key_len + 1, NULL, 0);
#endif
if (ret != 0) {
ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; // use general error for all key errors
goto cleanup;
Expand Down
2 changes: 2 additions & 0 deletions ports/esp32/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies.lock
managed_components/
20 changes: 9 additions & 11 deletions ports/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
endif()

# Include main IDF cmake file.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# Define the output sdkconfig so it goes in the build directory.
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)

# Save the manifest file set from the cmake command line.
set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST})

# Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options).
# Include board config; this is expected to set (among other options):
# - SDKCONFIG_DEFAULTS
# - IDF_TARGET
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)

# Set the frozen manifest file. Note if MICROPY_FROZEN_MANIFEST is set from the cmake
Expand All @@ -35,13 +34,6 @@ elseif (NOT MICROPY_FROZEN_MANIFEST)
set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/boards/manifest.py)
endif()

# Add sdkconfig fragments that depend on the IDF version.
if(IDF_VERSION_MAJOR EQUAL 4 AND IDF_VERSION_MINOR LESS 2)
set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} boards/sdkconfig.nimble_core0)
else()
set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} boards/sdkconfig.nimble_core1)
endif()

# Concatenate all sdkconfig files into a combined one for the IDF to use.
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
Expand All @@ -51,5 +43,11 @@ endforeach()
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)

# Include main IDF cmake file.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# Set the location of the main component for the project (one per target).
set(EXTRA_COMPONENT_DIRS main_${IDF_TARGET})

# Define the project.
project(micropython)
22 changes: 19 additions & 3 deletions ports/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ endif

HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"

define RUN_IDF_PY
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) $(1)
endef

all:
idf.py $(IDFPY_FLAGS) build || (echo -e $(HELP_BUILD_ERROR); false)
@$(PYTHON) makeimg.py \
Expand All @@ -61,13 +65,25 @@ all:
$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE

clean:
idf.py $(IDFPY_FLAGS) fullclean
$(call RUN_IDF_PY,fullclean)

deploy:
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) flash
$(call RUN_IDF_PY,flash)

erase:
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) erase_flash
$(call RUN_IDF_PY,erase-flash)

monitor:
$(call RUN_IDF_PY,monitor)

size:
$(call RUN_IDF_PY,size)

size-components:
$(call RUN_IDF_PY,size-components)

size-files:
$(call RUN_IDF_PY,size-files)

submodules:
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$(GIT_SUBMODULES)" submodules
15 changes: 5 additions & 10 deletions ports/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Initial development of this ESP32 port was sponsored in part by Microbric Pty Lt
Setting up ESP-IDF and the build environment
--------------------------------------------

MicroPython on ESP32 requires the Espressif IDF version 4 (IoT development
MicroPython on ESP32 requires the Espressif IDF version 5 (IoT development
framework, aka SDK). The ESP-IDF includes the libraries and RTOS needed to
manage the ESP32 microcontroller, as well as a way to manage the required
build environment and toolchains needed to build the firmware.

The ESP-IDF changes quickly and MicroPython only supports certain versions.
Currently MicroPython supports v4.0.2, v4.1.1, v4.2.2, v4.3.2 and v4.4,
Currently MicroPython supports v5.0.2,
although other IDF v4 versions may also work.

To install the ESP-IDF the full instructions can be found at the
Expand All @@ -47,10 +47,10 @@ The steps to take are summarised below.
To check out a copy of the IDF use git clone:

```bash
$ git clone -b v4.0.2 --recursive https://github.com/espressif/esp-idf.git
$ git clone -b v5.0.2 --recursive https://github.com/espressif/esp-idf.git
```

You can replace `v4.0.2` with `v4.2.2` or `v4.4` or any other supported version.
You can replace `v5.0.2` with any other supported version.
(You don't need a full recursive clone; see the `ci_esp32_setup` function in
`tools/ci.sh` in this repository for more detailed set-up commands.)

Expand All @@ -59,7 +59,7 @@ MicroPython and update the submodules using:

```bash
$ cd esp-idf
$ git checkout v4.2
$ git checkout v5.0.2
$ git submodule update --init --recursive
```

Expand All @@ -75,11 +75,6 @@ $ source export.sh # (or export.bat on Windows)
The `install.sh` step only needs to be done once. You will need to source
`export.sh` for every new session.

**Note:** If you are building MicroPython for the ESP32-S2, ESP32-C3 or ESP32-S3,
please ensure you are using the following required IDF versions:
- ESP32-S3 currently requires `v4.4` or later.
- ESP32-S2 and ESP32-C3 require `v4.3.1` or later.

Building the firmware
---------------------

Expand Down
1 change: 0 additions & 1 deletion ports/esp32/boards/ESP32_S2_WROVER/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_AFTER_NORESET=y

CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
Expand Down
2 changes: 0 additions & 2 deletions ports/esp32/boards/GENERIC_C3_USB/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
CONFIG_ESP32C3_REV_MIN_3=y
CONFIG_ESP32C3_REV_MIN=3
CONFIG_ESP32C3_BROWNOUT_DET=y
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_7=
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_4=y
CONFIG_ESP32C3_BROWNOUT_DET_LVL=4
CONFIG_ESP_CONSOLE_UART_DEFAULT=
CONFIG_ESP_CONSOLE_USB_CDC=
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
1 change: 1 addition & 0 deletions ports/esp32/boards/GENERIC_D2WD/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Optimise using -Os to reduce size
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_PERF=n
CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y

CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
Expand Down
3 changes: 0 additions & 3 deletions ports/esp32/boards/GENERIC_S3/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_AFTER_NORESET=y

CONFIG_SPIRAM_MEMTEST=

CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
Expand Down
3 changes: 0 additions & 3 deletions ports/esp32/boards/GENERIC_S3_SPIRAM/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_AFTER_NORESET=y

CONFIG_SPIRAM_MEMTEST=

CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
Expand Down
3 changes: 0 additions & 3 deletions ports/esp32/boards/GENERIC_S3_SPIRAM_OCT/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_AFTER_NORESET=y

CONFIG_SPIRAM_MEMTEST=

CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
Expand Down
1 change: 0 additions & 1 deletion ports/esp32/boards/GENERIC_SPIRAM/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
boards/sdkconfig.ble
boards/sdkconfig.spiram
boards/GENERIC_SPIRAM/sdkconfig.board
)
2 changes: 0 additions & 2 deletions ports/esp32/boards/GENERIC_SPIRAM/sdkconfig.board

This file was deleted.

2 changes: 0 additions & 2 deletions ports/esp32/boards/LOLIN_C3_MINI/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
CONFIG_ESP32C3_REV_MIN_3=y
CONFIG_ESP32C3_REV_MIN=3
CONFIG_ESP32C3_BROWNOUT_DET=y
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_7=
CONFIG_ESP32C3_BROWNOUT_DET_LVL_SEL_4=y
CONFIG_ESP32C3_BROWNOUT_DET_LVL=4
CONFIG_ESP_CONSOLE_UART_DEFAULT=
CONFIG_ESP_CONSOLE_USB_CDC=
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
Loading