Skip to content

Commit

Permalink
add bus, channel and bitrate arguments to dfu util
Browse files Browse the repository at this point in the history
  • Loading branch information
yconst committed Sep 25, 2023
1 parent 19d4f26 commit 1fd5509
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions studio/Python/tinymovr/dfu.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Usage:
dfu.py --node_id=ID [--bin=PATH | --recovery] [--no-reset]
dfu.py --node_id=ID [--bin=PATH | --recovery] [--no-reset] [--bus=<bus>] [--chan=<chan>] [--bitrate=<bitrate>]
Options:
--node_id=ID The CAN Node ID of the device in DFU mode.
--bin=PATH The path of the .bin file to upload.
--recovery Perform recovery procedure for inaccessible DFU bootloader.
--no-reset Do not perform a reset following successful flashing.
--bus=<bus> One or more interfaces to use, first available is used [default: canine,slcan_disco].
--chan=<chan> The bus device "channel".
--bitrate=<bitrate> CAN bitrate [default: 1000000].
"""

import sys
Expand Down Expand Up @@ -123,15 +126,22 @@ def upload_bin(device, bin_path):

def spawn():
# Parse command line arguments
args = docopt(__doc__)
node_id = int(args["--node_id"])
bin_path = args["--bin"]
arguments = docopt(__doc__)
node_id = int(arguments["--node_id"])
bin_path = arguments["--bin"]

# Set up the device
params = get_bus_config(["canine", "slcan_disco"])
params["bitrate"] = 1000000
buses = arguments["--bus"].rsplit(sep=",")
channel = arguments["--chan"]
bitrate = int(arguments["--bitrate"])

if args["--recovery"]:
if not channel:
params = get_bus_config(buses)
params["bitrate"] = bitrate
else:
params = {"bustype": buses[0], "channel": channel, "bitrate": bitrate}

if arguments["--recovery"]:

input("Please power off the device and then press any key to continue...")
print("Now power on the device.")
Expand Down Expand Up @@ -162,7 +172,7 @@ def spawn():
else:
upload_bin(device, bin_path)
compare_bin_w_device(device, bin_path, string="Verifying")
if not args["--no-reset"]:
if not arguments["--no-reset"]:
print("Resetting device...")
device.reset()
destroy_tee()
Expand Down

0 comments on commit 1fd5509

Please sign in to comment.