1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2011 by Mathias Kuester *
5 * Mathias Kuester <kesmtp@freenet.de> *
7 * Copyright (C) 2012 by Spencer Oliver *
8 * spen@spen-soft.co.uk *
9 ***************************************************************************/
15 /* project specific includes */
16 #include <jtag/interface.h>
17 #include <transport/transport.h>
18 #include <helper/time_support.h>
20 #include <jtag/hla/hla_layout.h>
21 #include <jtag/hla/hla_transport.h>
22 #include <jtag/hla/hla_interface.h>
24 #include <target/target.h>
26 static struct hl_interface_s hl_if
= {
31 .transport
= HL_TRANSPORT_UNKNOWN
,
32 .connect_under_reset
= false,
33 .initial_interface_speed
= -1,
34 .use_stlink_tcp
= false,
35 .stlink_tcp_port
= 7184,
41 int hl_interface_open(enum hl_transports tr
)
43 LOG_DEBUG("hl_interface_open");
45 enum reset_types jtag_reset_config
= jtag_get_reset_config();
47 if (jtag_reset_config
& RESET_CNCT_UNDER_SRST
) {
48 if (jtag_reset_config
& RESET_SRST_NO_GATING
)
49 hl_if
.param
.connect_under_reset
= true;
51 LOG_WARNING("\'srst_nogate\' reset_config option is required");
54 /* set transport mode */
55 hl_if
.param
.transport
= tr
;
57 int result
= hl_if
.layout
->open(&hl_if
);
58 if (result
!= ERROR_OK
)
61 return hl_interface_init_reset();
64 int hl_interface_init_target(struct target
*t
)
68 LOG_DEBUG("hl_interface_init_target");
70 /* this is the interface for the current target and we
71 * can setup the private pointer in the tap structure
72 * if the interface match the tap idcode
74 res
= hl_if
.layout
->api
->idcode(hl_if
.handle
, &t
->tap
->idcode
);
79 unsigned ii
, limit
= t
->tap
->expected_ids_cnt
;
82 for (ii
= 0; ii
< limit
; ii
++) {
83 uint32_t expected
= t
->tap
->expected_ids
[ii
];
85 /* treat "-expected-id 0" as a "don't-warn" wildcard */
86 if (!expected
|| !t
->tap
->idcode
||
87 (t
->tap
->idcode
== expected
)) {
94 LOG_WARNING("UNEXPECTED idcode: 0x%08" PRIx32
, t
->tap
->idcode
);
95 for (ii
= 0; ii
< limit
; ii
++)
96 LOG_ERROR("expected %u of %u: 0x%08" PRIx32
, ii
+ 1, limit
,
97 t
->tap
->expected_ids
[ii
]);
102 t
->tap
->priv
= &hl_if
;
103 t
->tap
->has_idcode
= true;
108 static int hl_interface_init(void)
110 LOG_DEBUG("hl_interface_init");
112 /* here we can initialize the layout */
113 return hl_layout_init(&hl_if
);
116 static int hl_interface_quit(void)
118 LOG_DEBUG("hl_interface_quit");
120 if (hl_if
.layout
->api
->close
)
121 hl_if
.layout
->api
->close(hl_if
.handle
);
123 jtag_command_queue_reset();
125 free((void *)hl_if
.param
.device_desc
);
130 static int hl_interface_reset(int req_trst
, int req_srst
)
132 return hl_if
.layout
->api
->assert_srst(hl_if
.handle
, req_srst
? 0 : 1);
135 int hl_interface_init_reset(void)
137 /* in case the adapter has not already handled asserting srst
138 * we will attempt it again */
139 if (hl_if
.param
.connect_under_reset
) {
140 adapter_assert_reset();
142 adapter_deassert_reset();
148 static int hl_interface_khz(int khz
, int *jtag_speed
)
150 if (!hl_if
.layout
->api
->speed
)
153 *jtag_speed
= hl_if
.layout
->api
->speed(hl_if
.handle
, khz
, true);
157 static int hl_interface_speed_div(int speed
, int *khz
)
163 static int hl_interface_speed(int speed
)
165 if (!hl_if
.layout
->api
->speed
)
169 /* pass speed as initial param as interface not open yet */
170 hl_if
.param
.initial_interface_speed
= speed
;
174 hl_if
.layout
->api
->speed(hl_if
.handle
, speed
, false);
179 int hl_interface_override_target(const char **targetname
)
181 if (hl_if
.layout
->api
->override_target
) {
182 if (hl_if
.layout
->api
->override_target(*targetname
)) {
183 *targetname
= "hla_target";
191 static int hl_interface_config_trace(bool enabled
, enum tpiu_pin_protocol pin_protocol
,
192 uint32_t port_size
, unsigned int *trace_freq
,
193 unsigned int traceclkin_freq
, uint16_t *prescaler
)
195 if (hl_if
.layout
->api
->config_trace
)
196 return hl_if
.layout
->api
->config_trace(hl_if
.handle
, enabled
,
197 pin_protocol
, port_size
, trace_freq
, traceclkin_freq
, prescaler
);
199 LOG_ERROR("The selected interface does not support tracing");
206 static int hl_interface_poll_trace(uint8_t *buf
, size_t *size
)
208 if (hl_if
.layout
->api
->poll_trace
)
209 return hl_if
.layout
->api
->poll_trace(hl_if
.handle
, buf
, size
);
214 COMMAND_HANDLER(hl_interface_handle_device_desc_command
)
216 LOG_DEBUG("hl_interface_handle_device_desc_command");
219 hl_if
.param
.device_desc
= strdup(CMD_ARGV
[0]);
221 LOG_ERROR("expected exactly one argument to hl_device_desc <description>");
227 COMMAND_HANDLER(hl_interface_handle_layout_command
)
229 LOG_DEBUG("hl_interface_handle_layout_command");
232 LOG_ERROR("Need exactly one argument to stlink_layout");
233 return ERROR_COMMAND_SYNTAX_ERROR
;
237 LOG_ERROR("already specified hl_layout %s",
239 return (strcmp(hl_if
.layout
->name
, CMD_ARGV
[0]) != 0)
240 ? ERROR_FAIL
: ERROR_OK
;
243 for (const struct hl_layout
*l
= hl_layout_get_list(); l
->name
;
245 if (strcmp(l
->name
, CMD_ARGV
[0]) == 0) {
251 LOG_ERROR("No adapter layout '%s' found", CMD_ARGV
[0]);
255 COMMAND_HANDLER(hl_interface_handle_vid_pid_command
)
257 if (CMD_ARGC
> HLA_MAX_USB_IDS
* 2) {
258 LOG_WARNING("ignoring extra IDs in hla_vid_pid "
259 "(maximum is %d pairs)", HLA_MAX_USB_IDS
);
260 CMD_ARGC
= HLA_MAX_USB_IDS
* 2;
262 if (CMD_ARGC
< 2 || (CMD_ARGC
& 1)) {
263 LOG_WARNING("incomplete hla_vid_pid configuration directive");
264 return ERROR_COMMAND_SYNTAX_ERROR
;
268 for (i
= 0; i
< CMD_ARGC
; i
+= 2) {
269 COMMAND_PARSE_NUMBER(u16
, CMD_ARGV
[i
], hl_if
.param
.vid
[i
/ 2]);
270 COMMAND_PARSE_NUMBER(u16
, CMD_ARGV
[i
+ 1], hl_if
.param
.pid
[i
/ 2]);
274 * Explicitly terminate, in case there are multiple instances of
277 hl_if
.param
.vid
[i
/ 2] = hl_if
.param
.pid
[i
/ 2] = 0;
282 COMMAND_HANDLER(hl_interface_handle_stlink_backend_command
)
285 bool use_stlink_tcp
= false;
286 uint16_t stlink_tcp_port
= 7184;
288 if (CMD_ARGC
== 0 || CMD_ARGC
> 2)
289 return ERROR_COMMAND_SYNTAX_ERROR
;
290 else if (strcmp(CMD_ARGV
[0], "usb") == 0) {
292 return ERROR_COMMAND_SYNTAX_ERROR
;
293 /* else use_stlink_tcp = false (already the case ) */
294 } else if (strcmp(CMD_ARGV
[0], "tcp") == 0) {
295 use_stlink_tcp
= true;
297 COMMAND_PARSE_NUMBER(u16
, CMD_ARGV
[1], stlink_tcp_port
);
299 return ERROR_COMMAND_SYNTAX_ERROR
;
301 hl_if
.param
.use_stlink_tcp
= use_stlink_tcp
;
302 hl_if
.param
.stlink_tcp_port
= stlink_tcp_port
;
307 COMMAND_HANDLER(interface_handle_hla_command
)
310 return ERROR_COMMAND_SYNTAX_ERROR
;
312 if (!hl_if
.layout
->api
->custom_command
) {
313 LOG_ERROR("The selected adapter doesn't support custom commands");
317 hl_if
.layout
->api
->custom_command(hl_if
.handle
, CMD_ARGV
[0]);
322 static const struct command_registration hl_interface_command_handlers
[] = {
324 .name
= "hla_device_desc",
325 .handler
= &hl_interface_handle_device_desc_command
,
326 .mode
= COMMAND_CONFIG
,
327 .help
= "set the device description of the adapter",
328 .usage
= "description_string",
331 .name
= "hla_layout",
332 .handler
= &hl_interface_handle_layout_command
,
333 .mode
= COMMAND_CONFIG
,
334 .help
= "set the layout of the adapter",
335 .usage
= "layout_name",
338 .name
= "hla_vid_pid",
339 .handler
= &hl_interface_handle_vid_pid_command
,
340 .mode
= COMMAND_CONFIG
,
341 .help
= "the vendor and product ID of the adapter",
342 .usage
= "(vid pid)*",
345 .name
= "hla_stlink_backend",
346 .handler
= &hl_interface_handle_stlink_backend_command
,
347 .mode
= COMMAND_CONFIG
,
348 .help
= "select which ST-Link backend to use",
349 .usage
= "usb | tcp [port]",
352 .name
= "hla_command",
353 .handler
= &interface_handle_hla_command
,
354 .mode
= COMMAND_EXEC
,
355 .help
= "execute a custom adapter-specific command",
356 .usage
= "<command>",
358 COMMAND_REGISTRATION_DONE
361 struct adapter_driver hl_adapter_driver
= {
363 .transports
= hl_transports
,
364 .commands
= hl_interface_command_handlers
,
366 .init
= hl_interface_init
,
367 .quit
= hl_interface_quit
,
368 .reset
= hl_interface_reset
,
369 .speed
= &hl_interface_speed
,
370 .khz
= &hl_interface_khz
,
371 .speed_div
= &hl_interface_speed_div
,
372 .config_trace
= &hl_interface_config_trace
,
373 .poll_trace
= &hl_interface_poll_trace
,
375 /* no ops for HLA, targets hla_target and stm8 intercept them all */
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)