From feffc0ea856c108d3564f59352fb07ef4a1725e4 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sat, 9 Nov 2024 14:27:16 +0100 Subject: [PATCH] Hybrid compile: add sdkconfig settings to boards manifest (#103) --- boards/esp32-solo1.json | 5 +++++ builder/frameworks/espidf.py | 31 ++++++++++++++++++--------- examples/arduino-blink/platformio.ini | 6 ------ platform.py | 5 +++-- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/boards/esp32-solo1.json b/boards/esp32-solo1.json index 9f3659e8d..906772ba4 100644 --- a/boards/esp32-solo1.json +++ b/boards/esp32-solo1.json @@ -29,6 +29,11 @@ "require_upload_port": true, "speed": 460800 }, + "espidf": { + "custom_sdkconfig": [ + "CONFIG_FREERTOS_UNICORE=y" + ] + }, "url": "https://en.wikipedia.org/wiki/ESP32", "vendor": "Espressif" } diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 808370926..5854c230e 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -177,25 +177,36 @@ def _get_installed_standard_pip_packages(): # # generate modified Arduino IDF sdkconfig, applying settings from "custom_sdkconfig" # -if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): - flag_custom_sdkonfig = True - if config.has_option("env:"+env["PIOENV"], "custom_component_add"): flag_custom_component_add = True - if config.has_option("env:"+env["PIOENV"], "custom_component_remove"): flag_custom_component_remove = True - + +if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): + flag_custom_sdkonfig = True +if "espidf.custom_sdkconfig" in board: + flag_custom_sdkonfig = True def HandleArduinoIDFsettings(env): def get_MD5_hash(phrase): import hashlib return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16] - if flag_custom_sdkonfig == True: + custom_sdk_config_flags = "" + board_idf_config_flags = "" + + if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): + flag_custom_sdkonfig = True + custom_sdk_config_flags = (env.GetProjectOption("custom_sdkconfig").rstrip("\n")) + "\n" + + if "espidf.custom_sdkconfig" in board: + board_idf_config_flags = ('\n'.join([element for element in board.get("espidf.custom_sdkconfig", "")])).rstrip("\n") + "\n" + flag_custom_sdkonfig = True + + if flag_custom_sdkonfig == True: # TDOO duplicated print("*** Add \"custom_sdkconfig\" settings to IDF sdkconfig.defaults ***") - idf_config_flags = env.GetProjectOption("custom_sdkconfig") - idf_config_flags = idf_config_flags + "\n" + idf_config_flags = custom_sdk_config_flags + idf_config_flags = idf_config_flags + board_idf_config_flags if flash_frequency != "80m": idf_config_flags = idf_config_flags + "# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set\n" esptool_flashfreq_y = "CONFIG_ESPTOOLPY_FLASHFREQ_%s=y\n" % flash_frequency.upper() @@ -223,7 +234,7 @@ def get_flag(line): with open(sdkconfig_src) as src: sdkconfig_dst = os.path.join(PROJECT_DIR, "sdkconfig.defaults") dst = open(sdkconfig_dst,"w") - dst.write("# TASMOTA__"+ get_MD5_hash(env.GetProjectOption("custom_sdkconfig").strip() + mcu) +"\n") + dst.write("# TASMOTA__"+ get_MD5_hash(''.join(custom_sdk_config_flags).strip() + mcu) +"\n") while line := src.readline(): flag = get_flag(line) if flag is None: @@ -319,7 +330,7 @@ def HandleCOMPONENTsettings(env): if flag_custom_component_add == True or flag_custom_component_remove == True: HandleCOMPONENTsettings(env) -if flag_custom_sdkonfig and "arduino" in env.subst("$PIOFRAMEWORK"): +if flag_custom_sdkonfig == True and "arduino" in env.subst("$PIOFRAMEWORK"): HandleArduinoIDFsettings(env) LIB_SOURCE = os.path.join(env.subst("$PROJECT_CORE_DIR"), "platforms", "espressif32", "builder", "build_lib") if not bool(os.path.exists(os.path.join(PROJECT_DIR, ".dummy"))): diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini index 094a57d6f..dd1614276 100644 --- a/examples/arduino-blink/platformio.ini +++ b/examples/arduino-blink/platformio.ini @@ -12,16 +12,10 @@ platform = espressif32 framework = arduino board = esp32-solo1 build_flags = -DLED_BUILTIN=2 -custom_sdkconfig = CONFIG_FREERTOS_UNICORE=y - '# CONFIG_BT_ENABLED is not set' - '# CONFIG_ULP_COPROC_ENABLED is not set' - '# CONFIG_LWIP_PPP_SUPPORT is not set' - '# CONFIG_ETH_ENABLED is not set' custom_component_remove = espressif/esp_hosted espressif/esp_wifi_remote espressif/mdns espressif/esp-dsp - espressif/esp_modem espressif/esp32-camera [env:esp32-s3-120] diff --git a/platform.py b/platform.py index 254892042..37fc9eec9 100644 --- a/platform.py +++ b/platform.py @@ -37,12 +37,13 @@ def configure_default_packages(self, variables, targets): board_config = self.board_config(variables.get("board")) mcu = variables.get("board_build.mcu", board_config.get("build.mcu", "esp32")) + board_sdkconfig = variables.get("board_espidf.custom_sdkconfig", board_config.get("espidf.custom_sdkconfig", "")) core_variant_board = ''.join(variables.get("board_build.extra_flags", board_config.get("build.extra_flags", ""))) core_variant_board = core_variant_board.replace("-D", " ") core_variant_build = (''.join(variables.get("build_flags", []))).replace("-D", " ") frameworks = variables.get("pioframework", []) - if "arduino" in frameworks and variables.get("custom_sdkconfig") is None: + if "arduino" in frameworks and variables.get("custom_sdkconfig") is None and len(str(board_sdkconfig)) < 3: if "CORE32SOLO1" in core_variant_board or "FRAMEWORK_ARDUINO_SOLO1" in core_variant_build: self.packages["framework-arduino-solo1"]["optional"] = False elif "CORE32ITEAD" in core_variant_board or "FRAMEWORK_ARDUINO_ITEAD" in core_variant_build: @@ -50,7 +51,7 @@ def configure_default_packages(self, variables, targets): else: self.packages["framework-arduinoespressif32"]["optional"] = False - if variables.get("custom_sdkconfig") is not None: + if variables.get("custom_sdkconfig") is not None or len(str(board_sdkconfig)) > 3: frameworks.append("espidf") self.packages["framework-espidf"]["optional"] = False self.packages["framework-arduinoespressif32"]["optional"] = False