Skip to content

Commit

Permalink
Use arduino-cli built uf2 file if available
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Feb 10, 2022
1 parent b83ba8a commit da10f87
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
run: bash ./actions_install.sh
- name: test platforms
run: |
python3 build_platform.py uno leonardo mega2560 zero esp8266 esp32 pico_rp2040
python3 build_platform.py uno leonardo mega2560 zero esp8266 esp32 pico_rp2040 feather_m4_express
26 changes: 22 additions & 4 deletions build_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ def run_or_die(cmd, error):

################################ UF2 Utils.

def glob01(pattern):
result = glob.glob(pattern)
if len(result) > 1:
raise RuntimeError(f"Required pattern {pattern} to match at most 1 file, got {result}")
return result[0] if result else None

def glob1(pattern):
result = glob.glob(pattern)
if len(result) != 1:
Expand Down Expand Up @@ -276,11 +282,23 @@ def generate_uf2(example_path):
"""
if not download_uf2_utils():
return None
cli_build_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
input_file = glob1(os.path.join(example_path, cli_build_path))
output_file = os.path.splitext(input_file)[0] + ".uf2"

cli_build_uf2_path = "build/*.*." + fqbn.split(':')[2] + "/*.uf2"
uf2_input_file = glob01(os.path.join(example_path, cli_build_uf2_path))

# Some platforms, like rp2040, directly generate a uf2 file, so no need to do it ourselves
if uf2_input_file is not None:
output_file = os.path.splitext(uf2_input_file)[0] + ".uf2"
ColorPrint.print_pass(CHECK)
ColorPrint.print_info("Used uf2 generated by arduino-cli")
return output_file

# For other uf2-supporting platforms, we can generate it from a hex file
cli_build_hex_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
hex_input_file = glob1(os.path.join(example_path, cli_build_hex_path))
output_file = os.path.splitext(hex_input_file)[0] + ".uf2"
family_id = ALL_PLATFORMS[platform][1]
cmd = ['python3', 'uf2conv.py', input_file, '-c', '-f', family_id, '-o', output_file]
cmd = ['python3', 'uf2conv.py', hex_input_file, '-c', '-f', family_id, '-o', output_file]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
r = proc.wait(timeout=60)
out = proc.stdout.read()
Expand Down
Empty file.
Empty file.

0 comments on commit da10f87

Please sign in to comment.