Skip to content

Commit 1442a35

Browse files
committed
Update ULP build script
- Added support for ESP32-C6 ULP - Updates according to changes in IDF v5.4.0 Resolves #1507
1 parent aab73c6 commit 1442a35

File tree

2 files changed

+74
-22
lines changed

2 files changed

+74
-22
lines changed

builder/frameworks/espidf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,8 +1804,10 @@ def _skip_prj_source_files(node):
18041804
#
18051805

18061806
ulp_dir = os.path.join(PROJECT_DIR, "ulp")
1807-
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c3", "esp32c6"):
1808-
env.SConscript("ulp.py", exports="env sdk_config project_config idf_variant")
1807+
if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu != "esp32c3":
1808+
env.SConscript(
1809+
"ulp.py", exports="env sdk_config project_config idf_variant"
1810+
)
18091811

18101812
#
18111813
# Process OTA partition and image

builder/frameworks/ulp.py

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,26 @@
2828
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
2929
BUILD_DIR = ulp_env.subst("$BUILD_DIR")
3030
ULP_BUILD_DIR = os.path.join(
31-
BUILD_DIR, "esp-idf", project_config["name"].replace("__idf_", ""), "ulp_main"
31+
BUILD_DIR,
32+
"esp-idf",
33+
project_config["name"].replace("__idf_", ""),
34+
"ulp_main",
3235
)
3336

3437

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

3841
toolchain_path = platform.get_package_dir(
39-
"toolchain-xtensa-esp-elf"
40-
if "arduino" not in env.subst("$PIOFRAMEWORK")
41-
else "toolchain-xtensa-%s" % idf_variant
42+
"toolchain-riscv32-esp"
43+
if idf_variant in ("esp32c3", "esp32c6")
44+
else (
45+
(
46+
"toolchain-xtensa-esp-elf"
47+
if "arduino" not in env.subst("$PIOFRAMEWORK")
48+
else "toolchain-xtensa-%s" % idf_variant
49+
)
50+
)
4251
)
4352

4453
additional_packages = [
@@ -72,9 +81,9 @@ def get_component_includes(target_config):
7281
if source["path"].endswith("ulp_main.bin.S"):
7382
return [
7483
inc["path"]
75-
for inc in target_config["compileGroups"][source["compileGroupIndex"]][
76-
"includes"
77-
]
84+
for inc in target_config["compileGroups"][
85+
source["compileGroupIndex"]
86+
]["includes"]
7887
]
7988

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

8796
cmd = (
88-
os.path.join(platform.get_package_dir("tool-cmake"), "bin", "cmake"),
97+
os.path.join(
98+
platform.get_package_dir("tool-cmake"), "bin", "cmake"
99+
),
89100
"-DCMAKE_GENERATOR=Ninja",
90101
"-DCMAKE_TOOLCHAIN_FILE="
91102
+ os.path.join(
92103
FRAMEWORK_DIR,
93104
"components",
94105
"ulp",
95106
"cmake",
96-
"toolchain-%sulp%s.cmake"
97-
% (
98-
"" if riscv_ulp_enabled else idf_variant + "-",
99-
"-riscv" if riscv_ulp_enabled else "",
107+
(
108+
"toolchain-lp-core-riscv.cmake"
109+
if sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False)
110+
else "toolchain-%sulp%s.cmake"
111+
% (
112+
"" if riscv_ulp_enabled else idf_variant + "-",
113+
"-riscv" if riscv_ulp_enabled else "",
114+
)
100115
),
101116
),
102-
"-DULP_S_SOURCES=%s" % ";".join([fs.to_unix_path(s.get_abspath()) for s in source]),
117+
"-DULP_S_SOURCES=%s"
118+
% ";".join([fs.to_unix_path(s.get_abspath()) for s in source]),
103119
"-DULP_APP_NAME=ulp_main",
104-
"-DCOMPONENT_DIR=" + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"),
105-
"-DCOMPONENT_INCLUDES=%s" % ";".join(get_component_includes(target_config)),
120+
"-DCOMPONENT_DIR="
121+
+ os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"),
122+
"-DCOMPONENT_INCLUDES=%s"
123+
% ";".join(get_component_includes(target_config)),
106124
"-DIDF_TARGET=%s" % idf_variant,
107125
"-DIDF_PATH=" + fs.to_unix_path(FRAMEWORK_DIR),
108-
"-DSDKCONFIG_HEADER=" + os.path.join(BUILD_DIR, "config", "sdkconfig.h"),
126+
"-DSDKCONFIG_HEADER="
127+
+ os.path.join(BUILD_DIR, "config", "sdkconfig.h"),
109128
"-DPYTHON=" + env.subst("$PYTHONEXE"),
110-
"-DSDKCONFIG_CMAKE=" + os.path.join(BUILD_DIR, "config", "sdkconfig.cmake"),
129+
"-DSDKCONFIG_CMAKE="
130+
+ os.path.join(BUILD_DIR, "config", "sdkconfig.cmake"),
131+
"-DULP_COCPU_IS_RISCV="
132+
+ (
133+
"ON"
134+
if idf_variant in ("esp32s2", "esp32s3")
135+
and sdk_config.get("ULP_COPROC_TYPE_RISCV", False)
136+
else ""
137+
),
138+
"-DULP_COCPU_IS_LP_CORE="
139+
+ (
140+
"ON"
141+
if sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False)
142+
else ""
143+
),
144+
"-DESP_ROM_HAS_LP_ROM="
145+
+ (
146+
"ON"
147+
if sdk_config.get("ESP_ROM_HAS_LP_ROM", False)
148+
else ""
149+
),
150+
"-DCMAKE_MODULE_PATH="
151+
+ fs.to_unix_path(
152+
os.path.join(FRAMEWORK_DIR, "components", "ulp", "cmake")),
111153
"-GNinja",
112154
"-B",
113155
ULP_BUILD_DIR,
@@ -152,7 +194,9 @@ def compile_ulp_binary():
152194
os.path.join(ULP_BUILD_DIR, "ulp_main.bin"),
153195
],
154196
None,
155-
ulp_binary_env.VerboseAction(" ".join(cmd), "Generating ULP project files $TARGETS"),
197+
ulp_binary_env.VerboseAction(
198+
" ".join(cmd), "Generating ULP project files $TARGETS"
199+
),
156200
)
157201

158202

@@ -164,14 +208,20 @@ def generate_ulp_assembly():
164208
"-DFILE_TYPE=BINARY",
165209
"-P",
166210
os.path.join(
167-
FRAMEWORK_DIR, "tools", "cmake", "scripts", "data_file_embed_asm.cmake"
211+
FRAMEWORK_DIR,
212+
"tools",
213+
"cmake",
214+
"scripts",
215+
"data_file_embed_asm.cmake",
168216
),
169217
)
170218

171219
return ulp_env.Command(
172220
os.path.join(BUILD_DIR, "ulp_main.bin.S"),
173221
os.path.join(ULP_BUILD_DIR, "ulp_main.bin"),
174-
ulp_env.VerboseAction(" ".join(cmd), "Generating ULP assembly file $TARGET"),
222+
ulp_env.VerboseAction(
223+
" ".join(cmd), "Generating ULP assembly file $TARGET"
224+
),
175225
)
176226

177227

0 commit comments

Comments
 (0)