Skip to content

ports/esp32: Add per-board configs (same as other ports). #4991

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 1 commit 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ user.props
# Generated rst files
######################
genrst/

# Per-board build files
######################
build-*/
45 changes: 38 additions & 7 deletions ports/esp32/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
# Select the board to build for: if not given on the command line,
# then default to GENERIC.
BOARD ?= GENERIC

# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)

BOARD_DIR ?= boards/$(BOARD)
ifeq ($(wildcard $(BOARD_DIR)/.),)
$(error Invalid BOARD specified: $(BOARD_DIR))
endif

include ../../py/mkenv.mk

# Optional (not currently used for ESP32)
-include mpconfigport.mk

ifneq ($(SDKCONFIG),)
$(error Use the BOARD variable instead of SDKCONFIG)
endif

# Expected to set SDKCONFIG
include $(BOARD_DIR)/mpconfigboard.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h

MICROPY_PY_USSL = 0
MICROPY_SSL_AXTLS = 0
Expand All @@ -22,8 +45,7 @@ FLASH_SIZE ?= 4MB
CROSS_COMPILE ?= xtensa-esp32-elf-
OBJDUMP = $(CROSS_COMPILE)objdump

# SDKCONFIG should be overridden to get a different configuration
SDKCONFIG ?= boards/sdkconfig
SDKCONFIG_COMBINED = $(BUILD)/sdkconfig.combined
SDKCONFIG_H = $(BUILD)/sdkconfig.h

# the git hash of the currently supported ESP IDF version
Expand Down Expand Up @@ -127,6 +149,7 @@ CFLAGS_BASE = -std=gnu99 $(CFLAGS_COMMON) -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_co
CFLAGS = $(CFLAGS_BASE) $(INC) $(INC_ESPCOMP)
CFLAGS += -DIDF_VER=\"$(IDF_VER)\"
CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
CFLAGS += -I$(BOARD_DIR)

