Skip to content

Commit

Permalink
Merge branch 'platformio:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
DogushC authored Jan 14, 2025
2 parents 858d4e4 + e972aab commit 77f3cfc
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 30 deletions.
52 changes: 46 additions & 6 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,37 @@ def get_idf_venv_dir():

def ensure_python_venv_available():

def _get_idf_venv_python_version():
try:
version = subprocess.check_output(
[
get_python_exe(),
"-c",
"import sys;print('{0}.{1}.{2}-{3}.{4}'.format(*list(sys.version_info)))"
], text=True
)
return version.strip()
except subprocess.CalledProcessError as e:
print("Failed to extract Python version from IDF virtual env!")
return None

def _is_venv_outdated(venv_data_file):
try:
with open(venv_data_file, "r", encoding="utf8") as fp:
venv_data = json.load(fp)
if venv_data.get("version", "") != IDF_ENV_VERSION:
print(
"Warning! IDF virtual environment version changed!"
)
return True
if (
venv_data.get("python_version", "")
!= _get_idf_venv_python_version()
):
print(
"Warning! Python version in the IDF virtual environment"
" differs from the current Python!"
)
return True
return False
except:
Expand Down Expand Up @@ -1387,8 +1413,13 @@ def _create_venv(venv_dir):
venv_data_file = os.path.join(venv_dir, "pio-idf-venv.json")
if not os.path.isfile(venv_data_file) or _is_venv_outdated(venv_data_file):
_create_venv(venv_dir)

install_python_deps()
with open(venv_data_file, "w", encoding="utf8") as fp:
venv_info = {"version": IDF_ENV_VERSION}
venv_info = {
"version": IDF_ENV_VERSION,
"python_version": _get_idf_venv_python_version()
}
json.dump(venv_info, fp, indent=2)


Expand All @@ -1407,11 +1438,10 @@ def get_python_exe():


#
# ESP-IDF requires Python packages with specific versions in a virtual environment
# Ensure Python environment contains everything required for IDF
#

ensure_python_venv_available()
install_python_deps()

# ESP-IDF package doesn't contain .git folder, instead package version is specified
# in a special file "version.h" in the root folder of the package
Expand Down Expand Up @@ -1616,7 +1646,15 @@ def get_python_exe():
# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
# cannot merge them correctly
extra_flags = filter_args(
link_args["LINKFLAGS"], ["-T", "-u", "-Wl,--start-group", "-Wl,--end-group"]
link_args["LINKFLAGS"],
[
"-T",
"-u",
"-Wl,--start-group",
"-Wl,--end-group",
"-Wl,--whole-archive",
"-Wl,--no-whole-archive",
],
)
link_args["LINKFLAGS"] = sorted(list(set(link_args["LINKFLAGS"]) - set(extra_flags)))

Expand Down Expand Up @@ -1804,8 +1842,10 @@ def _skip_prj_source_files(node):
#

ulp_dir = os.path.join(PROJECT_DIR, "ulp")
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c3", "esp32c6"):
env.SConscript("ulp.py", exports="env sdk_config project_config idf_variant")
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu != "esp32c3":
env.SConscript(
"ulp.py", exports="env sdk_config project_config idf_variant"
)

#
# Process OTA partition and image
Expand Down
90 changes: 70 additions & 20 deletions builder/frameworks/ulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
BUILD_DIR = ulp_env.subst("$BUILD_DIR")
ULP_BUILD_DIR = os.path.join(
BUILD_DIR, "esp-idf", project_config["name"].replace("__idf_", ""), "ulp_main"
BUILD_DIR,
"esp-idf",
project_config["name"].replace("__idf_", ""),
"ulp_main",
)


def prepare_ulp_env_vars(env):
ulp_env.PrependENVPath("IDF_PATH", FRAMEWORK_DIR)

toolchain_path = platform.get_package_dir(
"toolchain-xtensa-esp-elf"
if "arduino" not in env.subst("$PIOFRAMEWORK")
else "toolchain-xtensa-%s" % idf_variant
"toolchain-riscv32-esp"
if idf_variant in ("esp32c3", "esp32c6")
else (
(
"toolchain-xtensa-esp-elf"
if "arduino" not in env.subst("$PIOFRAMEWORK")
else "toolchain-xtensa-%s" % idf_variant
)
)
)

