Skip to content

Commit 5f930b4

Browse files
authored
Merge pull request #1022 from ttt-t3r/lpc55s69-add-unlock
Added code to unlock AP for lpc55s69
2 parents f384bde + fa07d4e commit 5f930b4

File tree

7 files changed

+226
-39
lines changed

7 files changed

+226
-39
lines changed

docs/options.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ processed. The consequence of this is that these options cannot be set in a YAML
1414

1515
<tr><th>Option Name</th><th>Type</th><th>Default</th><th>Description</th></tr>
1616

17+
<tr><td>adi.v5.max_invalid_ap_count</td>
18+
<td>int</td>
19+
<td>3</td>
20+
<td>
21+
If this number of invalid APs is found in a row, then AP scanning will stop. The 'scan_all_aps' option
22+
takes precedence over this option if set.
23+
</td></tr>
24+
1725
<tr><td>allow_no_cores</td>
1826
<td>bool</td>
1927
<td>False</td>

pyocd/core/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
## @brief Definitions of the builtin options.
2323
BUILTIN_OPTIONS = [
2424
# Common options
25+
OptionInfo('adi.v5.max_invalid_ap_count', int, 3,
26+
"If this number of invalid APs is found in a row, then AP scanning will stop. The 'scan_all_aps' option "
27+
"takes precedence over this option if set."),
2528
OptionInfo('allow_no_cores', bool, False,
2629
"Prevents raising an error if no core were found after CoreSight discovery."),
2730
OptionInfo('auto_unlock', bool, True,

pyocd/coresight/ap.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,39 @@ def __init__(self, dp, ap_address, idr=None, name="", flags=0, cmpid=None):
528528
def supported_transfer_sizes(self):
529529
"""! @brief Tuple of transfer sizes supported by this AP."""
530530
return self._transfer_sizes
531+
532+
@property
533+
def is_enabled(self):
534+
"""! @brief Whether any memory transfers are allowed by this AP.
535+
536+
Memory transfers may be disabled by an input signal to the AP. This is often done when debug security
537+
is enabled on the device, to disallow debugger access to internal memory.
538+
"""
539+
return self.is_enabled_for(Target.SecurityState.NONSECURE)
540+
541+
def is_enabled_for(self, security_state):
542+
"""! @brief Checks whether memory transfers are allowed by this AP for the given security state.
543+
544+
Memory transfers may be disabled by an input signal to the AP. This is often done when debug security
545+
is enabled on the device, to disallow debugger access to internal memory.
546+
547+
@param self The AP instance.
548+
@param security_state One of the @ref pyocd.core.target.Target.SecurityState "SecurityState" enums.
549+
@return Boolean indicating whether memory transfers can be performed in the requested security state. You
550+
may change the security state used for transfers with the hnonsec property and hnonsec_lock() method.
551+
"""
552+
assert isinstance(security_state, Target.SecurityState)
553+
554+
# Call to superclass to read CSW. We want to bypass our CSW cache since the enable signal can change
555+
# asynchronously.
556+
csw = AccessPort.read_reg(self, self._reg_offset + MEM_AP_CSW)
557+
if security_state is Target.SecurityState.NONSECURE:
558+
# Nonsecure transfers are always allowed when security transfers are enabled.
559+
return (csw & (CSW_DEVICEEN | CSW_SDEVICEEN)) != 0
560+
elif security_state is Target.SecurityState.SECURE:
561+
return (csw & CSW_SDEVICEEN) != 0
562+
else:
563+
assert False, "unsupported security state"
531564

532565
@locked
533566
def init(self):
@@ -694,6 +727,10 @@ def _init_rom_table_base():
694727
def find_components(self):
695728
try:
696729
if self.has_rom_table:
730+
if not self.is_enabled:
731+
LOG.warning("Skipping CoreSight discovery for %s because it is disabled", self.short_description)
732+
return
733+
697734
# Import locally to work around circular import.
698735
from .rom_table import (CoreSightComponentID, ROMTable)
699736

pyocd/coresight/discovery.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ def discover(self):
5151
raise NotImplementedError()
5252

5353
def _create_component(self, cmpid):
54-
LOG.debug("Creating %s component", cmpid.name)
55-
cmp = cmpid.factory(cmpid.ap, cmpid, cmpid.address)
56-
cmp.init()
54+
try:
55+
LOG.debug("Creating %s component", cmpid.name)
56+
cmp = cmpid.factory(cmpid.ap, cmpid, cmpid.address)
57+
cmp.init()
58+
except exceptions.Error as err:
59+
LOG.error("Error attempting to create component %s: %s", cmpid.name, err,
60+
exc_info=self.session.log_tracebacks)
5761

5862
def _create_cores(self):
5963
self._apply_to_all_components(self._create_component,
@@ -127,7 +131,7 @@ def _find_aps(self):
127131
invalid_count = 0
128132
elif not self.session.options.get('scan_all_aps'):
129133
invalid_count += 1
130-
if invalid_count == 2:
134+
if invalid_count == self.session.options.get('adi.v5.max_invalid_ap_count'):
131135
break
132136
except exceptions.Error as e:
133137
LOG.error("Exception while probing AP#%d: %s", apsel, e,

pyocd/target/family/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from collections import namedtuple
1919

2020
from . import target_kinetis
21+
from . import target_lpc5500
2122
from . import target_nRF52
2223

2324
## @brief Container for family matching information.
@@ -32,6 +33,7 @@
3233
# 'DsubFamily' (if present) attributes, or the 'Dname' part number. The comparisons are performed in
3334
# order from specific to general, starting with the part number.
3435
FAMILIES = [
36+
FamilyInfo("NXP", re.compile(r'LPC55S?[0-9]{2}.*'), target_lpc5500.LPC5500Family ),
3537
FamilyInfo("NXP", re.compile(r'MK[LEVWS]?.*'), target_kinetis.Kinetis ),
3638
FamilyInfo("Nordic Semiconductor", re.compile(r'nRF52[0-9]+.*'), target_nRF52.NRF52 ),
3739
]

0 commit comments

Comments
 (0)