Skip to content

Commit 9a78c29

Browse files
committed
DebugProbe: refactored individual flags into set of capabilities.
- Added DebugProbe.Capability enums and 'capabilities' property - Replaced has_swo() and 'supports_swj_sequence' property with capabilities. - Managed DP/AP register access capabilities.
1 parent 2895f10 commit 9a78c29

File tree

6 files changed

+59
-29
lines changed

6 files changed

+59
-29
lines changed

pyocd/coresight/dap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ def connect(self, protocol=None):
132132
@exception TransferError
133133
"""
134134
protocol_name = self._session.options.get('dap_protocol').strip().lower()
135-
send_swj = self._session.options.get('dap_enable_swj') and self._probe.supports_swj_sequence
135+
send_swj = self._session.options.get('dap_enable_swj') \
136+
and (DebugProbe.Capability.SWJ_SEQUENCE in self._probe.capabilities)
136137
use_deprecated = self._session.options.get('dap_use_deprecated_swj')
137138

138139
# Convert protocol from setting if not passed as parameter.

pyocd/probe/cmsis_dap_probe.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(self, device):
9999
self._protocol = None
100100
self._is_open = False
101101
self._dp_select = -1
102+
self._caps = set()
102103

103104
@property
104105
def description(self):
@@ -136,8 +137,8 @@ def is_open(self):
136137
return self._is_open
137138

138139
@property
139-
def supports_swj_sequence(self):
140-
return True
140+
def capabilities(self):
141+
return self._caps
141142

142143
def create_associated_board(self):
143144
assert self.session is not None
@@ -163,6 +164,14 @@ def open(self):
163164
self._supported_protocols.append(DebugProbe.Protocol.SWD)
164165
if self._capabilities & self.JTAG_CAPABILITY_MASK:
165166
self._supported_protocols.append(DebugProbe.Protocol.JTAG)
167+
168+
self._caps = {
169+
self.Capability.SWJ_SEQUENCE,
170+
self.Capability.BANKED_DP_REGISTERS,
171+
self.Capability.APv2_ADDRESSES,
172+
}
173+
if self._link.has_swo():
174+
self._caps.add(self.Capability.SWO)
166175
except DAPAccess.Error as exc:
167176
six.raise_from(self._convert_exception(exc), exc)
168177

@@ -372,12 +381,6 @@ def write_ap_multiple(self, addr, values):
372381
# SWO functions
373382
# ------------------------------------------- #
374383

375-
def has_swo(self):
376-
try:
377-
return self._link.has_swo()
378-
except DAPAccess.Error as exc:
379-
six.raise_from(self._convert_exception(exc), exc)
380-
381384
def swo_start(self, baudrate):
382385
try:
383386
self._link.swo_configure(True, baudrate)

pyocd/probe/debug_probe.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pyOCD debugger
2-
# Copyright (c) 2018-2019 Arm Limited
2+
# Copyright (c) 2018-2020 Arm Limited
33
# SPDX-License-Identifier: Apache-2.0
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,6 +32,32 @@ class Protocol(Enum):
3232
'default': Protocol.DEFAULT,
3333
}
3434

35+
class Capability(Enum):
36+
"""! @brief Probe capabilities."""
37+
## @brief Whether the probe supports the swj_sequence() API.
38+
#
39+
# If this property is True, then the swj_sequence() method is used to move between protocols.
40+
# If False, it is assumed the probe firmware automatically manages the protocol switch.
41+
SWJ_SEQUENCE = 0
42+
43+
## @brief Whether the probe supports receiving SWO data.
44+
SWO = 1
45+
46+
## @brief Whether the probe can access banked DP registers.
47+
BANKED_DP_REGISTERS = 2
48+
49+
## @brief Whether the probe can access APv2 registers.
50+
APv2_ADDRESSES = 3
51+
52+
## @brief Whether the probe automatically handles AP selection in the DP.
53+
#
54+
# If this capability is not present, the DebugPort object will perform the AP selection
55+
# by DP register writes.
56+
MANAGED_AP_SELECTION = 4
57+
58+
## @brief whether the probe automatically handles access of banked DAP registers.
59+
MANAGED_DPBANKSEL = 5
60+
3561
@classmethod
3662
def get_all_connected_probes(cls):
3763
"""! @brief Returns a list of DebugProbe instances."""
@@ -108,11 +134,10 @@ def is_open(self):
108134
raise NotImplementedError()
109135

110136
@property
111-
def supports_swj_sequence(self):
112-
"""! @brief Whether the probe supports the swj_sequence() API.
137+
def capabilities(self):
138+
"""! @brief A set of DebugProbe.Capability enums indicating the probe's features.
113139
114-
If this property is True, then the swj_sequence() method is used to move between protocols.
115-
If False, it is assumed the probe firmware automatically manages the protocol switch.
140+
This value should not be trusted until after the probe is opened.
116141
"""
117142
raise NotImplementedError()
118143

