From eba00652c2fbdc8dfd954027f3e522e723f2a7a8 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 26 Oct 2013 15:08:03 +0200 Subject: Enabled switching to bootloader from runtime mode. --- hidflash.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'hidflash.py') diff --git a/hidflash.py b/hidflash.py index a7042ca..6ab4bf6 100755 --- a/hidflash.py +++ b/hidflash.py @@ -34,9 +34,27 @@ if len(buf) & (64 - 1): dev = hidapi.hid_open(0x1d50, 0x6084, None) if not dev: - raise RuntimeError('Device not found.') + dev = hidapi.hid_open(0x1d50, 0x6080, None) + + if not dev: + raise RuntimeError('Device not found.') + + print 'Found runtime device, resetting to bootloader.' + + # Reset bootloader + if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x10'), 2) != 2: + raise RuntimeError('Reset failed.') + + time.sleep(1) + + hidapi.hid_exit() + + dev = hidapi.hid_open(0x1d50, 0x6084, None) + + if not dev: + raise RuntimeError('Device not found.') -print 'Found device, starting flashing.' +print 'Found bootloader device, starting flashing.' # Prepare if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x20'), 2) != 2: @@ -52,10 +70,21 @@ while buf: if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x21'), 2) != 2: raise RuntimeError('Finish failed.') -print 'Flashing finished, resetting.' +print 'Flashing finished, resetting to runtime.' # Reset if hidapi.hid_send_feature_report(dev, ctypes.c_char_p('\x00\x11'), 2) != 2: raise RuntimeError('Reset failed.') -print 'Done, everything ok.' +time.sleep(1) + +hidapi.hid_exit() + +if hidapi.hid_open(0x1d50, 0x6080, None): + print 'Done, everything ok.' + +elif hidapi.hid_open(0x1d50, 0x6084, None): + print 'Still in bootloader mode.' + +else: + print 'Device disappeared.' -- cgit v1.2.3