12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import json
15
16
import os
16
17
import subprocess
17
18
import sys
24
25
from platformio .project .config import ProjectConfig
25
26
from platformio .package .manager .tool import ToolPackageManager
26
27
28
+ def get_tool_version_from_platform_json (tool_name ):
29
+ platform_json_path = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "platforms_dir" ), "espressif32" , "platform.json" )
30
+ with open (platform_json_path , "r" , encoding = "utf-8" ) as file :
31
+ platform_data = json .load (file )
32
+ packages = platform_data .get ("packages" , {})
33
+ tool_info = packages [tool_name ]
34
+ version = tool_info .get ("version" , "" ) # version is an URL!
35
+ return version
36
+
27
37
IS_WINDOWS = sys .platform .startswith ("win" )
28
38
# Set Platformio env var to use windows_amd64 for all windows architectures
29
39
# only windows_amd64 native espressif toolchains are available
34
44
python_exe = get_pythonexe_path ()
35
45
pm = ToolPackageManager ()
36
46
47
+ if not os .path .exists (os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tool-scons" )):
48
+ scons_uri = get_tool_version_from_platform_json ("tool-scons" )
49
+ if scons_uri is not None :
50
+ pm .install (scons_uri )
51
+
37
52
IDF_TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".espressif" )
38
53
IDF_TOOLS = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tl-install" , "tools" , "idf_tools.py" )
39
54
IDF_TOOLS_CMD = (
@@ -69,9 +84,9 @@ def configure_default_packages(self, variables, targets):
69
84
70
85
# Enable debug tool gdb only when build debug is enabled
71
86
if (variables .get ("build_type" ) or "debug" in "" .join (targets )) and tl_flag :
72
- self .packages ["riscv32-esp-elf-gdb" ]["optional" ] = False if mcu in ["esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ] else True
87
+ self .packages ["riscv32-esp-elf-gdb" ]["optional" ] = False if mcu in ["esp32c2" , "esp32c3" , "esp32c5" , " esp32c6" , "esp32h2" , "esp32p4 " ] else True
73
88
self .packages ["riscv32-esp-elf-gdb" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tl-rv-gdb" )
74
- self .packages ["xtensa-esp-elf-gdb" ]["optional" ] = False if not mcu in ["esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ] else True
89
+ self .packages ["xtensa-esp-elf-gdb" ]["optional" ] = False if not mcu in ["esp32c2" , "esp32c3" , "esp32c5" , " esp32c6" , "esp32h2" , "esp32p4 " ] else True
75
90
self .packages ["xtensa-esp-elf-gdb" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tl-xt-gdb" )
76
91
else :
77
92
self .packages ["riscv32-esp-elf-gdb" ]["optional" ] = True
@@ -95,18 +110,22 @@ def configure_default_packages(self, variables, targets):
95
110
self .packages ["framework-arduinoespressif32-libs" ]["version" ] = dyn_lib_url
96
111
97
112
if variables .get ("custom_sdkconfig" ) is not None or len (str (board_sdkconfig )) > 3 :
98
- frameworks .append ("espidf" )
99
- self .packages ["framework-espidf" ]["optional" ] = False
100
113
if mcu == "esp32c2" :
101
114
self .packages ["framework-arduino-c2-skeleton-lib" ]["optional" ] = False
115
+ frameworks .append ("espidf" )
116
+ self .packages ["framework-espidf" ]["optional" ] = False
102
117
103
118
# packages for IDF and mixed Arduino+IDF projects
104
119
if tl_flag and "espidf" in frameworks :
105
120
for p in self .packages :
106
- if p in ("tool-scons" , "tool-cmake" , "tool-ninja" ):
121
+ if p in (
122
+ "tool-scons" ,
123
+ "tool-cmake" ,
124
+ "tool-ninja" ,
125
+ ):
107
126
self .packages [p ]["optional" ] = False
108
127
109
- if "" .join (targets ) in ("upload" , "buildfs" , "uploadfs" ):
128
+ if tl_flag and ( "" .join (targets ) in ("upload" , "buildfs" , "uploadfs" ) or variables . get ( "custom_files_upload" ) is not None ):
110
129
filesystem = variables .get ("board_build.filesystem" , "littlefs" )
111
130
if filesystem == "littlefs" :
112
131
# Use mklittlefs v3.2.0 to generate FS
@@ -166,7 +185,7 @@ def configure_default_packages(self, variables, targets):
166
185
self .packages ["esp32ulp-elf" ]["optional" ] = False
167
186
self .packages ["esp32ulp-elf" ]["version" ] = tc_path
168
187
# Enable RISC-V ULP toolchain for ESP32C6, ESP32S2, ESP32S3 when IDF is selected
169
- if tl_flag and "espidf" in frameworks and mcu in ("esp32s2" , "esp32s3" , "esp32c6" ):
188
+ if tl_flag and "espidf" in frameworks and mcu in ("esp32s2" , "esp32s3" , "esp32c5" , " esp32c6" , "esp32p4 " ):
170
189
tc_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tc-rv32" )
171
190
self .packages ["riscv32-esp-elf" ]["optional" ] = False
172
191
self .packages ["riscv32-esp-elf" ]["version" ] = tc_path
@@ -211,7 +230,7 @@ def _add_dynamic_options(self, board):
211
230
# A special case for the Kaluga board that has a separate interface config
212
231
if board .id == "esp32-s2-kaluga-1" :
213
232
supported_debug_tools .append ("ftdi" )
214
- if board .get ("build.mcu" , "" ) in ("esp32c3" , "esp32c6" , "esp32s3" , "esp32h2" ):
233
+ if board .get ("build.mcu" , "" ) in ("esp32c3" , "esp32c5" , " esp32c6" , "esp32s3" , "esp32h2" , "esp32p4 " ):
215
234
supported_debug_tools .append ("esp-builtin" )
216
235
217
236
upload_protocol = board .manifest .get ("upload" , {}).get ("protocol" )
0 commit comments