|
8 | 8 | import os.path
|
9 | 9 | import argparse
|
10 | 10 | import json
|
| 11 | +from time import sleep |
11 | 12 |
|
12 | 13 |
|
13 | 14 | UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
|
@@ -276,23 +277,25 @@ def error(msg):
|
276 | 277 | parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.')
|
277 | 278 | parser.add_argument('input', metavar='INPUT', type=str, nargs='?',
|
278 | 279 | help='input file (HEX, BIN or UF2)')
|
279 |
| - parser.add_argument('-b' , '--base', dest='base', type=str, |
| 280 | + parser.add_argument('-b', '--base', dest='base', type=str, |
280 | 281 | default="0x2000",
|
281 | 282 | help='set base address of application for BIN format (default: 0x2000)')
|
282 |
| - parser.add_argument('-o' , '--output', metavar="FILE", dest='output', type=str, |
| 283 | + parser.add_argument('-f', '--family', dest='family', type=str, |
| 284 | + default="0x0", |
| 285 | + help='specify familyID - number or name (default: 0x0)') |
| 286 | + parser.add_argument('-o', '--output', metavar="FILE", dest='output', type=str, |
283 | 287 | help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible')
|
284 |
| - parser.add_argument('-d' , '--device', dest="device_path", |
| 288 | + parser.add_argument('-d', '--device', dest="device_path", |
285 | 289 | help='select a device path to flash')
|
286 |
| - parser.add_argument('-l' , '--list', action='store_true', |
| 290 | + parser.add_argument('-l', '--list', action='store_true', |
287 | 291 | help='list connected devices')
|
288 |
| - parser.add_argument('-c' , '--convert', action='store_true', |
| 292 | + parser.add_argument('-c', '--convert', action='store_true', |
289 | 293 | help='do not flash, just convert')
|
290 |
| - parser.add_argument('-D' , '--deploy', action='store_true', |
| 294 | + parser.add_argument('-D', '--deploy', action='store_true', |
291 | 295 | help='just flash, do not convert')
|
292 |
| - parser.add_argument('-f' , '--family', dest='family', type=str, |
293 |
| - default="0x0", |
294 |
| - help='specify familyID - number or name (default: 0x0)') |
295 |
| - parser.add_argument('-C' , '--carray', action='store_true', |
| 296 | + parser.add_argument('-w', '--wait', action='store_true', |
| 297 | + help='wait for device to flash') |
| 298 | + parser.add_argument('-C', '--carray', action='store_true', |
296 | 299 | help='convert binary file to a C array, not UF2')
|
297 | 300 | parser.add_argument('-i', '--info', action='store_true',
|
298 | 301 | help='display header information from UF2, do not convert')
|
@@ -337,20 +340,23 @@ def error(msg):
|
337 | 340 | print("Converted to %s, output size: %d, start address: 0x%x" %
|
338 | 341 | (ext, len(outbuf), appstartaddr))
|
339 | 342 | if args.convert or ext != "uf2":
|
340 |
| - drives = [] |
341 | 343 | if args.output == None:
|
342 | 344 | args.output = "flash." + ext
|
343 |
| - else: |
344 |
| - drives = get_drives() |
345 |
| - |
346 | 345 | if args.output:
|
347 | 346 | write_file(args.output, outbuf)
|
348 |
| - else: |
| 347 | + if ext == "uf2" and not args.convert and not args.info: |
| 348 | + drives = get_drives() |
349 | 349 | if len(drives) == 0:
|
350 |
| - error("No drive to deploy.") |
351 |
| - for d in drives: |
352 |
| - print("Flashing %s (%s)" % (d, board_id(d))) |
353 |
| - write_file(d + "/NEW.UF2", outbuf) |
| 350 | + if args.wait: |
| 351 | + print("Waiting for drive to deploy...") |
| 352 | + while len(drives) == 0: |
| 353 | + sleep(0.1) |
| 354 | + drives = get_drives() |
| 355 | + elif not args.output: |
| 356 | + error("No drive to deploy.") |
| 357 | + for d in drives: |
| 358 | + print("Flashing %s (%s)" % (d, board_id(d))) |
| 359 | + write_file(d + "/NEW.UF2", outbuf) |
354 | 360 |
|
355 | 361 |
|
356 | 362 | if __name__ == "__main__":
|
|
0 commit comments