Use arduino-cli built uf2 file if available
This commit is contained in:
parent
b83ba8acb1
commit
47b38c42ee
2 changed files with 25 additions and 3 deletions
|
|
@ -248,6 +248,13 @@ if not IS_LEARNING_SYS:
|
||||||
|
|
||||||
################################ UF2 Utils.
|
################################ UF2 Utils.
|
||||||
|
|
||||||
|
def glob01(pattern):
|
||||||
|
result = glob.glob(pattern)
|
||||||
|
print("glob01", pattern, result)
|
||||||
|
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):
|
def glob1(pattern):
|
||||||
result = glob.glob(pattern)
|
result = glob.glob(pattern)
|
||||||
if len(result) != 1:
|
if len(result) != 1:
|
||||||
|
|
@ -276,11 +283,26 @@ def generate_uf2(example_path):
|
||||||
"""
|
"""
|
||||||
if not download_uf2_utils():
|
if not download_uf2_utils():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
os.system(f"find {example_path} -print")
|
||||||
|
|
||||||
|
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"
|
||||||
|
shutil.copy(uf2_input_file, output_file)
|
||||||
|
ColorPrint.print_pass(CHECK)
|
||||||
|
ColorPrint.print_info("Used uf2 generated by arduino-cli")
|
||||||
|
return
|
||||||
|
|
||||||
|
# For other uf2-supporting platforms, we can generate it from a hex file
|
||||||
cli_build_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
|
cli_build_path = "build/*.*." + fqbn.split(':')[2] + "/*.hex"
|
||||||
input_file = glob1(os.path.join(example_path, cli_build_path))
|
hex_input_file = glob1(os.path.join(example_path, cli_build_hex_path))
|
||||||
output_file = os.path.splitext(input_file)[0] + ".uf2"
|
output_file = os.path.splitext(nex_input_file)[0] + ".uf2"
|
||||||
family_id = ALL_PLATFORMS[platform][1]
|
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)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
r = proc.wait(timeout=60)
|
r = proc.wait(timeout=60)
|
||||||
out = proc.stdout.read()
|
out = proc.stdout.read()
|
||||||
|
|
|
||||||
0
examples/Blink/.pico_rp2040.generate
Normal file
0
examples/Blink/.pico_rp2040.generate
Normal file
Loading…
Reference in a new issue