Skip to content

esp32: switch esp-idf to v4.2, add CI, support MICROPY_BOARD #6731

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

Closed
wants to merge 7 commits into from
Closed
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
64 changes: 64 additions & 0 deletions .github/workflows/ports_esp32.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: esp32 port

on:
push:
pull_request:
paths:
- '.github/workflows/*.yml'
- 'tools/**'
- 'py/**'
- 'extmod/**'
- 'lib/**'
- 'drivers/**'
- 'ports/esp32/**'

jobs:
cmake_idf42_build:
runs-on: ubuntu-20.04
env:
IDF_PATH: ${{ github.workspace }}/../esp-idf
IDF_TOOLS_PATH: ${{ github.workspace }}/../tools
IDF_TARGET: esp32
steps:
- uses: actions/checkout@v2
- name: Pull esp-idf tools from cache
uses: actions/cache@v2
with:
path: /home/runner/work/micropython/tools # note: no .. in cache path
key: esp32_idf42_tools
- name: Install esp-idf and tools
run: source tools/ci.sh && ci_esp32_idf42_setup
- name: Prep submodules and mpy-cross
run: source tools/ci.sh && ci_esp32_idf42_prep
- name: Build GENERIC
run: source tools/ci.sh && MICROPY_BOARD=GENERIC ci_esp32_idf42_build
- name: Build GENERIC_OTA
run: source tools/ci.sh && MICROPY_BOARD=GENERIC_OTA ci_esp32_idf42_build
- name: Build GENERIC_D2WD
run: source tools/ci.sh && MICROPY_BOARD=GENERIC_D2WD ci_esp32_idf42_build
- name: Build TINYPICO
run: source tools/ci.sh && MICROPY_BOARD=TINYPICO ci_esp32_idf42_build
- name: Build TOOTHLESS_OTA
run: source tools/ci.sh && MICROPY_BOARD=TOOTHLESS_OTA ci_esp32_idf42_build

# idf3_build:
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v2
# - name: Install packages
# run: source tools/ci.sh && ci_esp32_idf3_setup && ci_esp32_idf3_path >> $GITHUB_PATH
# - name: Build
# env:
# IDF_PATH: ${{ github.workspace }}/esp-idf
# run: source tools/ci.sh && ci_esp32_idf3_build
#
# idf4_build:
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v2
# - name: Install packages
# run: source tools/ci.sh && ci_esp32_idf4_setup && ci_esp32_idf4_path >> $GITHUB_PATH
# - name: Build
# env:
# IDF_PATH: ${{ github.workspace }}/esp-idf
# run: source tools/ci.sh && ci_esp32_idf4_build
28 changes: 28 additions & 0 deletions extmod/extmod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,31 @@ set(MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/vfs_reader.c
${MICROPY_EXTMOD_DIR}/virtpin.c
)

set (MICROPY_INCLUDE_EXTMOD)

if(NOT TOOTHLESS)
set(MICROPY_SOURCE_EXTMOD ${MICROPY_SOURCE_EXTMOD}
${MICROPY_EXTMOD_DIR}/modbluetooth.c
${MICROPY_EXTMOD_DIR}/nimble/modbluetooth_nimble.c
${MICROPY_EXTMOD_DIR}/nimble/hal/hal_uart.c
)

set (MICROPY_INCLUDE_EXTMOD ${MICROPY_INCLUDE_EXTMOD}
${IDF_PATH}/components/bt/host/nimble/nimble/nimble/host/include
${IDF_PATH}/components/bt/host/nimble/esp-hci/include/
${IDF_PATH}/components/bt/host/nimble/nimble/nimble/include
${IDF_PATH}/components/bt/host/nimble/nimble/porting/nimble/include
${IDF_PATH}/components/bt/host/nimble/port/include
${IDF_PATH}/components/bt/host/nimble/nimble/porting/npl/freertos/include
${IDF_PATH}/components/bt/common/osi/include/osi
${IDF_PATH}/components/bt/host/nimble/nimble/nimble/host/util/include
${IDF_PATH}/components/bt/host/nimble/nimble/porting/npl/freertos/include
${IDF_PATH}/components/bt/host/nimble/nimble/nimble/host/services/gap/include
${IDF_PATH}/components/bt/host/nimble/nimble/nimble/host/services/gatt/include
${IDF_PATH}/components/bt/host/nimble/nimble/nimble/transport/uart/include
)
endif()

