1818import json
1919import re
2020import requests
21- from os .path import isfile , join
2221
2322from platformio .public import PlatformBase , to_unix_path
24- from platformio .project .config import ProjectConfig
2523
2624
2725IS_WINDOWS = sys .platform .startswith ("win" )
@@ -39,32 +37,26 @@ def configure_default_packages(self, variables, targets):
3937
4038 board_config = self .board_config (variables .get ("board" ))
4139 mcu = variables .get ("board_build.mcu" , board_config .get ("build.mcu" , "esp32" ))
40+ board_sdkconfig = variables .get ("board_espidf.custom_sdkconfig" , board_config .get ("espidf.custom_sdkconfig" , "" ))
41+ core_variant_board = '' .join (variables .get ("board_build.extra_flags" , board_config .get ("build.extra_flags" , "" )))
42+ core_variant_board = core_variant_board .replace ("-D" , " " )
43+ core_variant_build = ('' .join (variables .get ("build_flags" , []))).replace ("-D" , " " )
4244 frameworks = variables .get ("pioframework" , [])
4345
44- if variables .get ("custom_sdkconfig" ) is not None :
45- frameworks .append ("espidf" )
46-
4746 if "arduino" in frameworks :
4847 self .packages ["framework-arduinoespressif32" ]["optional" ] = False
4948 self .packages ["framework-arduinoespressif32-libs" ]["optional" ] = False
50- ARDUINO_FRAMEWORK_DIR = os .path .join (ProjectConfig .get_instance ().get ("platformio" , "packages_dir" ), "framework-arduinoespressif32" )
51- if not bool (os .path .exists (ARDUINO_FRAMEWORK_DIR )):
52- try :
53- # use latest stable release Arduino core
54- ARDUINO_CORE_API_URL = "https://api.github.com/repos/espressif/Arduino-esp32/releases/latest"
55- api_data = requests .get (ARDUINO_CORE_API_URL , timeout = 2 ).json ()
56- zipball = api_data .get ("zipball_url" )
57- tag = api_data .get ("tag_name" )
58- if tag is not None :
59- # print("Latest release Arduino core URL:", zipball)
60- self .packages ["framework-arduinoespressif32" ]["version" ] = zipball
61- # use corresponding espressif Arduino libs to release
62- URL = "https://raw.githubusercontent.com/espressif/arduino-esp32/" + tag + "/package/package_esp32_index.template.json"
63- packjdata = requests .get (URL , timeout = 10 ).json ()
64- dyn_lib_url = packjdata ['packages' ][0 ]['tools' ][0 ]['systems' ][0 ]['url' ]
65- self .packages ["framework-arduinoespressif32-libs" ]["version" ] = dyn_lib_url
66- except :
67- pass
49+ # use latest espressif Arduino libs
50+ URL = "https://raw.githubusercontent.com/espressif/arduino-esp32/release/v3.1.x/package/package_esp32_index.template.json"
51+ packjdata = requests .get (URL ).json ()
52+ dyn_lib_url = packjdata ['packages' ][0 ]['tools' ][0 ]['systems' ][0 ]['url' ]
53+ self .packages ["framework-arduinoespressif32-libs" ]["version" ] = dyn_lib_url
54+
55+ if variables .get ("custom_sdkconfig" ) is not None or len (str (board_sdkconfig )) > 3 :
56+ frameworks .append ("espidf" )
57+ self .packages ["framework-espidf" ]["optional" ] = False
58+ if mcu == "esp32c2" :
59+ self .packages ["framework-arduino-c2-skeleton-lib" ]["optional" ] = False
6860
6961 if "buildfs" in targets :
7062 filesystem = variables .get ("board_build.filesystem" , "littlefs" )
@@ -91,52 +83,12 @@ def configure_default_packages(self, variables, targets):
9183 else :
9284 del self .packages ["tool-dfuutil-arduino" ]
9385
94- build_core = variables .get (
95- "board_build.core" , board_config .get ("build.core" , "arduino" )
96- ).lower ()
97-
98- if frameworks == ["arduino" ] and build_core == "esp32" :
99- # In case the upstream Arduino framework is specified in the configuration
100- # file then we need to dynamically extract toolchain versions from the
101- # Arduino index file. This feature can be disabled via a special option:
102- if (
103- variables .get (
104- "board_build.arduino.upstream_packages" ,
105- board_config .get ("build.arduino.upstream_packages" , "no" ),
106- ).lower ()
107- == "yes"
108- ):
109- package_version = self .packages ["framework-arduinoespressif32" ][
110- "version"
111- ]
112-
113- url_items = urllib .parse .urlparse (package_version )
114- # Only GitHub repositories support dynamic packages
115- if (
116- url_items .scheme in ("http" , "https" )
117- and url_items .netloc .startswith ("github" )
118- and url_items .path .endswith (".git" )
119- ):
120- try :
121- self .configure_upstream_arduino_packages (url_items )
122- except Exception as e :
123- sys .stderr .write (
124- "Error! Failed to extract upstream toolchain"
125- "configurations:\n %s\n " % str (e )
126- )
127- sys .stderr .write (
128- "You can disable this feature via the "
129- "`board_build.arduino.upstream_packages = no` setting in "
130- "your `platformio.ini` file.\n "
131- )
132- sys .exit (1 )
133-
13486 # Starting from v12, Espressif's toolchains are shipped without
13587 # bundled GDB. Instead, it's distributed as separate packages for Xtensa
13688 # and RISC-V targets.
13789 for gdb_package in ("tool-xtensa-esp-elf-gdb" , "tool-riscv32-esp-elf-gdb" ):
13890 self .packages [gdb_package ]["optional" ] = False
139- #if IS_WINDOWS:
91+ # if IS_WINDOWS:
14092 # Note: On Windows GDB v12 is not able to
14193 # launch a GDB server in pipe mode while v11 works fine
14294 # self.packages[gdb_package]["version"] = "~11.2.0"
@@ -145,19 +97,18 @@ def configure_default_packages(self, variables, targets):
14597 if "espidf" in frameworks :
14698 self .packages ["toolchain-esp32ulp" ]["optional" ] = False
14799 for p in self .packages :
148- if p in ("tool-cmake" , "tool-ninja" ):
100+ if p in ("tool-scons" , "tool- cmake" , "tool-ninja" ):
149101 self .packages [p ]["optional" ] = False
150- # elif p in ("tool-mconf", "tool-idf") and IS_WINDOWS:
151- # self.packages[p]["optional"] = False
102+ # elif p in ("tool-mconf", "tool-idf") and IS_WINDOWS:
103+ # self.packages[p]["optional"] = False
152104
153- for available_mcu in ("esp32" , "esp32s2" , "esp32s3" ):
154- if available_mcu == mcu :
155- self .packages ["toolchain-xtensa-%s" % mcu ]["optional" ] = False
156- else :
157- self .packages .pop ("toolchain-xtensa-%s" % available_mcu , None )
105+ if mcu in ("esp32" , "esp32s2" , "esp32s3" ):
106+ self .packages ["toolchain-xtensa-esp-elf" ]["optional" ] = False
107+ else :
108+ self .packages .pop ("toolchain-xtensa-esp-elf" , None )
158109
159- if mcu in ("esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ):
160- if mcu in ("esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" ):
110+ if mcu in ("esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" , "esp32p4" ):
111+ if mcu in ("esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" , "esp32p4" ):
161112 self .packages .pop ("toolchain-esp32ulp" , None )
162113 # RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP
163114 self .packages ["toolchain-riscv32-esp" ]["optional" ] = False
@@ -310,114 +261,3 @@ def configure_debug_session(self, debug_config):
310261 )
311262 )
312263 debug_config .load_cmds = load_cmds
313-
314-
315- @staticmethod
316- def extract_toolchain_versions (tool_deps ):
317- def _parse_version (original_version ):
318- assert original_version
319- version_patterns = (
320- r"^gcc(?P<MAJOR>\d+)_(?P<MINOR>\d+)_(?P<PATCH>\d+)-esp-(?P<EXTRA>.+)$" ,
321- r"^esp-(?P<EXTRA>.+)-(?P<MAJOR>\d+)\.(?P<MINOR>\d+)\.?(?P<PATCH>\d+)$" ,
322- r"^esp-(?P<MAJOR>\d+)\.(?P<MINOR>\d+)\.(?P<PATCH>\d+)(_(?P<EXTRA>.+))?$" ,
323- )
324- for pattern in version_patterns :
325- match = re .search (pattern , original_version )
326- if match :
327- result = "%s.%s.%s" % (
328- match .group ("MAJOR" ),
329- match .group ("MINOR" ),
330- match .group ("PATCH" ),
331- )
332- if match .group ("EXTRA" ):
333- result = result + "+%s" % match .group ("EXTRA" )
334- return result
335-
336- raise ValueError ("Bad package version `%s`" % original_version )
337-
338- if not tool_deps :
339- raise ValueError (
340- ("Failed to extract tool dependencies from the remote package file" )
341- )
342-
343- toolchain_remap = {
344- "xtensa-esp32-elf-gcc" : "toolchain-xtensa-esp32" ,
345- "xtensa-esp32s2-elf-gcc" : "toolchain-xtensa-esp32s2" ,
346- "xtensa-esp32s3-elf-gcc" : "toolchain-xtensa-esp32s3" ,
347- "riscv32-esp-elf-gcc" : "toolchain-riscv32-esp" ,
348- }
349-
350- result = dict ()
351- for tool in tool_deps :
352- if tool ["name" ] in toolchain_remap :
353- result [toolchain_remap [tool ["name" ]]] = _parse_version (tool ["version" ])
354-
355- return result
356-
357- @staticmethod
358- def parse_tool_dependencies (index_data ):
359- for package in index_data .get ("packages" , []):
360- if package ["name" ] == "esp32" :
361- for platform in package ["platforms" ]:
362- if platform ["name" ] == "esp32" :
363- return platform ["toolsDependencies" ]
364-
365- return []
366-
367- @staticmethod
368- def download_remote_package_index (url_items ):
369- def _prepare_url_for_index_file (url_items ):
370- tag = "master"
371- if url_items .fragment :
372- tag = url_items .fragment
373- return (
374- "https://raw.githubusercontent.com/%s/"
375- "%s/package/package_esp32_index.template.json"
376- % (url_items .path .replace (".git" , "" ), tag )
377- )
378-
379- index_file_url = _prepare_url_for_index_file (url_items )
380-
381- try :
382- from platformio .public import fetch_http_content
383- content = fetch_http_content (index_file_url )
384- except ImportError :
385- import requests
386- content = requests .get (index_file_url , timeout = 5 ).text
387-
388- return json .loads (content )
389-
390- def configure_arduino_toolchains (self , package_index ):
391- if not package_index :
392- return
393-
394- toolchain_packages = self .extract_toolchain_versions (
395- self .parse_tool_dependencies (package_index )
396- )
397- for toolchain_package , version in toolchain_packages .items ():
398- if toolchain_package not in self .packages :
399- self .packages [toolchain_package ] = dict ()
400- self .packages [toolchain_package ]["version" ] = version
401- self .packages [toolchain_package ]["owner" ] = "espressif"
402- self .packages [toolchain_package ]["type" ] = "toolchain"
403-
404- def configure_upstream_arduino_packages (self , url_items ):
405- framework_index_file = os .path .join (
406- self .get_package_dir ("framework-arduinoespressif32" ) or "" ,
407- "package" ,
408- "package_esp32_index.template.json" ,
409- )
410-
411- # Detect whether the remote is already cloned
412- if os .path .isfile (framework_index_file ) and os .path .isdir (
413- os .path .join (
414- self .get_package_dir ("framework-arduinoespressif32" ) or "" , ".git"
415- )
416- ):
417- with open (framework_index_file ) as fp :
418- self .configure_arduino_toolchains (json .load (fp ))
419- else :
420- print ("Configuring toolchain packages from a remote source..." )
421- self .configure_arduino_toolchains (
422- self .download_remote_package_index (url_items )
423- )
0 commit comments