@ -23,10 +23,6 @@ import usb.core
import usb . util
import usb . util
import zlib
import zlib
# VID/PID
__VID = 0x0483
__PID = 0xDF11
# USB request __TIMEOUT
# USB request __TIMEOUT
__TIMEOUT = 4000
__TIMEOUT = 4000
@ -112,10 +108,10 @@ def find_dfu_cfg_descr(descr):
return None
return None
def init ( ) :
def init ( * * kwargs ) :
""" Initializes the found DFU device so that we can program it. """
""" Initializes the found DFU device so that we can program it. """
global __dev , __cfg_descr
global __dev , __cfg_descr
devices = get_dfu_devices ( idVendor = __VID , idProduct = __PID )
devices = get_dfu_devices ( * * kwargs )
if not devices :
if not devices :
raise ValueError ( " No DFU device found " )
raise ValueError ( " No DFU device found " )
if len ( devices ) > 1 :
if len ( devices ) > 1 :
@ -565,15 +561,13 @@ def cli_progress(addr, offset, size):
def main ( ) :
def main ( ) :
""" Test program for verifying this files functionality. """
""" Test program for verifying this files functionality. """
global __verbose
global __verbose
global __VID
global __PID
# Parse CMD args
# Parse CMD args
parser = argparse . ArgumentParser ( description = " DFU Python Util " )
parser = argparse . ArgumentParser ( description = " DFU Python Util " )
parser . add_argument (
parser . add_argument (
" -l " , " --list " , help = " list available DFU devices " , action = " store_true " , default = False
" -l " , " --list " , help = " list available DFU devices " , action = " store_true " , default = False
)
)
parser . add_argument ( " --vid " , help = " USB Vendor ID " , type = lambda x : int ( x , 0 ) , default = __VID )
parser . add_argument ( " --vid " , help = " USB Vendor ID " , type = lambda x : int ( x , 0 ) , default = None )
parser . add_argument ( " --pid " , help = " USB Product ID " , type = lambda x : int ( x , 0 ) , default = __PID )
parser . add_argument ( " --pid " , help = " USB Product ID " , type = lambda x : int ( x , 0 ) , default = None )
parser . add_argument (
parser . add_argument (
" -m " , " --mass-erase " , help = " mass erase device " , action = " store_true " , default = False
" -m " , " --mass-erase " , help = " mass erase device " , action = " store_true " , default = False
)
)
@ -588,14 +582,18 @@ def main():
__verbose = args . verbose
__verbose = args . verbose
__VID = args . vid
kwargs = { }
__PID = args . pid
if args . vid :
kwargs [ " idVendor " ] = args . vid
if args . pid :
kwargs [ " idProduct " ] = args . pid
if args . list :
if args . list :
list_dfu_devices ( idVendor = __VID , idProduct = __PID )
list_dfu_devices ( * * kwargs )
return
return
init ( )
init ( * * kwargs )
command_run = False
command_run = False
if args . mass_erase :
if args . mass_erase :