Skip to content

Commit

Permalink
auto-upgrade working but with an ugly exception printed to screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mach327 committed Feb 13, 2020
1 parent 15fc2b3 commit 1364248
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 562 deletions.
64 changes: 53 additions & 11 deletions md380_dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import usb.core

import dfu_suffix
from DFU import DFU, State
from DFU import DFU, State, Status
import md380_tool
import stm32_dfu

# The tricky thing is that *THREE* different applications all show up
# as this same VID/PID pair.
Expand Down Expand Up @@ -395,25 +397,71 @@ def main():
try:
if len(sys.argv) == 3:
if sys.argv[1] == 'read':
import usb.core
dfu = init_dfu()
upload_codeplug(dfu, sys.argv[2])
print('Read complete')
elif sys.argv[1] == 'readboot':
print("This only works from OS X. Use the one in md380-tool with patched firmware for other bootloaders.")
import usb.core
dfu = init_dfu()
upload_bootloader(dfu, sys.argv[2])

elif sys.argv[1] == "upgrade":
import usb.core
with open(sys.argv[2], 'rb') as f:
data = f.read()
dfu = init_dfu()
mfg = dfu.get_string(1)
if mfg != u'AnyRoad Technology':
print("Radio not in bootloader: attempting automatic reboot into bootloader")
try:
dfu.wait_till_ready()
del dfu
except usb.core.USBError as e:
#we expect a pipe error here (errno 32)
print("detach dfu")
if e.errno != 32:
print(e)
time.sleep(1)
try:
tooldfu = md380_tool.init_dfu()
tooldfu.reboot_to_bootloader()
del tooldfu
except usb.core.USBError as e:
#we expect a pipe error here (errno 32)
print("tooldfu")
if e.errno != 32:
print(e)
time.sleep(10) #wait for bootloader to be ready
status = None
while status != Status.OK: #stay here until bootloader actually ready
try:
dfu = init_dfu()
status = dfu.get_status()[0]
except usb.core.USBError as e:
#busy device is okay here, but the time.sleep should be enough to handle that
print(e)
status = None
time.sleep(.5)
download_firmware(dfu, data)
dfu.wait_till_ready()
try:
del dfu
except usb.core.USBError as e:
#we expect a pipe error here (errno 32)
print("detach dfu2")
if e.errno != 32:
print(e)
time.sleep(1)
try:
stm32dfu = stm32_dfu.init_dfu()
stm32dfu.go() #has a default address that works
del stm32dfu
except usb.core.USBError as e:
#we expect a pipe error here (errno 32)
print("stm32dfu go")
if e.errno != 32:
print(e)

elif sys.argv[1] == 'write':
import usb.core
f = open(sys.argv[2], 'rb')
data = f.read()
f.close()
Expand Down Expand Up @@ -454,36 +502,30 @@ def main():
print("Signed file written: %s" % dfu_file)

elif sys.argv[1] == 'settime':
import usb.core
dfu = init_dfu()
dfu.set_time()
else:
usage()

elif len(sys.argv) == 2:
if sys.argv[1] == 'detach':
import usb.core
dfu = init_dfu()
dfu.set_address(0x08000000) # Radio Application
detach(dfu)
elif sys.argv[1] == 'time':
import usb.core
dfu = init_dfu()
print(dfu.get_time())
elif sys.argv[1] == 'settime':
import usb.core
dfu = init_dfu()
dfu.set_time()
elif sys.argv[1] == 'reboot':
import usb.core
dfu = init_dfu()
dfu.md380_custom(0x91, 0x01) # Programming Mode
dfu.md380_custom(0x91, 0x01) # Programming Mode
# dfu.md380_custom(0x91,0x01); #Programming Mode
# dfu.drawtext("Rebooting",160,50);
dfu.md380_reboot()
elif sys.argv[1] == 'abort':
import usb.core
dfu = init_dfu()
dfu.abort()
else:
Expand Down
Loading

0 comments on commit 1364248

Please sign in to comment.