@@ -251,10 +276,6 @@ def get_memory_interface_for_ap(self, ap_address):
251276
## @name SWO
252277
##@{
253278

254-
def has_swo(self):
255-
"""! @brief Returns bool indicating whether the probe supports SWO."""
256-
raise NotImplementedError()
257-
258279
def swo_start(self, baudrate):
259280
"""! @brief Start receiving SWO data at the given baudrate.
260281

pyocd/probe/jlink_probe.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def is_open(self):
129129
return self._link.opened
130130

131131
@property
132-
def supports_swj_sequence(self):
133-
return False
132+
def capabilities(self):
133+
return {self.Capability.SWO}
134134

135135
def open(self):
136136
try:
@@ -311,9 +311,6 @@ def write_ap_multiple(self, addr, values):
311311
for v in values:
312312
self.write_ap(addr, v)
313313

314-
def has_swo(self):
315-
return True
316-
317314
def swo_start(self, baudrate):
318315
try:
319316
self._jlink.swo_start(baudrate)

pyocd/probe/stlink_probe.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(self, device):
5252
self._memory_interfaces = {}
5353
self._mbed_info = None
5454
self._board_id = None
55+
self._caps = set()
5556

5657
# Try to detect associated board info via the STLinkV2-1 MSD volume.
5758
detector = create_mbed_detector()
@@ -101,8 +102,8 @@ def is_open(self):
101102
return self._is_open
102103

103104
@property
104-
def supports_swj_sequence(self):
105-
return False
105+
def capabilities(self):
106+
return self._caps
106107

107108
def create_associated_board(self):
108109
assert self.session is not None
@@ -114,6 +115,15 @@ def create_associated_board(self):
114115
def open(self):
115116
self._link.open()
116117
self._is_open = True
118+
119+
# Update capabilities.
120+
self._caps = {
121+
self.Capability.SWO,
122+
self.Capability.MANAGED_AP_SELECTION,
123+
self.Capability.MANAGED_DPBANKSEL,
124+
}
125+
if self._link.supports_banked_dp:
126+
self._caps.add(self.Capability.BANKED_DP_REGISTERS)
117127

118128
def close(self):
119129
self._link.close()
@@ -204,9 +214,6 @@ def get_memory_interface_for_ap(self, ap_address):
204214
self._memory_interfaces[apsel] = STLinkMemoryInterface(self._link, apsel)
205215
return self._memory_interfaces[apsel]
206216

207-
def has_swo(self):
208-
return True
209-
210217
def swo_start(self, baudrate):
211218
self._link.swo_start(baudrate)
212219

pyocd/trace/swv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from ..coresight.tpiu import TPIU
2727
from ..core.target import Target
2828
from ..core import exceptions
29+
from ..probe.debug_probe import DebugProbe
2930

3031
LOG = logging.getLogger(__name__)
3132

@@ -101,7 +102,7 @@ def init(self, sys_clock, swo_clock, console):
101102
"""
102103
self._swo_clock = swo_clock
103104

104-
if not self._session.probe.has_swo():
105+
if DebugProbe.Capability.SWO not in self._session.probe.capabilities:
105106
LOG.warning("Probe %s does not support SWO", self._session.probe.unique_id)
106107
return
107108

0 commit comments

Comments
 (0)