Skip to content

Commit

Permalink
uf2conv.py add option to wait for device to flash
Browse files Browse the repository at this point in the history
  • Loading branch information
pierstitus committed Jul 5, 2022
1 parent 1f39a59 commit 7cc2237
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions utils/uf2conv.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
**uf2conv.py** [-h] [-l]

**uf2conv.py** [-b BASE] [-f FAMILY] [-o FILE] [-d DEVICE_PATH] [-l] [-c] [-D]
[-C]
[-w] [-C]
[HEX or BIN FILE]

**uf2conv.py** [-c] [-D] [-i] [UF2 FILE]
**uf2conv.py** [-c] [-D] [-w] [-i] [UF2 FILE]

## DESCRIPTION

Expand Down Expand Up @@ -55,6 +55,9 @@
`--deploy`
: just flash, do not convert

`-w`
`--wait`
: wait for device to flash

`-C`
`--carray`
Expand Down
13 changes: 11 additions & 2 deletions utils/uf2conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os.path
import argparse
import json
from time import sleep


UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
Expand Down Expand Up @@ -288,6 +289,8 @@ def error(msg):
help='do not flash, just convert')
parser.add_argument('-D', '--deploy', action='store_true',
help='just flash, do not convert')
parser.add_argument('-w', '--wait', action='store_true',
help='wait for device to flash')
parser.add_argument('-C', '--carray', action='store_true',
help='convert binary file to a C array, not UF2')
parser.add_argument('-i', '--info', action='store_true',
Expand Down Expand Up @@ -339,8 +342,14 @@ def error(msg):
write_file(args.output, outbuf)
if ext == "uf2" and not args.convert and not args.info:
drives = get_drives()
if len(drives) == 0 and not args.output:
error("No drive to deploy.")
if len(drives) == 0:
if args.wait:
print("Waiting for drive to deploy...")
while len(drives) == 0:
sleep(0.1)
drives = get_drives()
elif not args.output:
error("No drive to deploy.")
for d in drives:
print("Flashing %s (%s)" % (d, board_id(d)))
write_file(d + "/NEW.UF2", outbuf)
Expand Down

0 comments on commit 7cc2237

Please sign in to comment.