Skip to content

Commit

Permalink
Merge pull request #545 from flit/feature/cmsis_dap_v2
Browse files Browse the repository at this point in the history
CMSIS-DAPv2 support
  • Loading branch information
flit authored Feb 21, 2019
2 parents 0648fa6 + a9628bc commit 2113285
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Requirements
- macOS, Linux, or Windows 7 or newer
- Microcontroller with an Arm Cortex-M CPU
- Supported debug probe
- [CMSIS-DAP](http://www.keil.com/pack/doc/CMSIS/DAP/html/index.html), such as an on-board debug
probe using [DAPLink](https://os.mbed.com/handbook/DAPLink) firmware.
- [CMSIS-DAP](http://www.keil.com/pack/doc/CMSIS/DAP/html/index.html) v1 (HID) and v2 (WinUSB),
such as an on-board debug probe using [DAPLink](https://os.mbed.com/handbook/DAPLink) firmware.
- STLinkV2, either on-board or the standalone version.


Expand Down
1 change: 1 addition & 0 deletions pyocd/probe/pydapaccess/cmsis_dap_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Pin:
class DAPSWOTransport:
NONE = 0
DAP_SWO_DATA = 1
DAP_SWO_EP = 2

# SWO mode options.
class DAPSWOMode:
Expand Down
36 changes: 28 additions & 8 deletions pyocd/probe/pydapaccess/dap_access_cmsis_dap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .dap_settings import DAPSettings
from .dap_access_api import DAPAccessIntf
from .cmsis_dap_core import CMSISDAPProtocol
from .interface import (INTERFACE, USB_BACKEND, WS_BACKEND)
from .interface import (INTERFACE, USB_BACKEND, USB_BACKEND_V2, WS_BACKEND)
from .cmsis_dap_core import (Command, Pin, Capabilities, DAP_TRANSFER_OK,
DAP_TRANSFER_FAULT, DAP_TRANSFER_WAIT,
DAPSWOTransport, DAPSWOMode, DAPSWOControl,
Expand All @@ -50,10 +50,16 @@ class SWOStatus:

def _get_interfaces():
"""Get the connected USB devices"""
# Get CMSIS-DAPv2 interfaces.
if DAPSettings.use_ws:
return INTERFACE[WS_BACKEND].get_all_connected_interfaces(DAPSettings.ws_host, DAPSettings.ws_port)
interfaces = INTERFACE[WS_BACKEND].get_all_connected_interfaces(DAPSettings.ws_host, DAPSettings.ws_port)
else:
return INTERFACE[USB_BACKEND].get_all_connected_interfaces()
interfaces = INTERFACE[USB_BACKEND].get_all_connected_interfaces()

# Add in CMSIS-DAPv2 interfaces.
interfaces += INTERFACE[USB_BACKEND_V2].get_all_connected_interfaces()

return interfaces


def _get_unique_id(interface):
Expand Down Expand Up @@ -675,10 +681,16 @@ def swo_configure(self, enabled, rate):

try:
if enabled:
if self._protocol.swo_transport(DAPSWOTransport.DAP_SWO_DATA) != 0:
# Select the streaming SWO endpoint if available.
if self._interface.has_swo_ep:
transport = DAPSWOTransport.DAP_SWO_EP
else:
transport = DAPSWOTransport.DAP_SWO_DATA

if self._protocol.swo_transport(transport) != 0:
self._swo_disable()
return False
if self._protocol.swo_mode(DAP_SWO_MODE.UART) != 0:
if self._protocol.swo_mode(DAPSWOMode.UART) != 0:
self._swo_disable()
return False
if self._protocol.swo_baudrate(rate) == 0:
Expand Down Expand Up @@ -709,19 +721,27 @@ def swo_control(self, start):

if start:
self._protocol.swo_control(DAPSWOControl.START)
if self._interface.has_swo_ep:
self._interface.start_swo()
self._swo_status = SWOStatus.RUNNING
else:
self._protocol.swo_control(DAPSWOControl.STOP)
if self._interface.has_swo_ep:
self._interface.stop_swo()
self._swo_status = SWOStatus.CONFIGURED
return True

def get_swo_status(self):
return self._protocol.swo_status()

def swo_read(self, count=None):
if count is None:
count = self._packet_size
return self._protocol.swo_data(count)
if self._interface.has_swo_ep:
return self._interface.read_swo()
else:
if count is None:
count = self._packet_size
status, count, data = self._protocol.swo_data(count)
return bytearray(data)

def write_reg(self, reg_id, value, dap_index=0):
assert reg_id in self.REG
Expand Down
3 changes: 3 additions & 0 deletions pyocd/probe/pydapaccess/interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import logging
from .hidapi_backend import HidApiUSB
from .pyusb_backend import PyUSB
from .pyusb_v2_backend import PyUSBv2
from .pywinusb_backend import PyWinUSB
from .ws_backend import WebSocketInterface

INTERFACE = {
'hidapiusb': HidApiUSB,
'pyusb': PyUSB,
'pyusb_v2': PyUSBv2,
'pywinusb': PyWinUSB,
'ws': WebSocketInterface
}
Expand Down Expand Up @@ -58,3 +60,4 @@
else:
raise Exception("No USB backend found")

USB_BACKEND_V2 = "pyusb_v2"
24 changes: 24 additions & 0 deletions pyocd/probe/pydapaccess/interface/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# pyOCD debugger
# Copyright (c) 2019 Arm Limited
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

USB_CLASS_COMPOSITE = 0x00
USB_CLASS_MISCELLANEOUS = 0xef

CMSIS_DAP_USB_CLASSES = [
USB_CLASS_COMPOSITE,
USB_CLASS_MISCELLANEOUS,
]

5 changes: 5 additions & 0 deletions pyocd/probe/pydapaccess/interface/pyusb_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

from .interface import Interface
from .common import CMSIS_DAP_USB_CLASSES
from ..dap_access_api import DAPAccessIntf
import logging
import os
Expand Down Expand Up @@ -256,6 +257,10 @@ def __init__(self, serial=None):

def __call__(self, dev):
"""Return True if this is a DAP device, False otherwise"""
# Check if the device class is a valid one for CMSIS-DAP.
if dev.bDeviceClass not in CMSIS_DAP_USB_CLASSES:
return False

try:
device_string = dev.product
except ValueError as error:
Expand Down
Loading

0 comments on commit 2113285

Please sign in to comment.