Skip to content

Commit 26f4986

Browse files
authored
Merge pull request espressif#119 from brentru/ada-commits
Add local ESP32BSP installation and bring in-line with WipperSnapper fork
2 parents 2c68b06 + b2f6109 commit 26f4986

File tree

1 file changed

+60
-15
lines changed

1 file changed

+60
-15
lines changed

Diff for: build_platform.py

+60-15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
# Espressif
6363
"esp8266" : ["esp8266:esp8266:huzzah:eesz=4M3M,xtal=80", None],
6464
"esp32" : ["esp32:esp32:featheresp32:FlashFreq=80", None],
65+
"feather_esp32_v2_daily" : ["espressif:esp32:adafruit_feather_esp32_v2", None],
6566
"magtag" : ["esp32:esp32:adafruit_magtag29_esp32s2", "0xbfdd4eee"],
6667
"funhouse" : ["esp32:esp32:adafruit_funhouse_esp32s2", "0xbfdd4eee"],
6768
"metroesp32s2" : ["esp32:esp32:adafruit_metro_esp32s2", "0xbfdd4eee"],
@@ -117,6 +118,9 @@
117118
"proxlighttrinkey_m0" : ["adafruit:samd:adafruit_proxlighttrinkey_m0", "0x68ed2b88"],
118119
"qtpy_m0" : ["adafruit:samd:adafruit_qtpy_m0", "0x68ed2b88"],
119120
"qtpy_m0_tinyusb" : ["adafruit:samd:adafruit_qtpy_m0:usbstack=tinyusb", "0x68ed2b88"],
121+
# Arduino SAMD
122+
"mkrwifi1010" : ["arduino:samd:mkrwifi1010", "0x8054"],
123+
"nano_33_iot" : ["arduino:samd:nano_33_iot", "0x8057"],
120124
# Arduino nRF
121125
"microbit" : ["sandeepmistry:nRF5:BBCmicrobit:softdevice=s110", None],
122126
# Adafruit nRF
@@ -176,17 +180,51 @@ def print_info(message, end = '\n'):
176180
def print_bold(message, end = '\n'):
177181
sys.stdout.write('\x1b[1;37m' + message.strip() + '\x1b[0m' + end)
178182

183+
def manually_install_esp32_bsp():
184+
# see - https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#linux
185+
print("Manually installing latest ESP32 BSP...")
186+
os.system("mkdir -p /home/runner/Arduino/hardware/espressif")
187+
# Locally clone repo
188+
print("Cloning github.com/espressif/arduino-esp32..")
189+
cmd = "cd /home/runner/Arduino/hardware/espressif && git clone https://github.com/espressif/arduino-esp32.git esp32"
190+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
191+
r = proc.wait(timeout=1000)
192+
out = proc.stdout.read()
193+
err = proc.stderr.read()
194+
if r != 0:
195+
ColorPrint.print_fail("Failed to download ESP32 Arduino BSP!")
196+
ColorPrint.print_fail(out.decode("utf-8"))
197+
ColorPrint.print_fail(err.decode("utf-8"))
198+
exit(-1)
199+
print(out)
200+
print("Cloned repository!")
179201

