From dba071362f547e2fa0c8027e432b3e1e502c3e42 Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Wed, 10 Mar 2021 13:11:05 -0600 Subject: [PATCH 1/2] pyDAPAccess: remove backend check warnings. --- pyocd/probe/pydapaccess/interface/hidapi_backend.py | 4 +--- pyocd/probe/pydapaccess/interface/pyusb_backend.py | 2 -- pyocd/probe/pydapaccess/interface/pywinusb_backend.py | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pyocd/probe/pydapaccess/interface/hidapi_backend.py b/pyocd/probe/pydapaccess/interface/hidapi_backend.py index ff2552486..b64f05e1d 100644 --- a/pyocd/probe/pydapaccess/interface/hidapi_backend.py +++ b/pyocd/probe/pydapaccess/interface/hidapi_backend.py @@ -1,5 +1,6 @@ # pyOCD debugger # Copyright (c) 2006-2020 Arm Limited +# Copyright (c) 2021 Chris Reed # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +16,6 @@ # limitations under the License. import logging -import platform import six from .interface import Interface @@ -28,8 +28,6 @@ try: import hid except: - if platform.system() == 'Darwin': - LOG.error("hidapi is required for CMSIS-DAP support on macOS") IS_AVAILABLE = False else: IS_AVAILABLE = True diff --git a/pyocd/probe/pydapaccess/interface/pyusb_backend.py b/pyocd/probe/pydapaccess/interface/pyusb_backend.py index ec532bf37..b0087b05e 100644 --- a/pyocd/probe/pydapaccess/interface/pyusb_backend.py +++ b/pyocd/probe/pydapaccess/interface/pyusb_backend.py @@ -39,8 +39,6 @@ import usb.core import usb.util except: - if platform.system() == "Linux": - LOG.error("PyUSB is required for CMSIS-DAP support on Linux") IS_AVAILABLE = False else: IS_AVAILABLE = True diff --git a/pyocd/probe/pydapaccess/interface/pywinusb_backend.py b/pyocd/probe/pydapaccess/interface/pywinusb_backend.py index 5861c8afb..2427f3eeb 100644 --- a/pyocd/probe/pydapaccess/interface/pywinusb_backend.py +++ b/pyocd/probe/pydapaccess/interface/pywinusb_backend.py @@ -1,5 +1,6 @@ # pyOCD debugger # Copyright (c) 2006-2020 Arm Limited +# Copyright (c) 2021 Chris Reed # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +16,6 @@ # limitations under the License. import logging -import platform import collections from time import sleep import six @@ -32,8 +32,6 @@ try: import pywinusb.hid as hid except: - if platform.system() == "Windows": - LOG.error("PyWinUSB is required on a Windows Machine") IS_AVAILABLE = False else: IS_AVAILABLE = True From dadeca080dc609e9fcdb08a8167de4e017098da1 Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Wed, 10 Mar 2021 13:11:23 -0600 Subject: [PATCH 2/2] pyDAPAccess: use platform.system() for backend OS detection. --- pyocd/probe/pydapaccess/interface/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pyocd/probe/pydapaccess/interface/__init__.py b/pyocd/probe/pydapaccess/interface/__init__.py index adc61e0c4..3c364b67c 100644 --- a/pyocd/probe/pydapaccess/interface/__init__.py +++ b/pyocd/probe/pydapaccess/interface/__init__.py @@ -1,5 +1,6 @@ # pyOCD debugger # Copyright (c) 2006-2013 Arm Limited +# Copyright (c) 2021 Chris Reed # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +17,7 @@ import os import logging +import platform from ..dap_access_api import DAPAccessIntf from .hidapi_backend import HidApiUSB from .pyusb_backend import PyUSB @@ -40,8 +42,9 @@ USB_BACKEND = "" # Select backend based on OS and availability. +system = platform.system() if not USB_BACKEND: - if os.name == "nt": + if system == "Windows": # Prefer hidapi over pyWinUSB for Windows, since pyWinUSB has known bug(s) if HidApiUSB.isAvailable: USB_BACKEND = "hidapiusb" @@ -49,12 +52,12 @@ USB_BACKEND = "pywinusb" else: raise DAPAccessIntf.DeviceError("No USB backend found") - elif os.name == "posix": - # Select hidapi for OS X and pyUSB for Linux. - if os.uname()[0] == 'Darwin': - USB_BACKEND = "hidapiusb" - else: - USB_BACKEND = "pyusb" + # Default to hidapi for OS X. + elif system == "Darwin": + USB_BACKEND = "hidapiusb" + # Default to pyUSB for Linux. + elif system == "Linux": + USB_BACKEND = "pyusb" else: raise DAPAccessIntf.DeviceError("No USB backend found")