Skip to content

Commit 43ebbec

Browse files
committed
esp32: Rework board variant support to require mpconfigvariant file.
This commit reworks board variants on the esp32 port. It's a simple change that moves the board variant configuration from an "if" statement within `mpconfigboard.cmake` into separate files for each variant, with the name of the variant encoded in the filename: `mpconfigvariant_VARIANT.cmake`. Optionally, the base variant can have its own options in `mpconfigvariant.cmake` (this is an optional file, but all other variants of the base must have a corresponding mpconfigvariant file). There are two benefits to this: - The build system now gives an error if the variant that you specified doesn't exist (because the mpconfigvariant file must exist with the variant name you specify). - No more error-prone if-logic needed in the .cmake files. The way to build a variant is unchanged, still via: $ make BOARD_VARIANT=VARIANT Signed-off-by: Damien George <[email protected]>
1 parent 3af1425 commit 43ebbec

9 files changed

+60
-66
lines changed

ports/esp32/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
1919
message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
2020
endif()
2121

22+
# If a board variant is specified, check that it exists.
23+
if(MICROPY_BOARD_VARIANT)
24+
if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigvariant_${MICROPY_BOARD_VARIANT}.cmake)
25+
message(FATAL_ERROR "Invalid MICROPY_BOARD_VARIANT specified: ${MICROPY_BOARD_VARIANT}")
26+
endif()
27+
endif()
28+
2229
# Define the output sdkconfig so it goes in the build directory.
2330
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
2431

@@ -35,6 +42,11 @@ endif()
3542
# - SDKCONFIG_DEFAULTS
3643
# - IDF_TARGET
3744
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
45+
if(NOT MICROPY_BOARD_VARIANT)
46+
include(${MICROPY_BOARD_DIR}/mpconfigvariant.cmake OPTIONAL)
47+
else()
48+
include(${MICROPY_BOARD_DIR}/mpconfigvariant_${MICROPY_BOARD_VARIANT}.cmake)
49+
endif()
3850

3951
# Set the frozen manifest file. Note if MICROPY_FROZEN_MANIFEST is set from the cmake
4052
# command line, then it will override the default and any manifest set by the board.

ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,3 @@ set(SDKCONFIG_DEFAULTS
33
${SDKCONFIG_IDF_VERSION_SPECIFIC}
44
boards/sdkconfig.ble
55
)
6-
7-
if(MICROPY_BOARD_VARIANT STREQUAL "D2WD")
8-
set(SDKCONFIG_DEFAULTS
9-
${SDKCONFIG_DEFAULTS}
10-
boards/ESP32_GENERIC/sdkconfig.d2wd
11-
)
12-
13-
list(APPEND MICROPY_DEF_BOARD
14-
MICROPY_HW_MCU_NAME="ESP32-D2WD"
15-
# Disable some options to reduce firmware size.
16-
MICROPY_OPT_COMPUTED_GOTO=0
17-
MICROPY_PY_NETWORK_LAN=0
18-
)
19-
endif()
20-
21-
if(MICROPY_BOARD_VARIANT STREQUAL "OTA")
22-
set(SDKCONFIG_DEFAULTS
23-
${SDKCONFIG_DEFAULTS}
24-
boards/ESP32_GENERIC/sdkconfig.ota
25-
)
26-
27-
list(APPEND MICROPY_DEF_BOARD
28-
MICROPY_HW_BOARD_NAME="Generic ESP32 module with OTA"
29-
)
30-
endif()
31-
32-
if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM")
33-
set(SDKCONFIG_DEFAULTS
34-
${SDKCONFIG_DEFAULTS}
35-
boards/sdkconfig.spiram
36-
)
37-
38-
list(APPEND MICROPY_DEF_BOARD
39-
MICROPY_HW_BOARD_NAME="Generic ESP32 module with SPIRAM"
40-
)
41-
endif()
42-
43-
if(MICROPY_BOARD_VARIANT STREQUAL "UNICORE")
44-
set(SDKCONFIG_DEFAULTS
45-
${SDKCONFIG_DEFAULTS}
46-
boards/ESP32_GENERIC/sdkconfig.unicore
47-
)
48-
49-
list(APPEND MICROPY_DEF_BOARD
50-
MICROPY_HW_MCU_NAME="ESP32-UNICORE"
51-
)
52-
endif()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(SDKCONFIG_DEFAULTS
2+
${SDKCONFIG_DEFAULTS}
3+
boards/ESP32_GENERIC/sdkconfig.d2wd
4+
)
5+
6+
list(APPEND MICROPY_DEF_BOARD
7+
MICROPY_HW_MCU_NAME="ESP32-D2WD"
8+
# Disable some options to reduce firmware size.
9+
MICROPY_OPT_COMPUTED_GOTO=0
10+
MICROPY_PY_NETWORK_LAN=0
11+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(SDKCONFIG_DEFAULTS
2+
${SDKCONFIG_DEFAULTS}
3+
boards/ESP32_GENERIC/sdkconfig.ota
4+
)
5+
6+
list(APPEND MICROPY_DEF_BOARD
7+
MICROPY_HW_BOARD_NAME="Generic ESP32 module with OTA"
8+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(SDKCONFIG_DEFAULTS
2+
${SDKCONFIG_DEFAULTS}
3+
boards/sdkconfig.spiram
4+
)
5+
6+
list(APPEND MICROPY_DEF_BOARD
7+
MICROPY_HW_BOARD_NAME="Generic ESP32 module with SPIRAM"
8+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(SDKCONFIG_DEFAULTS
2+
${SDKCONFIG_DEFAULTS}
3+
boards/ESP32_GENERIC/sdkconfig.unicore
4+
)
5+
6+
list(APPEND MICROPY_DEF_BOARD
7+
MICROPY_HW_MCU_NAME="ESP32-UNICORE"
8+
)

ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,3 @@ set(SDKCONFIG_DEFAULTS
88
boards/sdkconfig.spiram_sx
99
boards/ESP32_GENERIC_S3/sdkconfig.board
1010
)
11-
12-
if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM_OCT")
13-
set(SDKCONFIG_DEFAULTS
14-
${SDKCONFIG_DEFAULTS}
15-
boards/sdkconfig.240mhz
16-
boards/sdkconfig.spiram_oct
17-
)
18-
19-
list(APPEND MICROPY_DEF_BOARD
20-
MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM"
21-
)
22-
endif()
23-
24-
if(MICROPY_BOARD_VARIANT STREQUAL "FLASH_4M")
25-
set(SDKCONFIG_DEFAULTS
26-
${SDKCONFIG_DEFAULTS}
27-
boards/ESP32_GENERIC_S3/sdkconfig.flash_4m
28-
)
29-
endif()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(SDKCONFIG_DEFAULTS
2+
${SDKCONFIG_DEFAULTS}
3+
boards/ESP32_GENERIC_S3/sdkconfig.flash_4m
4+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(SDKCONFIG_DEFAULTS
2+
${SDKCONFIG_DEFAULTS}
3+
boards/sdkconfig.240mhz
4+
boards/sdkconfig.spiram_oct
5+
)
6+
7+
list(APPEND MICROPY_DEF_BOARD
8+
MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM"
9+
)

0 commit comments

Comments
 (0)