diff --git a/pyocd/probe/picoprobe.py b/pyocd/probe/picoprobe.py index 481e984f0..14d1214db 100644 --- a/pyocd/probe/picoprobe.py +++ b/pyocd/probe/picoprobe.py @@ -18,8 +18,12 @@ from array import array from time import sleep +try: + from libusb_package import find as usb_find +except ImportError: + from usb.core import find as usb_find + from usb import core, util -import libusb_package import platform import errno @@ -108,7 +112,7 @@ def enumerate_picoprobes(cls, uid=None) -> List["PicoLink"]: """@brief Find and return all Picoprobes """ try: # Use a custom matcher to make sure the probe is a Picoprobe and accessible. - return [PicoLink(probe) for probe in libusb_package.find(find_all=True, custom_match=FindPicoprobe(uid))] + return [PicoLink(probe) for probe in usb_find(find_all=True, custom_match=FindPicoprobe(uid))] except core.NoBackendError: show_no_libusb_warning() return [] diff --git a/pyocd/probe/pydapaccess/interface/pyusb_backend.py b/pyocd/probe/pydapaccess/interface/pyusb_backend.py index cf240043e..229fc7c5c 100644 --- a/pyocd/probe/pydapaccess/interface/pyusb_backend.py +++ b/pyocd/probe/pydapaccess/interface/pyusb_backend.py @@ -37,7 +37,6 @@ TRACE.setLevel(logging.CRITICAL) try: - import libusb_package import usb.core import usb.util except ImportError: @@ -45,6 +44,12 @@ else: IS_AVAILABLE = True +try: + from libusb_package import find as usb_find +except ImportError: + from usb.core import find as usb_find + + class PyUSB(Interface): """@brief CMSIS-DAP USB interface class using pyusb for the backend.""" @@ -70,7 +75,7 @@ def open(self): assert self.closed is True # Get device handle - dev = libusb_package.find(custom_match=FindDap(self.serial_number)) + dev = usb_find(custom_match=FindDap(self.serial_number)) if dev is None: raise DAPAccessIntf.DeviceError("Device %s not found" % self.serial_number) @@ -161,7 +166,7 @@ def get_all_connected_interfaces(): """ # find all cmsis-dap devices try: - all_devices = libusb_package.find(find_all=True, custom_match=FindDap()) + all_devices = usb_find(find_all=True, custom_match=FindDap()) except usb.core.NoBackendError: if not PyUSB.did_show_no_libusb_warning: LOG.warning("CMSIS-DAPv1 probes may not be detected because no libusb library was found.") diff --git a/pyocd/probe/pydapaccess/interface/pyusb_v2_backend.py b/pyocd/probe/pydapaccess/interface/pyusb_v2_backend.py index a9b0a1a0c..e20079089 100644 --- a/pyocd/probe/pydapaccess/interface/pyusb_v2_backend.py +++ b/pyocd/probe/pydapaccess/interface/pyusb_v2_backend.py @@ -38,7 +38,6 @@ TRACE.setLevel(logging.CRITICAL) try: - import libusb_package import usb.core import usb.util except ImportError: @@ -46,6 +45,12 @@ else: IS_AVAILABLE = True +try: + from libusb_package import find as usb_find +except ImportError: + from usb.core import find as usb_find + + class PyUSBv2(Interface): """@brief CMSIS-DAPv2 interface using pyUSB.""" @@ -84,7 +89,7 @@ def open(self): assert self.closed is True # Get device handle - dev = libusb_package.find(custom_match=HasCmsisDapv2Interface(self.serial_number)) + dev = usb_find(custom_match=HasCmsisDapv2Interface(self.serial_number)) if dev is None: raise DAPAccessIntf.DeviceError("Device %s not found" % self.serial_number) @@ -187,7 +192,7 @@ def get_all_connected_interfaces(): """@brief Returns all the connected devices with a CMSIS-DAPv2 interface.""" # find all cmsis-dap devices try: - all_devices = libusb_package.find(find_all=True, custom_match=HasCmsisDapv2Interface()) + all_devices = usb_find(find_all=True, custom_match=HasCmsisDapv2Interface()) except usb.core.NoBackendError: common.show_no_libusb_warning() return [] diff --git a/pyocd/probe/stlink/usb.py b/pyocd/probe/stlink/usb.py index c9a400af2..883c014ce 100644 --- a/pyocd/probe/stlink/usb.py +++ b/pyocd/probe/stlink/usb.py @@ -15,7 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import libusb_package +try: + from libusb_package import find as usb_find +except ImportError: + from usb.core import find as usb_find import usb.core import usb.util import logging @@ -101,7 +104,7 @@ def _usb_match(cls, dev): @classmethod def get_all_connected_devices(cls): try: - devices = libusb_package.find(find_all=True, custom_match=cls._usb_match) + devices = usb_find(find_all=True, custom_match=cls._usb_match) except usb.core.NoBackendError: common.show_no_libusb_warning() return []