#string(JOIN " " __MSE ${MICROPY_SOURCE_EXTMOD})
#message(NOTICE ******************** MICROPY_SOURCE_EXTMOD ******* ${__MSE})
5 changes: 5 additions & 0 deletions extmod/nimble/nimble/nimble_npl_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

// --- Configuration of NimBLE data structures --------------------------------

// This is used at runtime to align allocations correctly.
#ifndef MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY

#define BLE_NPL_OS_ALIGNMENT (sizeof(uintptr_t))
#define BLE_NPL_TIME_FOREVER (0xffffffff)

Expand Down Expand Up @@ -68,6 +71,8 @@ struct ble_npl_sem {
volatile uint16_t count;
};

#endif // !MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY

// --- Called by the MicroPython port -----------------------------------------

void mp_bluetooth_nimble_os_eventq_run_all(void);
Expand Down
2 changes: 2 additions & 0 deletions extmod/uasyncio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def run_until_complete(main_task=None):
# No tasks can be woken so finished running
return
# print('(poll {})'.format(dt), len(_io_queue.map))
if dt > 5:
dt = 5
_io_queue.wait_io_event(dt)

# Get next task to run and continue it
Expand Down
8 changes: 7 additions & 1 deletion ports/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
cmake_minimum_required(VERSION 3.5)
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
set(SDKCONFIG_DEFAULTS boards/sdkconfig.base)

# Set a default board, if needed and load board.cmake
if(NOT MICROPY_BOARD)
set(MICROPY_BOARD GENERIC)
endif()
include(boards/${MICROPY_BOARD}/board.cmake)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(micropython)
44 changes: 44 additions & 0 deletions ports/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,50 @@ most efficient way to install the ESP32 toolchain and build the project. If
you use WSL then follow the Linux instructions rather than the Windows
instructions.

Over time, you are likely to use multiple versions of esp-idf, for this reason the
recommended set-up is to have top "project" directory under which you will end up with
three subdirectories:
- `esp-idf-vX.Y` for esp-idf and all its submodules/dependencies
- `tools` for the xtensa toolchains and more stuff (this can be shared by multiple
esp-idf versions)
- `micropython` for the micropython source and your builds (down in `ports/esp32/build-XXX`)

The perhaps quickest way to get everything set-up on linux (or Mac?) is:
- Create the project directory and the tools directory
- Fetch a complete esp-idf archive by downloading
`https://github.com/espressif/esp-idf/releases/download/v4.2/esp-idf-v4.2.zip`
and unzip it in you "project" directory, the files will all end up in `./esp-idf-vX.Y`.
You can find zips for alternate esp-idf versions by looking for the "Assets" downloads
in the [release notes on github](https://github.com/espressif/esp-idf/releases).
- Set two environment variables to point to your directories:
`IDF_PATH` -> `/path/to/project/esp-idf-vX.Y` and
`IDF_TOOLS_PATH` -> `/path/to/project/tools`
- Run the esp-idf installer, e.g., `cd esp-idf-vX.Y; ./install.sh` (there are versions for
other shells too). This will download the necessary toolchains and put them into the
`IDF_TOOLS_PATH` directory.
- Finally grab micropython: in your project dir,
`git clone https://github.com/micropython/micropython`
- We now need to fetch a submodule and build `mpy-cross`:
`cd micropython; git submodule update --init lib/berkeley-db-1.xx` and
`make -J4 -C mpy-cross`
- To build micropython prep a build directory:
`cd ports/esp32; mkdir -p build-GENERIC; cd build-GENERIC`
- Let esp-idf add necessary paths to your shell's environment:
`source $IDF_PATH/export.sh` (there are variants for other shells)
- Run cmake to build the makefiles:
`cmake -DMICROPY_BOARD=GENERIC ..`
- And finally build the firmware and flash it to an esp32 attached to `/dev/ttyUSB0`:
`make -J4 flash`

Some alternatives:
- You can find the latest shell commands to build on linux in `tools/ci.sh`, look for the
`ci_esp32_idfXX_XX` functions, these are executed in a setup, prep, build order.
- Instead of fetching the full esp-idf bundle you can follow the instructions
at the [Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/v4.0/get-started/index.html#step-3-set-up-the-tools).

OLD STUF FOLLOWS
================

The ESP-IDF changes quickly and MicroPython only supports certain versions.
The git hash of these versions (one for 3.x, one for 4.x) can be found by
running `make` without a configured `ESPIDF`. Then you can fetch the
Expand Down
5 changes: 5 additions & 0 deletions ports/esp32/boards/GENERIC/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
boards/sdkconfig.ble
boards/sdkconfig.240mhz
)
1 change: 0 additions & 1 deletion ports/esp32/boards/GENERIC/mpconfigboard.mk

This file was deleted.

4 changes: 4 additions & 0 deletions ports/esp32/boards/GENERIC_D2WD/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
boards/sdkconfig.2mib
)
5 changes: 0 additions & 5 deletions ports/esp32/boards/GENERIC_D2WD/mpconfigboard.mk

