From cfea71da507b5f40e86d81efd7ac24c4acd73b27 Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 28 Sep 2025 13:52:22 +0200 Subject: [PATCH] esp32/boards: Add new board variant for esp32c2 devices with 2MiB flash. Factors out the space-saving config options from `sdkconfig.d2wd` to a new `sdkconfig.flash_2MiB` file, and uses that in the new C2 FLASH_2M variant. Signed-off-by: Florent --- .../ESP32_GENERIC/mpconfigvariant_D2WD.cmake | 1 + ports/esp32/boards/ESP32_GENERIC/sdkconfig.d2wd | 16 +--------------- ports/esp32/boards/ESP32_GENERIC_C2/board.json | 3 +++ ports/esp32/boards/ESP32_GENERIC_C2/board.md | 2 ++ .../boards/ESP32_GENERIC_C2/mpconfigboard.h | 5 +++++ .../mpconfigvariant_FLASH_2M.cmake | 10 ++++++++++ ports/esp32/boards/sdkconfig.flash_2MiB | 17 +++++++++++++++++ 7 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 ports/esp32/boards/ESP32_GENERIC_C2/mpconfigvariant_FLASH_2M.cmake create mode 100644 ports/esp32/boards/sdkconfig.flash_2MiB diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake index 170c214bda..ec9998cfa5 100644 --- a/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigvariant_D2WD.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} + boards/sdkconfig.flash_2MiB boards/ESP32_GENERIC/sdkconfig.d2wd ) diff --git a/ports/esp32/boards/ESP32_GENERIC/sdkconfig.d2wd b/ports/esp32/boards/ESP32_GENERIC/sdkconfig.d2wd index 2ac983693d..017a6c7729 100644 --- a/ports/esp32/boards/ESP32_GENERIC/sdkconfig.d2wd +++ b/ports/esp32/boards/ESP32_GENERIC/sdkconfig.d2wd @@ -1,17 +1,3 @@ -# Optimise using -Os to reduce size -CONFIG_COMPILER_OPTIMIZATION_SIZE=y -CONFIG_COMPILER_OPTIMIZATION_PERF=n -CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y - -# Change maximum log level to error, to reduce firmware size. -CONFIG_LOG_MAXIMUM_LEVEL_ERROR=y -CONFIG_LOG_MAXIMUM_LEVEL_INFO=n - -# Disable SPI Ethernet driver to reduce firmware size. -CONFIG_ETH_USE_SPI_ETHERNET=n - +# Setting specific to d2wd CONFIG_ESPTOOLPY_FLASHMODE_DIO=y CONFIG_ESPTOOLPY_FLASHFREQ_40M=y -CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-2MiB.csv" diff --git a/ports/esp32/boards/ESP32_GENERIC_C2/board.json b/ports/esp32/boards/ESP32_GENERIC_C2/board.json index da0931a0e4..c496396ef1 100644 --- a/ports/esp32/boards/ESP32_GENERIC_C2/board.json +++ b/ports/esp32/boards/ESP32_GENERIC_C2/board.json @@ -18,5 +18,8 @@ "product": "ESP32-C2", "thumbnail": "", "url": "https://www.espressif.com/en/products/modules", + "variants": { + "FLASH_2M": "2MiB flash" + }, "vendor": "Espressif" } diff --git a/ports/esp32/boards/ESP32_GENERIC_C2/board.md b/ports/esp32/boards/ESP32_GENERIC_C2/board.md index b8ed10069f..7c5c295a44 100644 --- a/ports/esp32/boards/ESP32_GENERIC_C2/board.md +++ b/ports/esp32/boards/ESP32_GENERIC_C2/board.md @@ -1,3 +1,5 @@ The following files are firmware images that should work on most ESP32-C2-based boards with at least 4MiB of flash and 26MHz crystal frequency. This includes ESP8684-WROOM and ESP8684-MINI modules. + +If your board has only 2MiB of flash, you should try the FLASH\_2M variant diff --git a/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigboard.h b/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigboard.h index 999465373e..300ddb0e23 100644 --- a/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigboard.h +++ b/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigboard.h @@ -1,7 +1,12 @@ // This configuration is for a generic ESP32C2 board with 4MiB (or more) of flash. +#ifndef MICROPY_HW_BOARD_NAME #define MICROPY_HW_BOARD_NAME "ESP32C2 module" +#endif + +#ifndef MICROPY_HW_MCU_NAME #define MICROPY_HW_MCU_NAME "ESP32C2" +#endif #define MICROPY_HW_ENABLE_SDCARD (0) #define MICROPY_PY_MACHINE_I2S (0) diff --git a/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigvariant_FLASH_2M.cmake b/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigvariant_FLASH_2M.cmake new file mode 100644 index 0000000000..74af633db2 --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC_C2/mpconfigvariant_FLASH_2M.cmake @@ -0,0 +1,10 @@ +set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/sdkconfig.flash_2MiB +) + +list(APPEND MICROPY_DEF_BOARD + MICROPY_HW_BOARD_NAME="Generic ESP32-C2 module with 2MiB Flash" + MICROPY_OPT_COMPUTED_GOTO=0 + MICROPY_PY_NETWORK_LAN=0 +) diff --git a/ports/esp32/boards/sdkconfig.flash_2MiB b/ports/esp32/boards/sdkconfig.flash_2MiB new file mode 100644 index 0000000000..5239fbd4f1 --- /dev/null +++ b/ports/esp32/boards/sdkconfig.flash_2MiB @@ -0,0 +1,17 @@ +# Set flash size to 2MiB. +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=n +CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-2MiB.csv" + +# Disable SPI Ethernet driver to reduce firmware size. +CONFIG_ETH_USE_SPI_ETHERNET=n + +# Optimise using -Os to reduce size. +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_PERF=n +CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y + +# Change maximum log level to error, to reduce firmware size. +CONFIG_LOG_MAXIMUM_LEVEL_ERROR=y +CONFIG_LOG_MAXIMUM_LEVEL_INFO=n