Skip to content

Commit da10f87

Browse files
committed
Use arduino-cli built uf2 file if available
1 parent b83ba8a commit da10f87

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Diff for: .github/workflows/githubci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ jobs:
1616
run: bash ./actions_install.sh
1717
- name: test platforms
1818
run: |
19-
python3 build_platform.py uno leonardo mega2560 zero esp8266 esp32 pico_rp2040
19+
python3 build_platform.py uno leonardo mega2560 zero esp8266 esp32 pico_rp2040 feather_m4_express
2020

Diff for: build_platform.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ def run_or_die(cmd, error):
248248

249249
################################ UF2 Utils.
250250

251+
def glob01(pattern):
252+
result = glob.glob(pattern)
253+
if len(result) > 1:
254+
raise RuntimeError(f"Required pattern {pattern} to match at most 1 file, got {result}")
255+
return result[0] if result else None
256+
251257
def glob1(pattern):
252258
result = glob.glob(pattern)
253259
if len(result) != 1:
@@ -276,11 +282,23 @@ def generate_uf2(example_path):
276282
"""
277283
if not download_uf2_utils():
278284
return None
279-
cli_build_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
280-
input_file = glob1(os.path.join(example_path, cli_build_path))
281-
output_file = os.path.splitext(input_file)[0] + ".uf2"
285+
286+
cli_build_uf2_path = "build/*.*." + fqbn.split(':')[2] + "/*.uf2"
287+
uf2_input_file = glob01(os.path.join(example_path, cli_build_uf2_path))
288+
289+
# Some platforms, like rp2040, directly generate a uf2 file, so no need to do it ourselves
290+
if uf2_input_file is not None:
291+
output_file = os.path.splitext(uf2_input_file)[0] + ".uf2"
292+
ColorPrint.print_pass(CHECK)
293+
ColorPrint.print_info("Used uf2 generated by arduino-cli")
294+
return output_file
295+
296+
# For other uf2-supporting platforms, we can generate it from a hex file
297+
cli_build_hex_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
298+
hex_input_file = glob1(os.path.join(example_path, cli_build_hex_path))
299+
output_file = os.path.splitext(hex_input_file)[0] + ".uf2"
282300
family_id = ALL_PLATFORMS[platform][1]
283-
cmd = ['python3', 'uf2conv.py', input_file, '-c', '-f', family_id, '-o', output_file]
301+
cmd = ['python3', 'uf2conv.py', hex_input_file, '-c', '-f', family_id, '-o', output_file]
284302
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
285303
r = proc.wait(timeout=60)
286304
out = proc.stdout.read()

Diff for: examples/Blink/.feather_m4_express.generate

Whitespace-only changes.

Diff for: examples/Blink/.pico_rp2040.generate

Whitespace-only changes.

0 commit comments

Comments
 (0)