Skip to content

Commit

Permalink
Merge pull request #229 from c1728p9/pydapaccess_backport
Browse files Browse the repository at this point in the history
Pydapaccess backport
  • Loading branch information
c1728p9 committed Mar 14, 2016
2 parents 4087bcd + 52c2a31 commit d2f76f0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 28 deletions.
12 changes: 2 additions & 10 deletions pyOCD/pyDAPAccess/dap_access_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,15 @@
VALUE_MATCH = 1 << 4
MATCH_MASK = 1 << 5

MBED_VID = 0x0d28
MBED_PID = 0x0204


def _get_interfaces():
"""Get the connected USB devices"""
return INTERFACE[usb_backend].getAllConnectedInterface(MBED_VID, MBED_PID)
return INTERFACE[usb_backend].getAllConnectedInterface()


def _get_unique_id(interface):
"""Get the unique id from an interface"""
interface.write([0x80])
raw_id = bytearray(interface.read())
id_start = 2
id_size = raw_id[1]
unique_id = str(raw_id[id_start:id_start + id_size])
return unique_id
return interface.getSerialNumber()


class _Transfer(object):
Expand Down
17 changes: 13 additions & 4 deletions pyOCD/pyDAPAccess/interface/hidapi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,38 @@ def open(self):
pass

@staticmethod
def getAllConnectedInterface(vid, pid):
def getAllConnectedInterface():
"""
returns all the connected devices which matches HidApiUSB.vid/HidApiUSB.pid.
returns an array of HidApiUSB (Interface) objects
"""

devices = hid.enumerate(vid, pid)
devices = hid.enumerate()

if not devices:
logging.debug("No Mbed device connected")
return
return []

boards = []

for deviceInfo in devices:
product_name = deviceInfo['product_string']
if (product_name.find("CMSIS-DAP") < 0):
# Skip non cmsis-dap devices
continue

try:
dev = hid.device(vendor_id=deviceInfo['vendor_id'], product_id=deviceInfo['product_id'],
path=deviceInfo['path'])
except IOError:
logging.debug("Failed to open Mbed device")
return
continue

# Create the USB interface object for this device.
new_board = HidApiUSB()
new_board.vendor_name = deviceInfo['manufacturer_string']
new_board.product_name = deviceInfo['product_string']
new_board.serial_number = deviceInfo['serial_number']
new_board.vid = deviceInfo['vendor_id']
new_board.pid = deviceInfo['product_id']
new_board.device_info = deviceInfo
Expand Down Expand Up @@ -106,6 +112,9 @@ def read(self, timeout=-1):
"""
return self.device.read(64)

def getSerialNumber(self):
return self.serial_number

def close(self):
"""
close the interface
Expand Down
32 changes: 23 additions & 9 deletions pyOCD/pyDAPAccess/interface/pyusb_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,35 @@ def rx_task(self):
self.rcv_data.append(self.ep_in.read(self.ep_in.wMaxPacketSize, -1))

@staticmethod
def getAllConnectedInterface(vid, pid):
def getAllConnectedInterface():
"""
returns all the connected devices which matches PyUSB.vid/PyUSB.pid.
returns an array of PyUSB (Interface) objects
"""
# find all devices matching the vid/pid specified
all_devices = usb.core.find(find_all=True, idVendor=vid, idProduct=pid)
all_devices = usb.core.find(find_all=True)

if not all_devices:
logging.debug("No device connected")
return None
return []

boards = []

# iterate on all devices found
for board in all_devices:
interface_number = -1
try:
# The product string is read over USB when accessed.
# This can cause an exception to be thrown if the device
# is malfunctioning.
product = board.product
except usb.core.USBError as error:
logging.warning("Exception getting product string: %s", error)
continue
if (product is None) or (product.find("CMSIS-DAP") < 0):
# Not a cmsis-dap device so close it
usb.util.dispose_resources(board)
continue

