diff options
author | Damien George <damien@micropython.org> | 2024-06-05 22:48:16 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-06-28 11:23:55 +1000 |
commit | 43ebbec0c5c7a1b404ffdc738a8ab5f6fa0250cd (patch) | |
tree | 829c1a52b21ad1814d75fa92912a9894dcc0368c | |
parent | 3af1425be7a786f79fe02902ca2f6079bacde809 (diff) |
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 <damien@micropython.org>
9 files changed, 60 insertions, 66 deletions
diff --git a/ports/esp32/CMakeLists.txt b/ports/esp32/CMakeLists.txt index 3fe083002..d3927cd48 100644 --- a/ports/esp32/CMakeLists.txt +++ b/ports/esp32/CMakeLists.txt @@ -19,6 +19,13 @@ if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake) message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}") endif() +# If a board variant is specified, check that it exists. +if(MICROPY_BOARD_VARIANT) + if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigvariant_${MICROPY_BOARD_VARIANT}.cmake) + message(FATAL_ERROR "Invalid MICROPY_BOARD_VARIANT specified: ${MICROPY_BOARD_VARIANT}") + endif() +endif() + # Define the output sdkconfig so it goes in the build directory. set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) @@ -35,6 +42,11 @@ endif() # - SDKCONFIG_DEFAULTS # - IDF_TARGET include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) +if(NOT MICROPY_BOARD_VARIANT) + include(${MICROPY_BOARD_DIR}/mpconfigvariant.cmake OPTIONAL) +else() + include(${MICROPY_BOARD_DIR}/mpconfigvariant_${MICROPY_BOARD_VARIANT}.cmake) +endif() # Set the frozen manifest file. Note if MICROPY_FROZEN_MANIFEST is set from the cmake # command line, then it will override the default and any manifest set by the board. diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake index a3e8f616b..9d0077a15 100644 --- a/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake @@ -3,50 +3,3 @@ set(SDKCONFIG_DEFAULTS ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble ) - -if(MICROPY_BOARD_VARIANT STREQUAL "D2WD") - set(SDKCONFIG_DEFAULTS - ${SDKCONFIG_DEFAULTS} - boards/ESP32_GENERIC/sdkconfig.d2wd - ) - - list(APPEND MICROPY_DEF_BOARD - MICROPY_HW_MCU_NAME="ESP32-D2WD" - # Disable some options to reduce firmware size. - MICROPY_OPT_COMPUTED_GOTO=0 - MICROPY_PY_NETWORK_LAN=0 - ) -endif() - -if(MICROPY_BOARD_VARIANT STREQUAL "OTA") - set(SDKCONFIG_DEFAULTS - ${SDKCONFIG_DEFAULTS} - boards/ESP32_GENERIC/sdkconfig.ota - ) - - list(APPEND MICROPY_DEF_BOARD - MICROPY_HW_BOARD_NAME="Generic ESP32 module with OTA" - ) -endif() - -if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM") - set(SDKCONFIG_DEFAULTS - ${SDKCONFIG_DEFAULTS} - boards/sdkconfig.spiram - ) - - list(APPEND MICROPY_DEF_BOARD - MICROPY_HW_BOARD_NAME="Generic ESP32 module with SPIRAM" - ) -endif() - -if(MICROPY_BOARD_VARIANT STREQUAL "UNICORE") - set(SDKCONFIG_DEFAULTS - ${SDKCONFIG_DEFAULTS} - boards/ESP32_GENERIC/sdkconfig.unicore - ) - - list(APPEND MICROPY_DEF_BOARD - MICROPY_HW_MCU_NAME="ESP32-UNICORE" - ) -endif() diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake new file mode 100644 index 000000000..170c214bd --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake @@ -0,0 +1,11 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/ESP32_GENERIC/sdkconfig.d2wd +) + +list(APPEND MICROPY_DEF_BOARD + MICROPY_HW_MCU_NAME="ESP32-D2WD" + # Disable some options to reduce firmware size. + MICROPY_OPT_COMPUTED_GOTO=0 + MICROPY_PY_NETWORK_LAN=0 +) diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_OTA.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_OTA.cmake new file mode 100644 index 000000000..7f649c36f --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_OTA.cmake @@ -0,0 +1,8 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/ESP32_GENERIC/sdkconfig.ota +) + +list(APPEND MICROPY_DEF_BOARD + MICROPY_HW_BOARD_NAME="Generic ESP32 module with OTA" +) diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_SPIRAM.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_SPIRAM.cmake new file mode 100644 index 000000000..11e9c4eda --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_SPIRAM.cmake @@ -0,0 +1,8 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/sdkconfig.spiram +) + +list(APPEND MICROPY_DEF_BOARD + MICROPY_HW_BOARD_NAME="Generic ESP32 module with SPIRAM" +) diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_UNICORE.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_UNICORE.cmake new file mode 100644 index 000000000..beed6eb09 --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_UNICORE.cmake @@ -0,0 +1,8 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/ESP32_GENERIC/sdkconfig.unicore +) + +list(APPEND MICROPY_DEF_BOARD + MICROPY_HW_MCU_NAME="ESP32-UNICORE" +) diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake index 1f7440353..2bfdad21d 100644 --- a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake @@ -8,22 +8,3 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.spiram_sx boards/ESP32_GENERIC_S3/sdkconfig.board ) - -if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM_OCT") - set(SDKCONFIG_DEFAULTS - ${SDKCONFIG_DEFAULTS} - boards/sdkconfig.240mhz - boards/sdkconfig.spiram_oct - ) - - list(APPEND MICROPY_DEF_BOARD - MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM" - ) -endif() - -if(MICROPY_BOARD_VARIANT STREQUAL "FLASH_4M") - set(SDKCONFIG_DEFAULTS - ${SDKCONFIG_DEFAULTS} - boards/ESP32_GENERIC_S3/sdkconfig.flash_4m - ) -endif() diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigvariant_FLASH_4M.cmake b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigvariant_FLASH_4M.cmake new file mode 100644 index 000000000..e832cdb60 --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigvariant_FLASH_4M.cmake @@ -0,0 +1,4 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/ESP32_GENERIC_S3/sdkconfig.flash_4m +) diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigvariant_SPIRAM_OCT.cmake b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigvariant_SPIRAM_OCT.cmake new file mode 100644 index 000000000..8b2eda272 --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigvariant_SPIRAM_OCT.cmake @@ -0,0 +1,9 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/sdkconfig.240mhz + boards/sdkconfig.spiram_oct +) + +list(APPEND MICROPY_DEF_BOARD + MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM" +) |