2 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
3 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Utilities to support in-circuit debuggers that provide APIs to access
22 * directly ARM DAP, hiding the access to the underlining transport used
23 * for the physical connection (either JTAG or SWD).
24 * E.g. STMicroelectronics ST-Link/V2 (from version V2J24) and STLINK-V3.
26 * Single-DAP support only.
28 * For details, see "ARM IHI 0031A"
29 * ARM Debug Interface v5 Architecture Specification
31 * FIXME: in JTAG mode, trst is not managed
38 #include <jtag/interface.h>
40 #include <transport/transport.h>
42 COMMAND_HANDLER(dapdirect_jtag_empty_command
)
44 LOG_DEBUG("dapdirect_jtag_empty_command(\"%s\")", CMD_NAME
);
49 COMMAND_HANDLER(dapdirect_jtag_reset_command
)
51 enum reset_types jtag_reset_config
= jtag_get_reset_config();
54 * in case the adapter has not already handled asserting srst
55 * we will attempt it again
57 if (jtag_reset_config
& RESET_CNCT_UNDER_SRST
) {
58 if (jtag_reset_config
& RESET_SRST_NO_GATING
) {
59 adapter_assert_reset();
62 LOG_WARNING("\'srst_nogate\' reset_config option is required");
64 adapter_deassert_reset();
68 static const struct command_registration dapdirect_jtag_subcommand_handlers
[] = {
71 .mode
= COMMAND_CONFIG
,
72 .jim_handler
= jim_jtag_newtap
,
73 .help
= "declare a new TAP"
78 .handler
= dapdirect_jtag_empty_command
,
84 .handler
= dapdirect_jtag_empty_command
,
88 .name
= "arp_init-reset",
90 .handler
= dapdirect_jtag_reset_command
,
94 .name
= "tapisenabled",
96 .jim_handler
= jim_jtag_tap_enabler
,
100 .mode
= COMMAND_EXEC
,
101 .jim_handler
= jim_jtag_tap_enabler
,
104 .name
= "tapdisable",
105 .mode
= COMMAND_EXEC
,
106 .handler
= dapdirect_jtag_empty_command
,
112 .handler
= dapdirect_jtag_empty_command
,
117 .mode
= COMMAND_EXEC
,
118 .jim_handler
= jim_jtag_configure
,
123 .handler
= dapdirect_jtag_empty_command
,
126 COMMAND_REGISTRATION_DONE
129 static const struct command_registration dapdirect_jtag_handlers
[] = {
133 .chain
= dapdirect_jtag_subcommand_handlers
,
137 .name
= "jtag_ntrst_delay",
139 .handler
= dapdirect_jtag_empty_command
,
142 COMMAND_REGISTRATION_DONE
145 static const struct command_registration dapdirect_swd_subcommand_handlers
[] = {
148 .mode
= COMMAND_CONFIG
,
149 .jim_handler
= jim_jtag_newtap
,
150 .help
= "declare a new SWD DAP",
152 COMMAND_REGISTRATION_DONE
155 static const struct command_registration dapdirect_swd_handlers
[] = {
159 .help
= "SWD command group",
161 .chain
= dapdirect_swd_subcommand_handlers
,
163 COMMAND_REGISTRATION_DONE
166 static int dapdirect_jtag_select(struct command_context
*ctx
)
168 LOG_DEBUG("dapdirect_jtag_select()");
170 return register_commands(ctx
, NULL
, dapdirect_jtag_handlers
);
173 static int dapdirect_swd_select(struct command_context
*ctx
)
175 LOG_DEBUG("dapdirect_swd_select()");
177 return register_commands(ctx
, NULL
, dapdirect_swd_handlers
);
180 static int dapdirect_init(struct command_context
*ctx
)
182 enum reset_types jtag_reset_config
= jtag_get_reset_config();
184 LOG_DEBUG("dapdirect_init()");
186 if (jtag_reset_config
& RESET_CNCT_UNDER_SRST
) {
187 if (jtag_reset_config
& RESET_SRST_NO_GATING
)
188 adapter_assert_reset();
190 LOG_WARNING("\'srst_nogate\' reset_config option is required");
192 adapter_deassert_reset();
197 static struct transport dapdirect_jtag_transport
= {
198 .name
= "dapdirect_jtag",
199 .select
= dapdirect_jtag_select
,
200 .init
= dapdirect_init
,
203 static struct transport dapdirect_swd_transport
= {
204 .name
= "dapdirect_swd",
205 .select
= dapdirect_swd_select
,
206 .init
= dapdirect_init
,
209 static void dapdirect_constructor(void) __attribute__((constructor
));
210 static void dapdirect_constructor(void)
212 transport_register(&dapdirect_jtag_transport
);
213 transport_register(&dapdirect_swd_transport
);
217 * Returns true if the current debug session
218 * is using JTAG as its transport.
220 bool transport_is_dapdirect_jtag(void)
222 return get_current_transport() == &dapdirect_jtag_transport
;
226 * Returns true if the current debug session
227 * is using SWD as its transport.
229 bool transport_is_dapdirect_swd(void)
231 return get_current_transport() == &dapdirect_swd_transport
;