# this is what ESPIDF uses for c++ compilation
CXXFLAGS = -std=gnu++11 $(CFLAGS_COMMON) $(INC) $(INC_ESPCOMP)
Expand Down Expand Up @@ -198,6 +221,7 @@ SRC_C = \
mpthreadport.c \
machine_rtc.c \
machine_sdcard.c \
$(wildcard $(BOARD_DIR)/*.c) \
$(SRC_MOD)

EXTMOD_SRC_C = $(addprefix extmod/,\
Expand Down Expand Up @@ -239,7 +263,11 @@ SRC_QSTR_AUTO_DEPS +=
################################################################################
# Generate sdkconfig.h from sdkconfig

$(SDKCONFIG_H): $(SDKCONFIG)
$(SDKCONFIG_COMBINED): $(SDKCONFIG)
$(Q)$(MKDIR) -p $(dir $@)
$(Q)$(CAT) $^ > $@

$(SDKCONFIG_H): $(SDKCONFIG_COMBINED)
$(ECHO) "GEN $@"
$(Q)$(MKDIR) -p $(dir $@)
$(Q)$(PYTHON) $(ESPIDF)/tools/kconfig_new/confgen.py \
Expand All @@ -252,7 +280,7 @@ $(SDKCONFIG_H): $(SDKCONFIG)
--env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)"
$(Q)touch $@

$(HEADER_BUILD)/qstrdefs.generated.h: $(SDKCONFIG_H)
$(HEADER_BUILD)/qstrdefs.generated.h: $(SDKCONFIG_H) $(BOARD_DIR)/mpconfigboard.h

################################################################################
# List of object files from the ESP32 IDF components
Expand Down Expand Up @@ -423,12 +451,12 @@ $(eval $(foreach lib,$(LIB_ESPIDF),$(eval $(call gen_sections_info_rule,$(BUILD_
$(LDGEN_SECTION_INFOS): $(LDGEN_SECTIONS_INFO) $(ESPIDF)/make/ldgen.mk
$(Q)printf "$(foreach info,$(LDGEN_SECTIONS_INFO),$(info)\n)" > $@

$(BUILD)/esp32.project.ld: $(ESPCOMP)/esp32/ld/esp32.project.ld.in $(LDGEN_FRAGMENTS) $(SDKCONFIG) $(LDGEN_SECTION_INFOS)
$(BUILD)/esp32.project.ld: $(ESPCOMP)/esp32/ld/esp32.project.ld.in $(LDGEN_FRAGMENTS) $(SDKCONFIG_COMBINED) $(LDGEN_SECTION_INFOS)
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(ESPIDF)/tools/ldgen/ldgen.py \
--input $< \
--output $@ \
--config $(SDKCONFIG) \
--config $(SDKCONFIG_COMBINED) \
--kconfig $(ESPIDF)/Kconfig \
--fragments $(LDGEN_FRAGMENTS) \
--sections $(LDGEN_SECTION_INFOS) \
Expand Down Expand Up @@ -466,6 +494,7 @@ OBJ = $(OBJ_MP)

APP_LD_ARGS =
APP_LD_ARGS += $(LDFLAGS_MOD)
APP_LD_ARGS += $(addprefix -T,$(LD_FILES))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's LD_FILES intended to be used for? The esp32 is very specific about the linking phase, although I guess the user could add some additional bits if they really need to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nevercast asked for it. My guess is that it might be related to the rtc mem stuff.

APP_LD_ARGS += --start-group
APP_LD_ARGS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
APP_LD_ARGS += -L$(dir $(LIBSTDCXX_FILE_NAME)) -lstdc++
Expand Down Expand Up @@ -647,7 +676,9 @@ $(BUILD)/bootloader.elf: $(BOOTLOADER_OBJ) $(addprefix $(BOOTLOADER_LIB_DIR)/lib
# Declarations to build the partitions

PYTHON2 ?= python2
PART_SRC = partitions.csv

# Can be overriden by mkconfigboard.mk.
PART_SRC ?= partitions.csv

$(BUILD)/partitions.bin: $(PART_SRC)
$(ECHO) "Create $@"
Expand Down
20 changes: 11 additions & 9 deletions ports/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ variables for the build. In that case, create a new file in the esp32
directory called `makefile` and add the following lines to that file:
```
ESPIDF = <path to root of esp-idf repository>
BOARD = GENERIC
#PORT = /dev/ttyUSB0
#FLASH_MODE = qio
#FLASH_SIZE = 4MB
#CROSS_COMPILE = xtensa-esp32-elf-
#SDKCONFIG = boards/sdkconfig.spiram

include Makefile
```
Expand All @@ -92,16 +92,18 @@ are `PORT` for the serial port of your esp32 module, and `FLASH_MODE`
(which may need to be `dio` for some modules)
and `FLASH_SIZE`. See the Makefile for further information.

The default ESP IDF configuration settings are provided in the file
`boards/sdkconfig`, and this file is specified in the build by the make
variable `SDKCONFIG`. To use a custom configuration either set `SDKCONFIG`
in your custom `makefile` (or `GNUmakefile`) or set this variable on the
command line:
The default ESP IDF configuration settings are provided by the `GENERIC`
board definition in the directory `boards/GENERIC`. For a custom configuration
you can define your own board directory.

The `BOARD` variable can be set on the make command line:
```bash
$ make SDKCONFIG=sdkconfig.myboard
$ make BOARD=TINYPICO
```
The file `boards/sdkconfig.spiram` is provided for ESP32 modules that have
external SPIRAM.
or added to your custom `makefile` (or `GNUmakefile`) described above. There
is also a `GENERIC_SPIRAM` board for for ESP32 modules that have external
SPIRAM, but prefer to use a specific board target (or define your own as
necessary).

Building the firmware
---------------------
Expand Down
2 changes: 2 additions & 0 deletions ports/esp32/boards/GENERIC/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define MICROPY_HW_BOARD_NAME "ESP32 module"
#define MICROPY_HW_MCU_NAME "ESP32"
1 change: 1 addition & 0 deletions ports/esp32/boards/GENERIC/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SDKCONFIG += boards/sdkconfig.base
2 changes: 2 additions & 0 deletions ports/esp32/boards/GENERIC_SPIRAM/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define MICROPY_HW_BOARD_NAME "ESP32 module (spiram)"
#define MICROPY_HW_MCU_NAME "ESP32"
2 changes: 2 additions & 0 deletions ports/esp32/boards/GENERIC_SPIRAM/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SDKCONFIG += boards/sdkconfig.base
SDKCONFIG += boards/sdkconfig.spiram
2 changes: 2 additions & 0 deletions ports/esp32/boards/TINYPICO/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define MICROPY_HW_BOARD_NAME "TINYPICO"
#define MICROPY_HW_MCU_NAME "ESP32-PICO-D4"
2 changes: 2 additions & 0 deletions ports/esp32/boards/TINYPICO/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SDKCONFIG += boards/sdkconfig.base
SDKCONFIG += boards/sdkconfig.spiram
File renamed without changes.
28 changes: 0 additions & 28 deletions ports/esp32/boards/sdkconfig.spiram
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
# MicroPython on ESP32, ESP IDF configuration with SPIRAM support
# The following options override the defaults

CONFIG_IDF_TARGET="esp32"

# Application manager
CONFIG_APP_EXCLUDE_PROJECT_VER_VAR=y
CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR=y

# Bootloader config
CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y

# ESP32-specific
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
CONFIG_SPIRAM_SUPPORT=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
CONFIG_SPIRAM_USE_MEMMAP=y
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
CONFIG_ESP32_XTAL_FREQ_AUTO=y

# Power Management
CONFIG_PM_ENABLE=y

# FreeRTOS
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
CONFIG_SUPPORT_STATIC_ALLOCATION=y
CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK=y

# UDP
CONFIG_PPP_SUPPORT=y
CONFIG_PPP_PAP_SUPPORT=y
CONFIG_PPP_CHAP_SUPPORT=y
6 changes: 3 additions & 3 deletions ports/esp32/mpconfigport.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Options to control how MicroPython is built for this port,
// overriding defaults in py/mpconfig.h.

// Board-specific definitions
#include "mpconfigboard.h"

#include <stdint.h>
#include <alloca.h>
#include "rom/ets_sys.h"
Expand Down Expand Up @@ -268,7 +271,4 @@ typedef long mp_off_t;
#include <sys/types.h>

// board specifics

#define MICROPY_HW_BOARD_NAME "ESP32 module"
#define MICROPY_HW_MCU_NAME "ESP32"
#define MICROPY_PY_SYS_PLATFORM "esp32"
4 changes: 0 additions & 4 deletions ports/nrf/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
#####################
drivers/bluetooth/s1*/

# Build files
#####################
build-*/

1 change: 0 additions & 1 deletion ports/stm32/.gitignore

This file was deleted.