This file was deleted.

5 changes: 5 additions & 0 deletions ports/esp32/boards/GENERIC_OTA/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
boards/sdkconfig.ble
boards/sdkconfig.ota
)
4 changes: 0 additions & 4 deletions ports/esp32/boards/GENERIC_OTA/mpconfigboard.mk

This file was deleted.

4 changes: 0 additions & 4 deletions ports/esp32/boards/GENERIC_OTA/sdkconfig.board

This file was deleted.

2 changes: 0 additions & 2 deletions ports/esp32/boards/GENERIC_SPIRAM/mpconfigboard.mk

This file was deleted.

1 change: 1 addition & 0 deletions ports/esp32/boards/GENERIC_SPIRAM/sdkconfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(SDKCONFIG_DEFAULTS boards/sdkconfig.base;boards/sdkconfig.spiram)
17 changes: 17 additions & 0 deletions ports/esp32/boards/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ESP32 Board configurations
==========================

- `GENERIC` should work for most basic esp32 boards. It includes all functionality but ends up pretty
tight in memory. Also consider adding sdkconfig.fast for better performance, unless your esp32
chip is ancient or uses an odd xtal. Note that this build, as well as all others that include
bluetooth, disables one core, i.e., everything runs on `core_0` and `core_1` is turned off.
- `GENERIC_D2WD` is for boards using the esp32-d2wd chip, which has 2MB flash inside and thus needs
a different partition map. This chip is not very common.
- `GENERIC_OTA` is a variant of `GENERIC` with a partition table that supports two firmware
partitions, thereby enabling Over-The-Air updates. The filesystem is correspondingly a bit
smaller.
- `TINYPICO` is [https://www.tinypico.com](a tiny board) that contains an esp32-pico-d4, which has
4MB flash on the chip. The board also supports SPIRAM and that is enabled.
- `TOOTHLESS_OTA` is for most esp32 boards but excludes Bluetooth functionality. This frees up
some memory (especially for esp-idf and networking) and enables both cores. It also runs the
flash chip at 80Mhz in QIO mode, which may be incompatible with some non-espressif boards.
9 changes: 9 additions & 0 deletions ports/esp32/boards/TINYPICO/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
boards/sdkconfig.ble
boards/sdkconfig.240mhz
boards/sdkconfig.fast
boards/sdkconfig.spiram
)

set(MICROPY_FROZEN_MANIFEST ${BOARD_DIR}/manifest.py)
8 changes: 0 additions & 8 deletions ports/esp32/boards/TINYPICO/mpconfigboard.mk

This file was deleted.

4 changes: 0 additions & 4 deletions ports/esp32/boards/TINYPICO/sdkconfig.board

This file was deleted.

7 changes: 7 additions & 0 deletions ports/esp32/boards/TOOTHLESS_OTA/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
boards/sdkconfig.240mhz
boards/sdkconfig.fast
)

set(TOOTHLESS 1) # no bluetooth support
2 changes: 2 additions & 0 deletions ports/esp32/boards/TOOTHLESS_OTA/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define MICROPY_HW_BOARD_NAME "4MB/OTA NO-BT module"
#define MICROPY_HW_MCU_NAME "ESP32"
4 changes: 3 additions & 1 deletion ports/esp32/boards/sdkconfig.240mhz
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# MicroPython on ESP32, ESP IDF configuration with 240MHz CPU
# Run the esp32 at 240Mhz instead of the default 160Mhz.
# The 160Mhz default comes from the esp-idf default... But 240Mhz is in spec, the
# main downside is that it uses a bit more power.
CONFIG_ESP32_DEFAULT_CPU_FREQ_80=
CONFIG_ESP32_DEFAULT_CPU_FREQ_160=
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
Expand Down
2 changes: 2 additions & 0 deletions ports/esp32/boards/sdkconfig.2mib
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Partition table for 2MiB flash.
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-2MiB.csv"
31 changes: 11 additions & 20 deletions ports/esp32/boards/sdkconfig.base
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# MicroPython on ESP32, ESP IDF configuration
# The following options override the defaults
# The following options override the esp-idf's sdkconfig defaults

