13
13
# limitations under the License.
14
14
15
15
import os
16
+ import subprocess
16
17
import urllib
17
18
import sys
18
19
import json
21
22
from os .path import isfile , isdir , join
22
23
23
24
from platformio .public import PlatformBase , to_unix_path
25
+ from platformio .proc import get_pythonexe_path
24
26
25
-
27
+ python_exe = get_pythonexe_path ()
26
28
IS_WINDOWS = sys .platform .startswith ("win" )
27
29
IDF_TOOLS_PATH_DEFAULT = os .path .join (os .path .expanduser ("~" ), ".espressif" )
30
+ IDF_TOOLS = os .path .join (os .path .expanduser ("~" ), ".platformio" , "packages" , "tl-install" , "tools" , "idf_tools.py" )
31
+ IDF_TOOLS_FLAG = ["install" ]
32
+ IDF_TOOLS_CMD = [python_exe , IDF_TOOLS ] + IDF_TOOLS_FLAG
28
33
29
34
30
35
class Espressif32Platform (PlatformBase ):
@@ -36,6 +41,14 @@ def configure_default_packages(self, variables, targets):
36
41
mcu = variables .get ("board_build.mcu" , board_config .get ("build.mcu" , "esp32" ))
37
42
frameworks = variables .get ("pioframework" , [])
38
43
44
+ self .packages ["tl-install" ]["optional" ] = False
45
+
46
+ # IDF Install is needed only one time
47
+ if not os .path .exists (join (IDF_TOOLS_PATH_DEFAULT , "tools" )):
48
+ rc = subprocess .call (IDF_TOOLS_CMD )
49
+ if rc != 0 :
50
+ sys .stderr .write ("Error: Couldn't execute 'idf_tools.py install' \n " )
51
+
39
52
40
53
if "arduino" in frameworks :
41
54
self .packages ["framework-arduinoespressif32" ]["optional" ] = False
@@ -87,7 +100,9 @@ def configure_default_packages(self, variables, targets):
87
100
for gdb_package in ("tl-xt-gdb" , "tl-rv-gdb" ):
88
101
self .packages [gdb_package ]["optional" ] = False
89
102
tl_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , gdb_package )
90
- self .packages [gdb_package ]["version" ] = tl_path
103
+ # print("gdb path:", tl_path)
104
+ if os .path .exists (tl_path ):
105
+ self .packages [gdb_package ]["version" ] = tl_path
91
106
92
107
# Common packages for IDF and mixed Arduino+IDF projects
93
108
if "espidf" in frameworks :
@@ -114,7 +129,9 @@ def configure_default_packages(self, variables, targets):
114
129
# RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
115
130
self .packages ["tc-rv32" ]["optional" ] = False
116
131
rv32_path = "file://" + join (IDF_TOOLS_PATH_DEFAULT , "tools" , "tc-rv32" )
117
- self .packages ["tc-rv32" ]["version" ] = rv32_path
132
+ if os .path .exists (rv32_path ):
133
+ self .packages ["tc-rv32" ]["owner" ] = "espressif"
134
+ self .packages ["tc-rv32" ]["version" ] = rv32_path
118
135
119
136
return super ().configure_default_packages (variables , targets )
120
137
0 commit comments