Skip to content

Commit 5ab5c32

Browse files
authored
target: add Ambiq Apollo3 target and NM180410 board support (#1632)
1 parent 6dc261a commit 5ab5c32

File tree

6 files changed

+45728
-0
lines changed

6 files changed

+45728
-0
lines changed

pyocd/board/board_ids.py

+1
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,5 @@ class BoardInfo(NamedTuple):
317317
"9906": BoardInfo( "micro:bit v2", "nrf52833", "microbitv2.bin", ),
318318
"C004": BoardInfo( "tinyK20", "k20d50m", "l1_k20d50m.bin", ),
319319
"C006": BoardInfo( "VBLUno51", "nrf51", "l1_nrf51.bin", ),
320+
"D000": BoardInfo( "NM180410", "ama3b1kk_kbr", "l1_ama3b1kk_kbr.bin", ),
320321
}

pyocd/debug/svd/data/apollo3.svd

+45,505
Large diffs are not rendered by default.

pyocd/target/builtin/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
from . import target_STM32H7B0xx
138138
from . import target_Air001
139139
from . import target_Air32F103xx
140+
from . import target_AMA3B1KK
140141

141142
## @brief Dictionary of all builtin targets.
142143
#
@@ -318,4 +319,5 @@
318319
'air32f103xp': target_Air32F103xx.Air32F103xP,
319320
'air32f103xe': target_Air32F103xx.Air32F103xE,
320321
'air32f103xg': target_Air32F103xx.Air32F103xG,
322+
'ama3b1kk_kbr': target_AMA3B1KK.AMA3B1KK_KBR,
321323
}
+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# pyOCD debugger
2+
# Copyright (c) 2023 Northern Mechatronics, Inc.
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+
import logging
18+
19+
from ...core import exceptions
20+
from ...core.memory_map import (FlashRegion, RamRegion, MemoryMap)
21+
from ...coresight.coresight_target import CoreSightTarget
22+
from ...debug.svd.loader import SVDFile
23+
from ..family.target_ama3b import AMA3BFamily
24+
25+
LOG = logging.getLogger(__name__)
26+
27+
FLASH_ALGO = {
28+
'load_address' : 0x10000000,
29+
30+
# Flash algorithm as a hex string
31+
'instructions': [
32+
0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2,
33+
0x2040f04f, 0x61812147, 0x61412100, 0x46086181, 0x20004770, 0xe92d4770, 0x4e3341f0, 0x4f332500,
34+
0x444e2406, 0x68734622, 0x46382100, 0x43054798, 0x2c401c64, 0x6832dbf6, 0x46382101, 0x43284790,
35+
0x81f0e8bd, 0x0cc1b510, 0x2101d000, 0x444a4a26, 0xf3c06853, 0x48253245, 0x28004798, 0x2001d000,
36+
0xe92dbd10, 0x460747f0, 0x07884616, 0x2001d000, 0x0491eb00, 0x8070f8df, 0x0006ea47, 0xa06cf8df,
37+
0x44c80780, 0x2000d025, 0xf5b4e01f, 0xd2017f00, 0xe00100a5, 0x6500f44f, 0x20004915, 0xe0044449,
38+
0x2b01f816, 0x2b01f801, 0x42a81c40, 0x4910d3f8, 0xc008f8d8, 0xf02708ab, 0x44490203, 0x47e04650,
39+
0xd1042800, 0x0495eba4, 0x2c00442f, 0xe8bdd1dd, 0xf8d887f0, 0x46235008, 0x4631463a, 0x46ac4650,
40+
0x47f0e8bd, 0x00004760, 0x00000004, 0x12344321, 0x00000024, 0x00000000, 0x0800004d, 0x08000051,
41+
0x08000055, 0x08000059, 0x0800005d, 0x08000061, 0x08000065, 0x08000069, 0x00000000, 0x00000000,
42+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
43+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
44+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
45+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
46+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
47+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
48+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
49+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
50+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
51+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
52+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
53+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
54+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
55+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
56+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
57+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
58+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
59+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
60+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
61+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
62+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
63+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
64+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
65+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
66+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
67+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
68+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
69+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
70+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
71+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
72+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
73+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
74+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
75+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
76+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
77+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
78+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
79+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
80+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
81+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
82+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
83+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
84+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
85+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
86+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
87+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
88+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
89+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
90+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
91+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
92+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
93+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
94+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
95+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
96+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
97+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
98+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
99+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
100+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
101+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
102+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
103+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
104+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
105+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
106+
],
107+
108+
# Relative function addresses
109+
'pc_init': 0x10000021,
110+
'pc_unInit': 0x10000033,
111+
'pc_program_page': 0x10000083,
112+
'pc_erase_sector': 0x10000065,
113+
'pc_eraseAll': 0x10000037,
114+
115+
'static_base' : 0x10000000 + 0x00000020 + 0x000000F4,
116+
'begin_stack' : 0x10000400,
117+
'begin_data' : 0x10000000 + 0x1000,
118+
'page_size' : 0x2000,
119+
'analyzer_supported' : False,
120+
'analyzer_address' : 0x00000000,
121+
'page_buffers' : [0x10001000, 0x10003000], # Enable double buffering
122+
'min_program_length' : 0x2000,
123+
124+
# Flash information
125+
'flash_start': 0xC000,
126+
'flash_size': 0xF4000,
127+
'sector_sizes': (
128+
(0x0, 0x2000),
129+
)
130+
}
131+
132+
class AMA3B1KK_KBR(CoreSightTarget):
133+
134+
VENDOR = "Ambiq Micro"
135+
136+
MEMORY_MAP = MemoryMap(
137+
FlashRegion(name='flash', start=0x0000C000, length=0x000F4000, access='rx',
138+
page_size=0x2000,
139+
sector_size=0x2000,
140+
is_boot_memory=True,
141+
algo=FLASH_ALGO),
142+
143+
RamRegion( name='sram', start=0x10000000, length=0x00060000, access='rwx')
144+
)
145+
146+
CortexM_Core = AMA3BFamily
147+
148+
def __init__(self, link):
149+
super().__init__(link, self.MEMORY_MAP)
150+
self._svd_location = SVDFile.from_builtin("apollo3.svd")
151+
152+
def create_init_sequence(self):
153+
seq = super().create_init_sequence()
154+
seq.wrap_task('discovery',
155+
lambda seq: seq.replace_task('create_cores', self.create_cores)
156+
)
157+
return seq
158+
159+
def create_cores(self):
160+
try:
161+
core = self.CortexM_Core(self.session, self.aps[0], self.memory_map, 0)
162+
core.default_reset_type = self.ResetType.SW_SYSRESETREQ
163+
self.aps[0].core = core
164+
core.init()
165+
self.add_core(core)
166+
except exceptions.Error:
167+
LOG.error("No Apollo3 Core found")

