21
21
from platformio .public import PlatformBase , to_unix_path
22
22
from platformio .proc import get_pythonexe_path
23
23
from platformio .project .config import ProjectConfig
24
+ from platformio .package .manager .tool import ToolPackageManager
24
25
25
26
python_exe = get_pythonexe_path ()
27
+ pm = ToolPackageManager ()
26
28
27
29
IDF_TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".espressif" )
28
30
IDF_TOOLS = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "tl-install" , "tools" , "idf_tools.py" )
29
- IDF_TOOLS_FLAG = ["install" ]
30
- IDF_TOOLS_CMD = [python_exe , IDF_TOOLS ] + IDF_TOOLS_FLAG
31
+ IDF_TOOLS_CMD = (
32
+ python_exe ,
33
+ IDF_TOOLS ,
34
+ "install" ,
35
+ )
36
+
37
+ # IDF Install is needed only one time
38
+ tl_flag = bool (os .path .exists (IDF_TOOLS ))
39
+ if (tl_flag and not bool (os .path .exists (join (IDF_TOOLS_PATH_DEFAULT , "tools" )))):
40
+ rc = subprocess .call (IDF_TOOLS_CMD )
41
+ if rc != 0 :
42
+ sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install'\n " )
43
+ else :
44
+ shutil .copytree (join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-packages" ), join (IDF_TOOLS_PATH_DEFAULT , "tools" ), symlinks = False , ignore = None , ignore_dangling_symlinks = False , dirs_exist_ok = True )
45
+ for p in ("tool-mklittlefs" , "tool-mkfatfs" , "tool-mkspiffs" , "tool-dfuutil" , "tool-openocd" , "tool-cmake" , "tool-ninja" , "tool-cppcheck" , "tool-clangtidy" , "tool-pvs-studio" , "tc-xt-esp32" , "tc-xt-esp32s2" , "tc-xt-esp32s3" , "tc-ulp" , "tc-rv32" , "tl-xt-gdb" , "tl-rv-gdb" , "contrib-piohome" , "contrib-pioremote" ):
46
+ tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , p )
47
+ pm .install (tl_path )
31
48
32
49
class Espressif32Platform (PlatformBase ):
33
50
def configure_default_packages (self , variables , targets ):
@@ -37,48 +54,16 @@ def configure_default_packages(self, variables, targets):
37
54
board_config = self .board_config (variables .get ("board" ))
38
55
mcu = variables .get ("board_build.mcu" , board_config .get ("build.mcu" , "esp32" ))
39
56
frameworks = variables .get ("pioframework" , [])
40
- tl_flag = bool (os .path .exists (IDF_TOOLS ))
41
-
42
- # IDF Install is needed only one time
43
- if not os .path .exists (join (IDF_TOOLS_PATH_DEFAULT , "tools" )) and tl_flag :
44
- rc = subprocess .call (IDF_TOOLS_CMD )
45
- if rc != 0 :
46
- sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install'\n " )
47
- else :
48
- shutil .copytree (join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-packages" ), join (IDF_TOOLS_PATH_DEFAULT , "tools" ), symlinks = False , ignore = None , ignore_dangling_symlinks = False , dirs_exist_ok = True )
49
-
50
- if tl_flag :
51
- # install tool is not needed anymore
52
- self .packages ["tl-install" ]["optional" ] = True
53
- # Install all tools and toolchains
54
- for p in self .packages :
55
- if p in ("tool-mklittlefs" , "tool-mkfatfs" , "tool-mkspiffs" , "tool-dfuutil" , "tool-openocd" , "tool-cmake" , "tool-ninja" , "tool-cppcheck" , "tool-clangtidy" , "tool-pvs-studio" , "contrib-piohome" , "contrib-pioremote" , "tc-ulp" , "tc-rv32" , "tl-xt-gdb" , "tl-rv-gdb" ):
56
- tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , p )
57
- self .packages [p ]["optional" ] = False
58
- self .packages [p ]["version" ] = tl_path
59
- # Enable common packages for IDF and mixed Arduino+IDF projects
60
- for p in self .packages :
61
- if p in ("tool-cmake" , "tool-ninja" , "tc-ulp" ):
62
- self .packages [p ]["optional" ] = False if "espidf" in frameworks else True
63
- # Enabling of following tools is not needed, installing is enough
64
- for p in self .packages :
65
- if p in ("contrib-pioremote" , "contrib-piohome" ):
66
- try :
67
- pkg_dir = pm .get_package (p ).path
68
- # When package is not found an execption happens -> install is forced
69
- # else the are removed from current env
70
- self .packages [p ]["optional" ] = True
71
- except :
72
- pass
73
-
74
57
75
58
# Enable debug tool gdb only when build debug is enabled
76
- if variables .get ("build_type" ) or "debug" in "" .join (targets ):
77
- self .packages ["tl-rv-gdb" ]["optional" ] = False if mcu in ["esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ] else True
78
- self .packages ["tl-xt-gdb" ]["optional" ] = False if not mcu in ["esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ] else True
59
+ if (variables .get ("build_type" ) or "debug" in "" .join (targets )) and tl_flag :
60
+ self .packages ["riscv32-esp-elf-gdb" ]["optional" ] = False if mcu in ["esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ] else True
61
+ self .packages ["riscv32-esp-elf-gdb" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tl-rv-gdb" )
62
+ self .packages ["xtensa-esp-elf-gdb" ]["optional" ] = False if not mcu in ["esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ] else True
63
+ self .packages ["xtensa-esp-elf-gdb" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tl-xt-gdb" )
79
64
else :
80
- self .packages ["tl-rv -gdb" ]["optional" ] = True
81
- self .packages ["tl-xt -gdb" ]["optional" ] = True
65
+ self .packages ["riscv32-esp-elf -gdb" ]["optional" ] = True
66
+ self .packages ["xtensa-esp-elf -gdb" ]["optional" ] = True
82
67
83
68
# Enable check tools only when "check_tool" is enabled
84
69
for p in self .packages :
@@ -93,17 +78,18 @@ def configure_default_packages(self, variables, targets):
93
78
filesystem = variables .get ("board_build.filesystem" , "littlefs" )
94
79
if filesystem == "littlefs" :
95
80
# Use mklittlefs v3.2.0 to generate FS
96
- tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-mklittlefs" )
97
81
self .packages ["tool-mklittlefs" ]["optional" ] = False
98
- self .packages ["tool-mklittlefs" ]["version" ] = tl_path
82
+ self .packages ["tool-mklittlefs" ]["version" ] = "file://" + join ( IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-mklittlefs" )
99
83
del self .packages ["tool-mkfatfs" ]
100
84
del self .packages ["tool-mkspiffs" ]
101
85
elif filesystem == "fatfs" :
102
86
self .packages ["tool-mkfatfs" ]["optional" ] = False
87
+ self .packages ["tool-mkfatfs" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-mkfatfs" )
103
88
del self .packages ["tool-mklittlefs" ]
104
89
del self .packages ["tool-mkspiffs" ]
105
90
elif filesystem == "spiffs" :
106
91
self .packages ["tool-mkspiffs" ]["optional" ] = False
92
+ self .packages ["tool-mkspiffs" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-mkspiffs" )
107
93
del self .packages ["tool-mkfatfs" ]
108
94
del self .packages ["tool-mklittlefs" ]
109
95
else :
@@ -113,38 +99,41 @@ def configure_default_packages(self, variables, targets):
113
99
114
100
if variables .get ("upload_protocol" ):
115
101
self .packages ["tool-openocd" ]["optional" ] = False
102
+ self .packages ["tool-openocd" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-openocd" )
116
103
else :
117
104
del self .packages ["tool-openocd" ]
118
105
119
106
if "downloadfs" in targets :
120
107
filesystem = variables .get ("board_build.filesystem" , "littlefs" )
121
108
if filesystem == "littlefs" :
122
109
# Use mklittlefs v4.0.0 to unpack, older version is incompatible
123
- tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-mklittlefs400" )
124
110
self .packages ["tool-mklittlefs" ]["optional" ] = False
125
- self .packages ["tool-mklittlefs" ]["version" ] = tl_path
111
+ self .packages ["tool-mklittlefs" ]["version" ] = "file://" + join ( IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-mklittlefs400" )
126
112
127
113
# Currently only Arduino Nano ESP32 uses the dfuutil tool as uploader
128
114
if variables .get ("board" ) == "arduino_nano_esp32" :
129
115
self .packages ["tool-dfuutil" ]["optional" ] = False
116
+ self .packages ["tool-dfuutil" ]["version" ] = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tool-dfuutil" )
130
117
else :
131
118
del self .packages ["tool-dfuutil" ]
132
119
133
120
# Enable needed toolchains
134
121
for available_mcu in ("esp32" , "esp32s2" , "esp32s3" ):
135
122
if available_mcu == mcu and tl_flag :
136
123
tc_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tc-xt-%s" % mcu )
137
- self .packages ["tc-xt -%s" % mcu ]["optional" ] = False
138
- self .packages ["tc-xt -%s" % mcu ]["version" ] = tc_path
124
+ self .packages ["toolchain-xtensa -%s" % mcu ]["optional" ] = False
125
+ self .packages ["toolchain-xtensa -%s" % mcu ]["version" ] = tc_path
139
126
if available_mcu == "esp32" :
140
- del self .packages ["tc-rv32 " ]
141
- # Enable ULP toolchains
127
+ del self .packages ["toolchain-riscv32-esp " ]
128
+ # Enable riscv and ULP toolchains
142
129
if mcu in ("esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ):
143
130
if mcu in ("esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ):
144
- del self .packages ["tc-ulp " ]
131
+ del self .packages ["toolchain-esp32ulp " ]
145
132
# RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
146
133
if tl_flag :
147
- self .packages ["tc-rv32" ]["optional" ] = False
134
+ tc_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tc-rv32" )
135
+ self .packages ["toolchain-riscv32-esp" ]["optional" ] = False
136
+ self .packages ["toolchain-riscv32-esp" ]["version" ] = tc_path
148
137
149
138
return super ().configure_default_packages (variables , targets )
150
139
0 commit comments