Skip to content

Move penv setup out of main.py / invert mcu detection logic #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions builder/frameworks/_embed_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
Import("env")

board = env.BoardConfig()
mcu = board.get("build.mcu", "esp32")
is_xtensa = mcu in ("esp32", "esp32s2", "esp32s3")

#
# Embedded files helpers
Expand Down Expand Up @@ -101,23 +103,22 @@ def transform_to_asm(target, source, env):
files = [join("$BUILD_DIR", s.name + ".S") for s in source]
return files, source


mcu = board.get("build.mcu", "esp32")

env.Append(
BUILDERS=dict(
TxtToBin=Builder(
action=env.VerboseAction(
" ".join(
[
"riscv32-esp-elf-objcopy"
if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4")
else "xtensa-%s-elf-objcopy" % mcu,
if not is_xtensa
else f"xtensa-{mcu}-elf-objcopy",
"--input-target",
"binary",
"--output-target",
"elf32-littleriscv" if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4") else "elf32-xtensa-le",
"elf32-littleriscv" if not is_xtensa else "elf32-xtensa-le",
"--binary-architecture",
"riscv" if mcu in ("esp32c2","esp32c3","esp32c5","esp32c6","esp32h2","esp32p4") else "xtensa",
"riscv" if not is_xtensa else "xtensa",
"--rename-section",
".data=.rodata.embedded",
"$SOURCE",
Expand Down
21 changes: 12 additions & 9 deletions builder/frameworks/ulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,35 @@
BUILD_DIR, "esp-idf", project_config["name"].replace("__idf_", ""), "ulp_main"
)

is_xtensa = idf_variant in ("esp32", "esp32s2", "esp32s3")

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

toolchain_path = platform.get_package_dir(
"toolchain-xtensa-esp-elf"
if idf_variant not in ("esp32c5","esp32c6", "esp32p4")
if is_xtensa
else "toolchain-riscv32-esp"
)

toolchain_path_ulp = platform.get_package_dir(
"toolchain-esp32ulp"
if sdk_config.get("ULP_COPROC_TYPE_FSM", False)
else ""
else None
)

python_dir = os.path.dirname(ulp_env.subst("$PYTHONEXE")) or ""
additional_packages = [
toolchain_path,
toolchain_path_ulp,
platform.get_package_dir("tool-ninja"),
os.path.join(platform.get_package_dir("tool-cmake"), "bin"),
os.path.dirname(where_is_program("python")),
python_dir,
]

for package in additional_packages:
ulp_env.PrependENVPath("PATH", package)
if package and os.path.isdir(package):
ulp_env.PrependENVPath("PATH", package)


def collect_ulp_sources():
Expand Down Expand Up @@ -85,17 +88,17 @@ def _generate_ulp_configuration_action(env, target, source):
riscv_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_RISCV", False)
lp_core_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False)

if lp_core_ulp_enabled == False:
if not lp_core_ulp_enabled:
ulp_toolchain = "toolchain-%sulp%s.cmake"% (
"" if riscv_ulp_enabled else idf_variant + "-",
"-riscv" if riscv_ulp_enabled else "",
)
else:
ulp_toolchain = "toolchain-lp-core-riscv.cmake"

comp_includes = ";".join(get_component_includes(target_config))
plain_includes = ";".join(app_includes["plain_includes"])
comp_includes = comp_includes + plain_includes
comp_includes_list = get_component_includes(target_config)
plain_includes_list = app_includes["plain_includes"]
comp_includes = ";".join(comp_includes_list + plain_includes_list)

cmd = (
os.path.join(platform.get_package_dir("tool-cmake"), "bin", "cmake"),
Expand All @@ -112,7 +115,7 @@ def _generate_ulp_configuration_action(env, target, 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=" + comp_includes,
"-DCOMPONENT_INCLUDES=%s" % comp_includes,
"-DIDF_TARGET=%s" % idf_variant,
"-DIDF_PATH=" + fs.to_unix_path(FRAMEWORK_DIR),
"-DSDKCONFIG_HEADER=" + os.path.join(BUILD_DIR, "config", "sdkconfig.h"),
Expand Down
Loading