pyocd/target/family/target_ama3b.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# pyOCD debugger
2+
# Copyright (c) 2023 Northern Mechatronics, Inc.
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+
import logging
18+
19+
from ...coresight.cortex_m import CortexM
20+
21+
LOG = logging.getLogger(__name__)
22+
23+
class AMA3BFamily(CortexM):
24+
REG_MCU_CTRL_BOOTLOADER = 0x400201A0
25+
REG_MCU_CTRL_SCRATCH0 = 0x400201B0
26+
27+
def set_reset_catch(self, reset_type=None):
28+
# If Debugger Support is disabled by the SDBG bit in INFO0_SECURITY,
29+
# The least significant bit of register REG_MCU_CTRL_SCRATCH0 must be
30+
# set to indicate that a halt is requested by the debugger after
31+
# primary boot.
32+
#
33+
# Refer to document A-SOCA3B-UGGA02EN for more details.
34+
35+
# Check the REG_MCU_CTRL_BOOTLOADER register to see if secure boot
36+
# is enabled for:
37+
# bit 31:30 warm reset
38+
# bit 29:28 cold reset
39+
# bit 27:26 secure boot feature enabled
40+
secure_boot = False
41+
reg_bootloader = self.read_memory(self.REG_MCU_CTRL_BOOTLOADER)
42+
if (reg_bootloader & 0xFC000000):
43+
secure_boot = True
44+
LOG.debug("AMA3B Secure Boot: %x" % secure_boot)
45+
46+
if(secure_boot is True):
47+
# Modify only the least significant bit and preserve the scratch
48+
# register as it could be used by the application firmware.
49+
reg_scratch0 = self.read_memory(self.REG_MCU_CTRL_SCRATCH0) | 0x01
50+
self.write_memory(self.REG_MCU_CTRL_SCRATCH0, reg_scratch0)
51+
else:
52+
LOG.debug("normal_set_reset_catch")
53+
super().set_reset_catch(reset_type)
16.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)