# get active config
config = board.get_active_configuration()
Expand Down Expand Up @@ -108,8 +120,6 @@ def getAllConnectedInterface(vid, pid):
else:
ep_out = ep

product_name = usb.util.get_string(board, 2)
vendor_name = usb.util.get_string(board, 1)
"""If there is no EP for OUT then we can use CTRL EP"""
if not ep_in:
logging.error('Endpoints not found')
Expand All @@ -119,11 +129,12 @@ def getAllConnectedInterface(vid, pid):
new_board.ep_in = ep_in
new_board.ep_out = ep_out
new_board.dev = board
new_board.vid = vid
new_board.pid = pid
new_board.vid = board.idVendor
new_board.pid = board.idProduct
new_board.intf_number = interface_number
new_board.product_name = product_name
new_board.vendor_name = vendor_name
new_board.product_name = product
new_board.vendor_name = board.manufacturer
new_board.serial_number = board.serial_number
new_board.start_rx()
boards.append(new_board)

Expand Down Expand Up @@ -169,6 +180,9 @@ def setPacketCount(self, count):
# No interface level restrictions on count
self.packet_count = count

def getSerialNumber(self):
return self.serial_number

def close(self):
"""
close the interface
Expand Down
11 changes: 7 additions & 4 deletions pyOCD/pyDAPAccess/interface/pywinusb_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ def open(self):
self.device.open(shared=False)

@staticmethod
def getAllConnectedInterface(vid, pid):
def getAllConnectedInterface():
"""
returns all the connected devices which matches PyWinUSB.vid/PyWinUSB.pid.
returns an array of PyWinUSB (Interface) objects
returns all the connected CMSIS-DAP devices
"""
all_devices = hid.find_all_hid_devices()

# find devices with good vid/pid
all_mbed_devices = []
for d in all_devices:
if (d.vendor_id == vid) and (d.product_id == pid):
if (d.product_name.find("CMSIS-DAP") >= 0):
all_mbed_devices.append(d)

boards = []
Expand All @@ -83,6 +82,7 @@ def getAllConnectedInterface(vid, pid):
new_board.report = report[0]
new_board.vendor_name = dev.vendor_name
new_board.product_name = dev.product_name
new_board.serial_number = dev.serial_number
new_board.vid = dev.vendor_id
new_board.pid = dev.product_id
new_board.device = dev
Expand Down Expand Up @@ -127,6 +127,9 @@ def setPacketCount(self, count):
# No interface level restrictions on count
self.packet_count = count

def getSerialNumber(self):
return self.serial_number

def close(self):
"""
close the interface
Expand Down
14 changes: 13 additions & 1 deletion test/gdb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import os
import json
import sys
from subprocess import Popen, STDOUT, PIPE

from pyOCD.tools.gdb_server import GDBServerTool
Expand All @@ -36,6 +37,17 @@

TEST_PARAM_FILE = "test_params.txt"
TEST_RESULT_FILE = "test_results.txt"
PYTHON_GDB_FOR_OS = {
"linux": "arm-none-eabi-gdb",
"darwin": "arm-none-eabi-gdb-py",
"win": "arm-none-eabi-gdb-py",
}
PYTHON_GDB = None
for prefix, program in PYTHON_GDB_FOR_OS.iteritems():
if sys.platform.startswith(prefix):
PYTHON_GDB = program
break


parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -116,7 +128,7 @@ def test_gdb(board_id=None):
f.write(json.dumps(test_params))

# Run the test
gdb = ["arm-none-eabi-gdb-py", "--command=gdb_script.py"]
gdb = [PYTHON_GDB, "--command=gdb_script.py"]
with open("output.txt", "wb") as f:
program = Popen(gdb, stdin=PIPE, stdout=f, stderr=STDOUT)
args = ['-p=%i' % test_port, "-f=%i" % test_clock, "-b=%s" % board_id]
Expand Down

0 comments on commit d2f76f0

Please sign in to comment.