Skip to content

Commit 6dc261a

Browse files
authored
Add mps2 an521, reset on loading to Ram and soft-bkpt-as-hard (#1638)
* Add support for mps2_an521 * Generate reset when loading to Ram * Add support for soft-bkpt-as-hard
1 parent 975fe95 commit 6dc261a

File tree

7 files changed

+92
-3
lines changed

7 files changed

+92
-3
lines changed

pyocd/core/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ class OptionInfo(NamedTuple):
196196
OptionInfo('xpsr_control_fields', bool, False,
197197
"When set to True, XPSR and CONTROL registers will have their respective bitfields defined "
198198
"for presentation in gdb."),
199+
OptionInfo('soft_bkpt_as_hard', bool, False,
200+
"Replace software breakpoints with hardware breakpoints."),
199201
]
200202

201203
## @brief The runtime dictionary of options.

pyocd/flash/loader.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def program(self, progress_cb: Optional[ProgressCallback] = None, **kwargs: Any)
9494
if progress_cb is not None:
9595
progress_cb(1.0)
9696

97+
if kwargs.get("no_reset", False) is False:
98+
target.reset_and_halt()
99+
97100
# Return some performance numbers.
98101
return ProgrammingInfo(
99102
program_time=time() - start_time,

pyocd/gdbserver/gdbserver.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,16 @@ def __init__(self, session, core=None):
136136
self.semihost_use_syscalls = session.options.get('semihost_use_syscalls') # Not subscribed.
137137
self.serve_local_only = session.options.get('serve_local_only') # Not subscribed.
138138
self.report_core = session.options.get('report_core_number')
139+
self.soft_bkpt_as_hard = session.options.get('soft_bkpt_as_hard')
140+
139141
# Subscribe to changes for those of the above options that make sense to change at runtime.
140142
self.session.options.subscribe(self._option_did_change, [
141143
'vector_catch',
142144
'step_into_interrupt',
143145
'persist',
144146
'enable_semihosting',
145147
'report_core_number',
148+
'soft_bkpt_as_hard',
146149
])
147150

148151
self.packet_size = 2048
@@ -464,7 +467,8 @@ def breakpoint(self, data):
464467
# handle software breakpoint Z0/z0
465468
if data[1:2] == b'0':
466469
if data[0:1] == b'Z':
467-
if not self.target.set_breakpoint(addr, Target.BreakpointType.SW):
470+
bkpt_type = Target.BreakpointType.HW if self.soft_bkpt_as_hard else Target.BreakpointType.SW
471+
if not self.target.set_breakpoint(addr, bkpt_type):
468472
return self.create_rsp_packet(b'E01') #EPERM
469473
else:
470474
self.target.remove_breakpoint(addr)
@@ -1266,4 +1270,5 @@ def _option_did_change(self, notification):
12661270
LOG.info("Semihosting %s", ('enabled' if self.enable_semihosting else 'disabled'))
12671271
elif notification.event == 'report_core_number':
12681272
self.report_core = notification.data.new_value
1269-
1273+
elif notification.event == 'soft_bkpt_as_hard':
1274+
self.soft_bkpt_as_hard = notification.data.new_value

pyocd/subcommands/gdbserver_cmd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def get_args(cls) -> List[argparse.ArgumentParser]:
8989
help="Allow single stepping to step into interrupts.")
9090
gdbserver_options.add_argument("-c", "--command", dest="commands", metavar="CMD", action='append', nargs='+',
9191
help="Run command (OpenOCD compatibility).")
92+
gdbserver_options.add_argument("-bh", "--soft-bkpt-as-hard", dest="soft_bkpt_as_hard", default=False, action="store_true",
93+
help="Replace software breakpoints with hardware breakpoints.")
9294

9395
return [cls.CommonOptions.COMMON, cls.CommonOptions.CONNECT, gdbserver_parser]
9496

@@ -147,6 +149,7 @@ def invoke(self) -> int:
147149
'enable_semihosting' : self._args.enable_semihosting,
148150
'serve_local_only' : self._args.serve_local_only,
149151
'vector_catch' : self._args.vector_catch,
152+
'soft_bkpt_as_hard' : self._args.soft_bkpt_as_hard,
150153
})
151154

152155
# Split list of cores to serve.