CONFIG_IDF_TARGET="esp32"
CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000

# Application manager
# Application manager - MicroPython doesn't use the application versioning of esp-idf.
CONFIG_APP_EXCLUDE_PROJECT_VER_VAR=y
CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR=y

# Bootloader config
# Bootloader config - Keep the bootloader quiet.
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y

# Change default log level to "ERROR" (instead of "INFO")
CONFIG_LOG_DEFAULT_LEVEL_INFO=n
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
CONFIG_LOG_DEFAULT_LEVEL=1
# Change default log level to reduce chatter at boot and when turning wifi or BLE on/off.
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=n # enable to see how flash/psram is inited
CONFIG_LOG_DEFAULT_LEVEL_INFO=n # enable to see boot/wifi/ble chatter
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
CONFIG_LOG_DEFAULT_LEVEL_ERROR=n
#CONFIG_LOG_DEFAULT_LEVEL=2 # 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG

# ESP32-specific
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
Expand All @@ -35,24 +37,13 @@ CONFIG_LWIP_PPP_PAP_SUPPORT=y
CONFIG_LWIP_PPP_CHAP_SUPPORT=y

# SSL
# Use 4kiB output buffer instead of default 16kiB (because IDF heap is fragmented in 4.0)
# Use 4kiB output buffer instead of default 16kiB (because IDF heap is tight).
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y

# ULP coprocessor support
CONFIG_ESP32_ULP_COPROC_ENABLED=y

# v3.3-only (renamed in 4.0)
CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
CONFIG_SUPPORT_STATIC_ALLOCATION=y
CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK=y
CONFIG_PPP_SUPPORT=y
CONFIG_PPP_PAP_SUPPORT=y
CONFIG_PPP_CHAP_SUPPORT=y
CONFIG_ULP_COPROC_ENABLED=y

# For cmake build
# Ensure cmake uses the right partition map
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
17 changes: 8 additions & 9 deletions ports/esp32/boards/sdkconfig.ble
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n
CONFIG_BT_NIMBLE_PINNED_TO_CORE=0

# v3.3-only (renamed in 4.0)
CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=y
CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY=
CONFIG_BTDM_CONTROLLER_MODE_BTDM=
CONFIG_BLUEDROID_ENABLED=n
CONFIG_NIMBLE_ENABLED=y
CONFIG_NIMBLE_MAX_CONNECTIONS=4
CONFIG_NIMBLE_PINNED_TO_CORE_0=n
CONFIG_NIMBLE_PINNED_TO_CORE_1=y
CONFIG_WIFI_IRAM_OPT=n
CONFIG_WIFI_RX_IRAM_OPT=n
CONFIG_FREERTOS_UNICORE=y
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=n
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=n
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=n
15 changes: 15 additions & 0 deletions ports/esp32/boards/sdkconfig.fast
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Remove work-arounds for ancient silicon
# Use esptool.py chip_id to get your chip's revision, ex: Chip is ESP32D0WDQ6 (revision 1)
CONFIG_ESP32_REV_MIN_0=n
CONFIG_ESP32_REV_MIN_1=y

# Set flash to 80Mhz and QIO, all WROOM/WROVER modules should support that, some 3rd-party
# modules/boards may not. Enabling CONFIG_LOG_DEFAULT_LEVEL_INFO in sdkconfig.base will
# tell you what esp-idf actually configures.
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y

# Set SPIRAM to 80Mhz. This should works with all SPIRAM chips out there, but it does
# tie up either the HSPI or VSPI controller, check the esp-idf docs.
# This setting has no effect if SPIRAM is not enabled using sdkconfig.spiram.
CONFIG_SPIRAM_SPEED_80M=y
6 changes: 6 additions & 0 deletions ports/esp32/boards/sdkconfig.ota
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Enable the rollback of the app so a failing OTA can be reverted.
# See esp-idf docs.
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y

# Partition table with two app partitions to enable OTA.
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-ota.csv"
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy