stlink: print version info
[openocd.git] / src / jtag / hla / hla_interface.c
1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
4 * *
5 * Copyright (C) 2012 by Spencer Oliver *
6 * spen@spen-soft.co.uk *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 /* project specific includes */
29 #include <jtag/interface.h>
30 #include <transport/transport.h>
31 #include <helper/time_support.h>
32
33 #include <jtag/hla/hla_tcl.h>
34 #include <jtag/hla/hla_layout.h>
35 #include <jtag/hla/hla_transport.h>
36 #include <jtag/hla/hla_interface.h>
37
38 #include <target/target.h>
39
40 static struct hl_interface_s hl_if = { {0, 0, 0, 0, 0, 0}, 0, 0 };
41
42 int hl_interface_open(enum hl_transports tr)
43 {
44 LOG_DEBUG("hl_interface_open");
45
46 /* set transport mode */
47 hl_if.param.transport = tr;
48
49 int result = hl_if.layout->open(&hl_if);
50 if (result != ERROR_OK)
51 return result;
52
53 return hl_interface_init_reset();
54 }
55
56 int hl_interface_init_target(struct target *t)
57 {
58 int res;
59
60 LOG_DEBUG("hl_interface_init_target");
61
62 /* this is the interface for the current target and we
63 * can setup the private pointer in the tap structure
64 * if the interface match the tap idcode
65 */
66 res = hl_if.layout->api->idcode(hl_if.fd, &t->tap->idcode);
67
68 if (res != ERROR_OK)
69 return res;
70
71 unsigned ii, limit = t->tap->expected_ids_cnt;
72 int found = 0;
73
74 for (ii = 0; ii < limit; ii++) {
75 uint32_t expected = t->tap->expected_ids[ii];
76
77 /* treat "-expected-id 0" as a "don't-warn" wildcard */
78 if (!expected || (t->tap->idcode == expected)) {
79 found = 1;
80 break;
81 }
82 }
83
84 if (found == 0) {
85 LOG_ERROR("hl_interface_init_target: target not found: idcode: 0x%08x",
86 t->tap->idcode);
87 return ERROR_FAIL;
88 }
89
90 t->tap->priv = &hl_if;
91 t->tap->hasidcode = 1;
92
93 return ERROR_OK;
94 }
95
96 static int hl_interface_init(void)
97 {
98 LOG_DEBUG("hl_interface_init");
99
100 /* here we can initialize the layout */
101 return hl_layout_init(&hl_if);
102 }
103
104 static int hl_interface_quit(void)
105 {
106 LOG_DEBUG("hl_interface_quit");
107
108 return ERROR_OK;
109 }
110
111 static int hl_interface_speed(int speed)
112 {
113 LOG_DEBUG("hl_interface_speed: ignore speed %d", speed);
114
115 return ERROR_OK;
116 }
117
118 static int hl_speed_div(int speed, int *khz)
119 {
120 *khz = speed;
121 return ERROR_OK;
122 }
123
124 static int hl_khz(int khz, int *jtag_speed)
125 {
126 *jtag_speed = khz;
127 return ERROR_OK;
128 }
129
130 static int hl_interface_execute_queue(void)
131 {
132 LOG_DEBUG("hl_interface_execute_queue: ignored");
133
134 return ERROR_OK;
135 }
136
137 int hl_interface_init_reset(void)
138 {
139 enum reset_types jtag_reset_config = jtag_get_reset_config();
140
141 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
142 if (jtag_reset_config & RESET_SRST_NO_GATING) {
143 jtag_add_reset(0, 1);
144 hl_if.layout->api->assert_srst(hl_if.fd, 0);
145 } else
146 LOG_WARNING("\'srst_nogate\' reset_config option is required");
147 }
148
149 return ERROR_OK;
150 }
151
152 COMMAND_HANDLER(hl_interface_handle_device_desc_command)
153 {
154 LOG_DEBUG("hl_interface_handle_device_desc_command");
155
156 if (CMD_ARGC == 1) {
157 hl_if.param.device_desc = strdup(CMD_ARGV[0]);
158 } else {
159 LOG_ERROR("expected exactly one argument to hl_device_desc <description>");
160 }
161
162 return ERROR_OK;
163 }
164
165 COMMAND_HANDLER(hl_interface_handle_serial_command)
166 {
167 LOG_DEBUG("hl_interface_handle_serial_command");
168
169 if (CMD_ARGC == 1) {
170 hl_if.param.serial = strdup(CMD_ARGV[0]);
171 } else {
172 LOG_ERROR("expected exactly one argument to hl_serial <serial-number>");
173 }
174
175 return ERROR_OK;
176 }
177
178 COMMAND_HANDLER(hl_interface_handle_layout_command)
179 {
180 LOG_DEBUG("hl_interface_handle_layout_command");
181
182 if (CMD_ARGC != 1) {
183 LOG_ERROR("Need exactly one argument to stlink_layout");
184 return ERROR_COMMAND_SYNTAX_ERROR;
185 }
186
187 if (hl_if.layout) {
188 LOG_ERROR("already specified hl_layout %s",
189 hl_if.layout->name);
190 return (strcmp(hl_if.layout->name, CMD_ARGV[0]) != 0)
191 ? ERROR_FAIL : ERROR_OK;
192 }
193
194 for (const struct hl_layout *l = hl_layout_get_list(); l->name;
195 l++) {
196 if (strcmp(l->name, CMD_ARGV[0]) == 0) {
197 hl_if.layout = l;
198 return ERROR_OK;
199 }
200 }
201
202 LOG_ERROR("No adapter layout '%s' found", CMD_ARGV[0]);
203 return ERROR_FAIL;
204 }
205
206 COMMAND_HANDLER(hl_interface_handle_vid_pid_command)
207 {
208 LOG_DEBUG("hl_interface_handle_vid_pid_command");
209
210 if (CMD_ARGC != 2) {
211 LOG_WARNING("ignoring extra IDs in hl_vid_pid (maximum is 1 pair)");
212 return ERROR_COMMAND_SYNTAX_ERROR;
213 }
214
215 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], hl_if.param.vid);
216 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], hl_if.param.pid);
217
218 return ERROR_OK;
219 }
220
221 COMMAND_HANDLER(hl_interface_handle_api_command)
222 {
223 if (CMD_ARGC != 1)
224 return ERROR_COMMAND_SYNTAX_ERROR;
225
226 unsigned new_api;
227 COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], new_api);
228 if ((new_api == 0) || (new_api > 2))
229 return ERROR_COMMAND_SYNTAX_ERROR;
230
231 hl_if.param.api = new_api;
232
233 return ERROR_OK;
234 }
235
236 static const struct command_registration hl_interface_command_handlers[] = {
237 {
238 .name = "stlink_device_desc",
239 .handler = &hl_interface_handle_device_desc_command,
240 .mode = COMMAND_CONFIG,
241 .help = "set the a device description of the adapter",
242 .usage = "description_string",
243 },
244 {
245 .name = "stlink_serial",
246 .handler = &hl_interface_handle_serial_command,
247 .mode = COMMAND_CONFIG,
248 .help = "set the serial number of the adapter",
249 .usage = "serial_string",
250 },
251 {
252 .name = "stlink_layout",
253 .handler = &hl_interface_handle_layout_command,
254 .mode = COMMAND_CONFIG,
255 .help = "set the layout of the adapter",
256 .usage = "layout_name",
257 },
258 {
259 .name = "stlink_vid_pid",
260 .handler = &hl_interface_handle_vid_pid_command,
261 .mode = COMMAND_CONFIG,
262 .help = "the vendor and product ID of the adapter",
263 .usage = "(vid pid)* ",
264 },
265 {
266 .name = "stlink_api",
267 .handler = &hl_interface_handle_api_command,
268 .mode = COMMAND_CONFIG,
269 .help = "set the desired stlink api level",
270 .usage = "api version 1 or 2",
271 },
272 COMMAND_REGISTRATION_DONE
273 };
274
275 struct jtag_interface hl_interface = {
276 .name = "stlink",
277 .supported = 0,
278 .commands = hl_interface_command_handlers,
279 .transports = hl_transports,
280 .init = hl_interface_init,
281 .quit = hl_interface_quit,
282 .speed = hl_interface_speed,
283 .speed_div = hl_speed_div,
284 .khz = hl_khz,
285 .execute_queue = hl_interface_execute_queue,
286 };

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)