From 99c55fce60674d43185cec0e6635e093c253c824 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 31 Jul 2015 16:10:47 +0900 Subject: [PATCH] support ST-Link/V2-1 --- ChangeLog | 4 ++++ tool/stlinkv2.py | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 036c2cf..1caf785 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-07-31 Niibe Yutaka + + * tool/stlinkv2.py: Support ST-Link/V2-1. + 2015-07-28 Niibe Yutaka * tool/stlinkv2.py: Fix for Python3. Thanks to Bertrand Jacquin. diff --git a/tool/stlinkv2.py b/tool/stlinkv2.py index 940a0c6..a982bac 100755 --- a/tool/stlinkv2.py +++ b/tool/stlinkv2.py @@ -133,7 +133,10 @@ class OperationFailure(Exception): class stlinkv2(object): def __init__(self, dev): - self.__bulkout = 2 + if dev.idProduct == USB_VENDOR_STLINKV2: + self.__bulkout = 2 + else: + self.__bulkout = 1 self.__bulkin = 0x81 self.__timeout = 1000 # 1 second @@ -143,7 +146,13 @@ class stlinkv2(object): if intf.interfaceClass != 0xff: # Vendor specific raise ValueError("Wrong interface class.", intf.interfaceClass) self.__devhandle = dev.open() - self.__devhandle.setConfiguration(conf.value) + # ST-Link/V2-1 has other interfaces + # Some other processes or kernel would use it + # So, write access to configuration causes error + try: + self.__devhandle.setConfiguration(conf.value) + except: + pass self.__devhandle.claimInterface(intf.interfaceNumber) # self.__devhandle.setAltInterface(0) # This was not good for libusb-win32 with wrong arg intf, new correct value 0 would be OK @@ -535,6 +544,7 @@ class stlinkv2(object): USB_VENDOR_ST=0x0483 # 0x0483 SGS Thomson Microelectronics USB_VENDOR_STLINKV2=0x3748 # 0x3748 ST-LINK/V2 +USB_VENDOR_STLINKV2_1=0x374b # 0x374b ST-LINK/V2_1 def stlinkv2_devices(): busses = usb.busses() @@ -543,7 +553,7 @@ def stlinkv2_devices(): for dev in devices: if dev.idVendor != USB_VENDOR_ST: continue - if dev.idProduct != USB_VENDOR_STLINKV2: + if dev.idProduct != USB_VENDOR_STLINKV2 and dev.idProduct != USB_VENDOR_STLINKV2_1: continue yield dev