cmd: add missing usage var
[openocd.git] / src / jtag / stlink / stlink_interface.c
1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
4 * *
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. *
9 * *
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. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 /* project specific includes */
25 #include <jtag/interface.h>
26 #include <transport/transport.h>
27 #include <helper/time_support.h>
28
29 #include <jtag/stlink/stlink_tcl.h>
30 #include <jtag/stlink/stlink_layout.h>
31 #include <jtag/stlink/stlink_interface.h>
32
33 #include <target/target.h>
34
35 static struct stlink_interface_s stlink_if = { {0, 0, 0, 0}, 0, 0 };
36
37 int stlink_interface_open(void)
38 {
39 LOG_DEBUG("stlink_interface_open");
40
41 return stlink_if.layout->open(&stlink_if);
42 }
43
44 int stlink_interface_init_target(struct target *t)
45 {
46 int res;
47
48 /* this is the interface for the current target and we
49 * can setup the private pointer in the tap structure
50 * if the interface match the tap idcode
51 */
52 res = stlink_if.layout->api->idcode(stlink_if.fd, &t->tap->idcode);
53
54 if (res != ERROR_OK)
55 return res;
56
57 unsigned ii, limit = t->tap->expected_ids_cnt;
58 int found = 0;
59
60 for (ii = 0; ii < limit; ii++) {
61 uint32_t expected = t->tap->expected_ids[ii];
62
63 if (t->tap->idcode == expected) {
64 found = 1;
65 break;
66 }
67 }
68
69 if (found == 0) {
70 LOG_ERROR
71 ("stlink_interface_init_target: target not found: idcode: %x ",
72 t->tap->idcode);
73 return ERROR_FAIL;
74 }
75
76 t->tap->priv = &stlink_if;
77 t->tap->hasidcode = 1;
78
79 return ERROR_OK;
80 }
81
82 static int stlink_interface_init(void)
83 {
84 LOG_DEBUG("stlink_interface_init");
85
86 /* here we can initialize the layout */
87 return stlink_layout_init(&stlink_if);
88 }
89
90 static int stlink_interface_quit(void)
91 {
92 LOG_DEBUG("stlink_interface_quit");
93
94 return ERROR_OK;
95 }
96
97 static int stlink_interface_speed(int speed)
98 {
99 LOG_DEBUG("stlink_interface_speed: ignore speed %d", speed);
100
101 return ERROR_OK;
102 }
103
104 static int stlink_speed_div(int speed, int *khz)
105 {
106 *khz = speed;
107 return ERROR_OK;
108 }
109
110 static int stlink_khz(int khz, int *jtag_speed)
111 {
112 *jtag_speed = khz;
113 return ERROR_OK;
114 }
115
116 static int stlink_interface_execute_queue(void)
117 {
118 LOG_DEBUG("stlink_interface_execute_queue: ignored");
119
120 return ERROR_OK;
121 }
122
123 COMMAND_HANDLER(stlink_interface_handle_device_desc_command)
124 {
125 LOG_DEBUG("stlink_interface_handle_device_desc_command");
126
127 if (CMD_ARGC == 1) {
128 stlink_if.param.device_desc = strdup(CMD_ARGV[0]);
129 } else {
130 LOG_ERROR
131 ("expected exactly one argument to stlink_device_desc <description>");
132 }
133
134 return ERROR_OK;
135 }
136
137 COMMAND_HANDLER(stlink_interface_handle_serial_command)
138 {
139 LOG_DEBUG("stlink_interface_handle_serial_command");
140
141 if (CMD_ARGC == 1) {
142 stlink_if.param.serial = strdup(CMD_ARGV[0]);
143 } else {
144 LOG_ERROR
145 ("expected exactly one argument to stlink_serial <serial-number>");
146 }
147
148 return ERROR_OK;
149 }
150
151 COMMAND_HANDLER(stlink_interface_handle_layout_command)
152 {
153 LOG_DEBUG("stlink_interface_handle_layout_command");
154
155 if (CMD_ARGC != 1) {
156 LOG_ERROR("Need exactly one argument to stlink_layout");
157 return ERROR_COMMAND_SYNTAX_ERROR;
158 }
159
160 if (stlink_if.layout) {
161 LOG_ERROR("already specified stlink_layout %s",
162 stlink_if.layout->name);
163 return (strcmp(stlink_if.layout->name, CMD_ARGV[0]) != 0)
164 ? ERROR_FAIL : ERROR_OK;
165 }
166
167 for (const struct stlink_layout *l = stlink_layout_get_list(); l->name;
168 l++) {
169 if (strcmp(l->name, CMD_ARGV[0]) == 0) {
170 stlink_if.layout = l;
171 return ERROR_OK;
172 }
173 }
174
175 LOG_ERROR("No STLINK layout '%s' found", CMD_ARGV[0]);
176 return ERROR_FAIL;
177 }
178
179 COMMAND_HANDLER(stlink_interface_handle_vid_pid_command)
180 {
181 LOG_DEBUG("stlink_interface_handle_vid_pid_command");
182
183 if (CMD_ARGC != 2) {
184 LOG_WARNING
185 ("ignoring extra IDs in stlink_vid_pid (maximum is 1 pair)");
186 return ERROR_COMMAND_SYNTAX_ERROR;
187 }
188
189 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], stlink_if.param.vid);
190 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], stlink_if.param.pid);
191
192 return ERROR_OK;
193 }
194
195 static const struct command_registration stlink_interface_command_handlers[] = {
196 {
197 .name = "stlink_device_desc",
198 .handler = &stlink_interface_handle_device_desc_command,
199 .mode = COMMAND_CONFIG,
200 .help = "set the stlink device description of the STLINK device",
201 .usage = "description_string",
202 },
203 {
204 .name = "stlink_serial",
205 .handler = &stlink_interface_handle_serial_command,
206 .mode = COMMAND_CONFIG,
207 .help = "set the serial number of the STLINK device",
208 .usage = "serial_string",
209 },
210 {
211 .name = "stlink_layout",
212 .handler = &stlink_interface_handle_layout_command,
213 .mode = COMMAND_CONFIG,
214 .help = "set the layout of the STLINK to usb or sg",
215 .usage = "layout_name",
216 },
217 {
218 .name = "stlink_vid_pid",
219 .handler = &stlink_interface_handle_vid_pid_command,
220 .mode = COMMAND_CONFIG,
221 .help = "the vendor and product ID of the STLINK device",
222 .usage = "(vid pid)* ",
223 },
224 COMMAND_REGISTRATION_DONE
225 };
226
227 struct jtag_interface stlink_interface = {
228 .name = "stlink",
229 .supported = 0,
230 .commands = stlink_interface_command_handlers,
231 .transports = stlink_transports,
232 .init = stlink_interface_init,
233 .quit = stlink_interface_quit,
234 .speed = stlink_interface_speed,
235 .speed_div = stlink_speed_div,
236 .khz = stlink_khz,
237 .execute_queue = stlink_interface_execute_queue,
238 };

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)