additional_packages = [
Expand Down Expand Up @@ -72,9 +81,9 @@ def get_component_includes(target_config):
if source["path"].endswith("ulp_main.bin.S"):
return [
inc["path"]
for inc in target_config["compileGroups"][source["compileGroupIndex"]][
"includes"
]
for inc in target_config["compileGroups"][
source["compileGroupIndex"]
]["includes"]
]

return [os.path.join(BUILD_DIR, "config")]
Expand All @@ -85,29 +94,62 @@ def _generate_ulp_configuration_action(env, target, source):
riscv_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_RISCV", False)

cmd = (
os.path.join(platform.get_package_dir("tool-cmake"), "bin", "cmake"),
os.path.join(
platform.get_package_dir("tool-cmake"), "bin", "cmake"
),
"-DCMAKE_GENERATOR=Ninja",
"-DCMAKE_TOOLCHAIN_FILE="
+ os.path.join(
FRAMEWORK_DIR,
"components",
"ulp",
"cmake",
"toolchain-%sulp%s.cmake"
% (
"" if riscv_ulp_enabled else idf_variant + "-",
"-riscv" if riscv_ulp_enabled else "",
(
"toolchain-lp-core-riscv.cmake"
if sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False)
else "toolchain-%sulp%s.cmake"
% (
"" if riscv_ulp_enabled else idf_variant + "-",
"-riscv" if riscv_ulp_enabled else "",
)
),
),
"-DULP_S_SOURCES=%s" % ";".join([fs.to_unix_path(s.get_abspath()) for s in source]),
"-DULP_S_SOURCES=%s"
% ";".join([fs.to_unix_path(s.get_abspath()) for s in source]),
"-DULP_APP_NAME=ulp_main",
"-DCOMPONENT_DIR=" + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"),
"-DCOMPONENT_INCLUDES=%s" % ";".join(get_component_includes(target_config)),
"-DCOMPONENT_DIR="
+ os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"),
"-DCOMPONENT_INCLUDES=%s"
% ";".join(get_component_includes(target_config)),
"-DIDF_TARGET=%s" % idf_variant,
"-DIDF_PATH=" + fs.to_unix_path(FRAMEWORK_DIR),
"-DSDKCONFIG_HEADER=" + os.path.join(BUILD_DIR, "config", "sdkconfig.h"),
"-DSDKCONFIG_HEADER="
+ os.path.join(BUILD_DIR, "config", "sdkconfig.h"),
"-DPYTHON=" + env.subst("$PYTHONEXE"),
"-DSDKCONFIG_CMAKE=" + os.path.join(BUILD_DIR, "config", "sdkconfig.cmake"),
"-DSDKCONFIG_CMAKE="
+ os.path.join(BUILD_DIR, "config", "sdkconfig.cmake"),
"-DULP_COCPU_IS_RISCV="
+ (
"ON"
if idf_variant in ("esp32s2", "esp32s3")
and sdk_config.get("ULP_COPROC_TYPE_RISCV", False)
else ""
),
"-DULP_COCPU_IS_LP_CORE="
+ (
"ON"
if sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False)
else ""
),
"-DESP_ROM_HAS_LP_ROM="
+ (
"ON"
if sdk_config.get("ESP_ROM_HAS_LP_ROM", False)
else ""
),
"-DCMAKE_MODULE_PATH="
+ fs.to_unix_path(
os.path.join(FRAMEWORK_DIR, "components", "ulp", "cmake")),
"-GNinja",
"-B",
ULP_BUILD_DIR,
Expand Down Expand Up @@ -152,7 +194,9 @@ def compile_ulp_binary():
os.path.join(ULP_BUILD_DIR, "ulp_main.bin"),
],
None,
ulp_binary_env.VerboseAction(" ".join(cmd), "Generating ULP project files $TARGETS"),
ulp_binary_env.VerboseAction(
" ".join(cmd), "Generating ULP project files $TARGETS"
),
)


Expand All @@ -164,14 +208,20 @@ def generate_ulp_assembly():
"-DFILE_TYPE=BINARY",
"-P",
os.path.join(
FRAMEWORK_DIR, "tools", "cmake", "scripts", "data_file_embed_asm.cmake"
FRAMEWORK_DIR,
"tools",
"cmake",
"scripts",
"data_file_embed_asm.cmake",
),
)

return ulp_env.Command(
os.path.join(BUILD_DIR, "ulp_main.bin.S"),
os.path.join(ULP_BUILD_DIR, "ulp_main.bin"),
ulp_env.VerboseAction(" ".join(cmd), "Generating ULP assembly file $TARGET"),
ulp_env.VerboseAction(
" ".join(cmd), "Generating ULP assembly file $TARGET"
),
)


Expand Down
6 changes: 3 additions & 3 deletions platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"optional": true,
"owner": "espressif",
"version": "8.4.0+2021r2-patch5",
"optionalVersions": ["13.2.0+20240530"]
"optionalVersions": ["14.2.0+20241119"]
},
"toolchain-xtensa-esp-elf": {
"type": "toolchain",
"optional": true,
"owner": "platformio",
"version": "13.2.0+20240530"
"version": "14.2.0+20241119"
},
"toolchain-esp32ulp": {
"type": "toolchain",
Expand Down Expand Up @@ -88,7 +88,7 @@
"type": "framework",
"optional": true,
"owner": "platformio",
"version": "~3.50301.0",
"version": "~3.50400.0",
"optionalVersions": ["~3.40407.0"]
},
"tool-esptoolpy": {
Expand Down
2 changes: 1 addition & 1 deletion platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def configure_default_packages(self, variables, targets):
self.packages["toolchain-riscv32-esp"]["owner"] = "platformio"
self.packages["toolchain-riscv32-esp"][
"version"
] = "13.2.0+20240530"
] = "14.2.0+20241119"

if "arduino" in frameworks:
# Disable standalone GDB packages for Arduino and Arduino/IDF projects
Expand Down

0 comments on commit 77f3cfc

Please sign in to comment.