target/cortex_m: prevent asserting reset if examine is deferred
[openocd.git] / src / target / adi_v5_dapdirect.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*
4 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
5 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
6 */
7
8 /**
9 * @file
10 * Utilities to support in-circuit debuggers that provide APIs to access
11 * directly ARM DAP, hiding the access to the underlining transport used
12 * for the physical connection (either JTAG or SWD).
13 * E.g. STMicroelectronics ST-Link/V2 (from version V2J24) and STLINK-V3.
14 *
15 * Single-DAP support only.
16 *
17 * For details, see "ARM IHI 0031A"
18 * ARM Debug Interface v5 Architecture Specification
19 *
20 * FIXME: in JTAG mode, trst is not managed
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <jtag/interface.h>
28 #include <jtag/tcl.h>
29 #include <transport/transport.h>
30
31 COMMAND_HANDLER(dapdirect_jtag_empty_command)
32 {
33 LOG_DEBUG("dapdirect_jtag_empty_command(\"%s\")", CMD_NAME);
34
35 return ERROR_OK;
36 }
37
38 COMMAND_HANDLER(dapdirect_jtag_reset_command)
39 {
40 enum reset_types jtag_reset_config = jtag_get_reset_config();
41
42 /*
43 * in case the adapter has not already handled asserting srst
44 * we will attempt it again
45 */
46 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
47 if (jtag_reset_config & RESET_SRST_NO_GATING) {
48 adapter_assert_reset();
49 return ERROR_OK;
50 }
51 LOG_WARNING("\'srst_nogate\' reset_config option is required");
52 }
53 adapter_deassert_reset();
54 return ERROR_OK;
55 }
56
57 static const struct command_registration dapdirect_jtag_subcommand_handlers[] = {
58 {
59 .name = "newtap",
60 .mode = COMMAND_CONFIG,
61 .handler = handle_jtag_newtap,
62 .help = "declare a new TAP",
63 .usage = "basename tap_type '-irlen' count "
64 "['-enable'|'-disable'] "
65 "['-expected_id' number] "
66 "['-ignore-version'] "
67 "['-ignore-bypass'] "
68 "['-ircapture' number] "
69 "['-ir-bypass' number] "
70 "['-mask' number]",
71 },
72 {
73 .name = "init",
74 .mode = COMMAND_ANY,
75 .handler = dapdirect_jtag_empty_command,
76 .usage = ""
77 },
78 {
79 .name = "arp_init",
80 .mode = COMMAND_ANY,
81 .handler = dapdirect_jtag_empty_command,
82 .usage = ""
83 },
84 {
85 .name = "arp_init-reset",
86 .mode = COMMAND_ANY,
87 .handler = dapdirect_jtag_reset_command,
88 .usage = ""
89 },
90 {
91 .name = "tapisenabled",
92 .mode = COMMAND_EXEC,
93 .handler = handle_jtag_tap_enabler,
94 .help = "Returns a Tcl boolean (0/1) indicating whether "
95 "the TAP is enabled (1) or not (0).",
96 .usage = "tap_name",
97 },
98 {
99 .name = "tapenable",
100 .mode = COMMAND_EXEC,
101 .handler = handle_jtag_tap_enabler,
102 .help = "Try to enable the specified TAP using the "
103 "'tap-enable' TAP event.",
104 .usage = "tap_name",
105 },
106 {
107 .name = "tapdisable",
108 .mode = COMMAND_EXEC,
109 .handler = dapdirect_jtag_empty_command,
110 .usage = "",
111 },
112 {
113 .name = "configure",
114 .mode = COMMAND_ANY,
115 .handler = dapdirect_jtag_empty_command,
116 .usage = "",
117 },
118 {
119 .name = "cget",
120 .mode = COMMAND_EXEC,
121 .handler = handle_jtag_configure,
122 .usage = "",
123 },
124 {
125 .name = "names",
126 .mode = COMMAND_ANY,
127 .handler = dapdirect_jtag_empty_command,
128 .usage = "",
129 },
130 COMMAND_REGISTRATION_DONE
131 };
132
133 static const struct command_registration dapdirect_jtag_handlers[] = {
134 {
135 .name = "jtag",
136 .mode = COMMAND_ANY,
137 .chain = dapdirect_jtag_subcommand_handlers,
138 .usage = "",
139 },
140 {
141 .name = "jtag_ntrst_delay",
142 .mode = COMMAND_ANY,
143 .handler = dapdirect_jtag_empty_command,
144 .usage = "",
145 },
146 COMMAND_REGISTRATION_DONE
147 };
148
149 static const struct command_registration dapdirect_swd_subcommand_handlers[] = {
150 {
151 .name = "newdap",
152 .mode = COMMAND_CONFIG,
153 .handler = handle_jtag_newtap,
154 .help = "declare a new SWD DAP",
155 .usage = "basename dap_type ['-irlen' count] "
156 "['-enable'|'-disable'] "
157 "['-expected_id' number] "
158 "['-ignore-version'] "
159 "['-ignore-bypass'] "
160 "['-ircapture' number] "
161 "['-ir-bypass' number] "
162 "['-mask' number]",
163 },
164 COMMAND_REGISTRATION_DONE
165 };
166
167 static const struct command_registration dapdirect_swd_handlers[] = {
168 {
169 .name = "swd",
170 .mode = COMMAND_ANY,
171 .help = "SWD command group",
172 .usage = "",
173 .chain = dapdirect_swd_subcommand_handlers,
174 },
175 COMMAND_REGISTRATION_DONE
176 };
177
178 static int dapdirect_jtag_select(struct command_context *ctx)
179 {
180 LOG_DEBUG("dapdirect_jtag_select()");
181
182 return register_commands(ctx, NULL, dapdirect_jtag_handlers);
183 }
184
185 static int dapdirect_swd_select(struct command_context *ctx)
186 {
187 LOG_DEBUG("dapdirect_swd_select()");
188
189 return register_commands(ctx, NULL, dapdirect_swd_handlers);
190 }
191
192 static int dapdirect_init(struct command_context *ctx)
193 {
194 enum reset_types jtag_reset_config = jtag_get_reset_config();
195
196 LOG_DEBUG("dapdirect_init()");
197
198 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
199 if (jtag_reset_config & RESET_SRST_NO_GATING)
200 adapter_assert_reset();
201 else
202 LOG_WARNING("\'srst_nogate\' reset_config option is required");
203 } else
204 adapter_deassert_reset();
205
206 return ERROR_OK;
207 }
208
209 static struct transport dapdirect_jtag_transport = {
210 .name = "dapdirect_jtag",
211 .select = dapdirect_jtag_select,
212 .init = dapdirect_init,
213 };
214
215 static struct transport dapdirect_swd_transport = {
216 .name = "dapdirect_swd",
217 .select = dapdirect_swd_select,
218 .init = dapdirect_init,
219 };
220
221 static void dapdirect_constructor(void) __attribute__((constructor));
222 static void dapdirect_constructor(void)
223 {
224 transport_register(&dapdirect_jtag_transport);
225 transport_register(&dapdirect_swd_transport);
226 }
227
228 /**
229 * Returns true if the current debug session
230 * is using JTAG as its transport.
231 */
232 bool transport_is_dapdirect_jtag(void)
233 {
234 return get_current_transport() == &dapdirect_jtag_transport;
235 }
236
237 /**
238 * Returns true if the current debug session
239 * is using SWD as its transport.
240 */
241 bool transport_is_dapdirect_swd(void)
242 {
243 return get_current_transport() == &dapdirect_swd_transport;
244 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)