pyocd/target/builtin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
from . import target_HC32L13x
125125
from . import target_HC32L19x
126126
from . import target_HC32L07x
127+
from . import target_MPS2_AN521
127128
from . import target_MPS3_AN522
128129
from . import target_MPS3_AN540
129130
from . import target_RP2040
@@ -143,6 +144,7 @@
143144
# instead of dashes punctuation. See pyocd.target.normalise_target_type_name() for the code that
144145
# normalises user-provided target type names for comparison with these.
145146
BUILTIN_TARGETS = {
147+
'mps2_an521': target_MPS2_AN521.AN521,
146148
'mps3_an522': target_MPS3_AN522.AN522,
147149
'mps3_an540': target_MPS3_AN540.AN540,
148150
'cortex_m': CoreSightTarget,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# pyOCD debugger
2+
# Copyright (c) 2023 Arm Limited
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from typing import Optional
18+
from ...coresight.coresight_target import CoreSightTarget
19+
from ...core.memory_map import (RamRegion, MemoryMap)
20+
21+
from ...core.target import Target
22+
23+
# see https://developer.arm.com/documentation/101104/0200/programmers-model/system-control-element/system-control-register-block
24+
SYSTEM_CONTROL = 0x50021000
25+
RESET_MASK = SYSTEM_CONTROL + 0x104
26+
RESET_MASK_SYSRSTREQ0_EN = 1 << 4
27+
RESET_MASK_SYSRSTREQ1_EN = 1 << 5
28+
CPU_WAIT = SYSTEM_CONTROL + 0x118
29+
CPU_WAIT_CPU0 = 1
30+
CPU_WAIT_CPU1 = 2
31+
32+
class AN521(CoreSightTarget):
33+
34+
VENDOR = "Arm"
35+
36+
MEMORY_MAP = MemoryMap(
37+
RamRegion( name='code_ns', start=0x00000000, length=0x08000000, access='rwx'),
38+
RamRegion( name='code_s', start=0x10000000, length=0x08000000, access='rwxs'),
39+
40+
RamRegion( name='sram_ns', start=0x20000000, length=0x02000000, access='rwx'),
41+
RamRegion( name='mtb_ns', start=0x24000000, length=0x00004000, access='rwx'),
42+
RamRegion( name='sram2_ns', start=0x28000000, length=0x00200000, access='rwx'),
43+
RamRegion( name='sram3_ns', start=0x28200000, length=0x00200000, access='rwx'),
44+
45+
RamRegion( name='sram_s', start=0x30000000, length=0x02000000, access='rwxs'),
46+
RamRegion( name='mtb_s', start=0x34000000, length=0x00004000, access='rwxs'),
47+
RamRegion( name='sram2_s', start=0x38000000, length=0x00200000, access='rwxs'),
48+
RamRegion( name='sram3_s', start=0x38200000, length=0x00200000, access='rwxs'),
49+
# External Parallel SRAM only mapped to non-secure
50+
RamRegion( name='psram_ns', start=0x80000000, length=0x01000000, access='rwx'),
51+
)
52+
53+
def __init__(self, session):
54+
super().__init__(session, self.MEMORY_MAP)
55+
56+
def create_init_sequence(self):
57+
seq = super().create_init_sequence()
58+
59+
seq.insert_before('halt_on_connect',
60+
('enable_sysresetreq', self._enable_sysresetreq),
61+
)
62+
63+
return seq
64+
65+
def _enable_sysresetreq(self):
66+
reset_mask = self.read32(RESET_MASK)
67+
reset_mask |= RESET_MASK_SYSRSTREQ0_EN
68+
self.write32(RESET_MASK, reset_mask)
69+
70+
71+
def reset_and_halt(self, reset_type: Optional[Target.ResetType] = None):
72+
self.write32(CPU_WAIT, CPU_WAIT_CPU1)
73+
super().reset_and_halt(reset_type)

pyocd/tools/gdb_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def build_parser(self):
7878
parser.add_argument("-s", "--step-int", dest="step_into_interrupt", default=None, action="store_true", help="Allow single stepping to step into interrupts.")
7979
parser.add_argument("-f", "--frequency", dest="frequency", default=None, type=int, help="Set the SWD clock frequency in Hz.")
8080
parser.add_argument("-o", "--persist", dest="persist", default=None, action="store_true", help="Keep GDB server running even after remote has detached.")
81-
parser.add_argument("-bh", "--soft-bkpt-as-hard", dest="soft_bkpt_as_hard", default=False, action="store_true", help="Replace software breakpoints with hardware breakpoints (ignored).")
81+
parser.add_argument("-bh", "--soft-bkpt-as-hard", dest="soft_bkpt_as_hard", default=False, action="store_true", help="Replace software breakpoints with hardware breakpoints.")
8282
group = parser.add_mutually_exclusive_group()
8383
group.add_argument("-ce", "--chip_erase", action="store_true", help="Use chip erase when programming.")
8484
group.add_argument("-se", "--sector_erase", action="store_true", help="Use sector erase when programming.")
@@ -133,6 +133,7 @@ def get_gdb_server_settings(self, args):
133133
'fast_program' : args.fast_program,
134134
'enable_semihosting' : args.enable_semihosting,
135135
'semihost_console_type' : args.semihost_console_type,
136+
'soft_bkpt_as_hard' : args.soft_bkpt_as_hard,
136137
'telnet_port' : args.telnet_port,
137138
'semihost_use_syscalls' : args.semihost_use_syscalls,
138139
'serve_local_only' : args.serve_local_only,

0 commit comments

Comments
 (0)