180-
def install_platform(platform):
181-
print("Installing", platform, end=" ")
182-
if platform == "adafruit:avr": # we have a platform dep
202+
print("Installing ESP32 Arduino BSP...")
203+
cmd = "cd /home/runner/Arduino/hardware/espressif/esp32/tools && python3 get.py"
204+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
205+
r = proc.wait(timeout=1000)
206+
out = proc.stdout.read()
207+
err = proc.stderr.read()
208+
if r != 0:
209+
ColorPrint.print_fail("Failed to install ESP32 Arduino BSP!")
210+
ColorPrint.print_fail(out.decode("utf-8"))
211+
ColorPrint.print_fail(err.decode("utf-8"))
212+
exit(-1)
213+
print(out)
214+
print("Installed ESP32 BSP from source!")
215+
216+
def install_platform(fqbn, platform_name):
217+
print("Installing", fqbn, end=" ")
218+
if fqbn == "adafruit:avr": # we have a platform dep
183219
install_platform("arduino:avr")
184-
if os.system("arduino-cli core install "+platform+" --additional-urls "+BSP_URLS+" > /dev/null") != 0:
185-
ColorPrint.print_fail("FAILED to install "+platform)
220+
if "daily" in platform_name: # manually install ESP32 BSP from latest source
221+
manually_install_esp32_bsp()
222+
if os.system("arduino-cli core install "+fqbn+" --additional-urls "+BSP_URLS+" > /dev/null") != 0:
223+
ColorPrint.print_fail("FAILED to install "+fqbn)
186224
exit(-1)
187225
ColorPrint.print_pass(CHECK)
188226
# print installed core version
189-
print(os.popen('arduino-cli core list | grep {}'.format(platform)).read(), end='')
227+
print(os.popen('arduino-cli core list | grep {}'.format(fqbn)).read(), end='')
190228

191229
def run_or_die(cmd, error):
192230
print(cmd)
@@ -292,12 +330,20 @@ def generate_uf2(example_path):
292330
ColorPrint.print_info("Used uf2 generated by arduino-cli")
293331
return output_file
294332

295-
# For other uf2-supporting platforms, we can generate it from a hex file
296-
cli_build_hex_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
297-
hex_input_file = glob1(os.path.join(example_path, cli_build_hex_path))
298-
output_file = os.path.splitext(hex_input_file)[0] + ".uf2"
299-
family_id = ALL_PLATFORMS[platform][1]
300-
cmd = ['python3', 'uf2conv.py', hex_input_file, '-c', '-f', family_id, '-o', output_file]
333+
# Generate using a hex file for all platforms except for ESP32-S2 (exports as .bin files)
334+
if not "esp32s2" in fqbn:
335+
cli_build_hex_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
336+
hex_input_file = glob1(os.path.join(example_path, cli_build_hex_path))
337+
output_file = os.path.splitext(hex_input_file)[0] + ".uf2"
338+
family_id = ALL_PLATFORMS[platform][1]
339+
cmd = ['python3', 'uf2conv.py', hex_input_file, '-c', '-f', family_id, '-o', output_file]
340+
else:
341+
cli_build_path = "build/*.*." + fqbn.split(':')[2] + "/*.ino.bin"
342+
input_file = glob1(os.path.join(example_path, cli_build_path))
343+
output_file = os.path.splitext(input_file)[0] + ".uf2"
344+
family_id = ALL_PLATFORMS[platform][1]
345+
cmd = ['python3', 'uf2conv.py', input_file, '-c', '-f', family_id, '-b', "0x0000", '-o', output_file]
346+
301347
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
302348
r = proc.wait(timeout=60)
303349
out = proc.stdout.read()
@@ -382,11 +428,10 @@ def test_examples_in_folder(folderpath):
382428
cmd = ['arduino-cli', 'compile', '--warnings', 'all', '--fqbn', fqbn, folderpath]
383429
else:
384430
cmd = ['arduino-cli', 'compile', '--warnings', 'none', '--export-binaries', '--fqbn', fqbn, folderpath]
385-
386431
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
387432
stderr=subprocess.PIPE)
388433
try:
389-
out, err = proc.communicate(timeout=60)
434+
out, err = proc.communicate(timeout=120)
390435
r = proc.returncode
391436
except:
392437
proc.kill()
@@ -463,7 +508,7 @@ def test_examples_in_learningrepo(folderpath):
463508
fqbn = ALL_PLATFORMS[platform][0]
464509
print('#'*80)
465510
ColorPrint.print_info("SWITCHING TO "+fqbn)
466-
install_platform(":".join(fqbn.split(':', 2)[0:2])) # take only first two elements
511+
install_platform(":".join(fqbn.split(':', 2)[0:2]), platform) # take only first two elements
467512
print('#'*80)
468513
if not IS_LEARNING_SYS:
469514
test_examples_in_folder(BUILD_DIR+"/examples")

0 commit comments

Comments
 (0)