01c5559fb560cc830730d398ad86d8ac9b65d9b0
[openocd.git] / src / jtag / arm-jtag-ew.c
1 /***************************************************************************
2 * Copyright (C) 2009 by Dimitar Dimitrov <dinuxbg@gmail.com> *
3 * based on Dominic Rath's and Benedikt Sauter's usbprog.c *
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
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "interface.h"
26 #include "commands.h"
27 #include <usb.h>
28 #include "usb_common.h"
29
30
31 #define USB_VID 0x15ba
32 #define USB_PID 0x001e
33
34 #define ARMJTAGEW_EPT_BULK_OUT 0x01u
35 #define ARMJTAGEW_EPT_BULK_IN 0x82u
36
37 #define ARMJTAGEW_USB_TIMEOUT 2000
38
39 #define ARMJTAGEW_IN_BUFFER_SIZE (4*1024)
40 #define ARMJTAGEW_OUT_BUFFER_SIZE (4*1024)
41
42
43 /* USB command request codes. */
44 #define CMD_GET_VERSION 0x00
45 #define CMD_SELECT_DPIMPL 0x10
46 #define CMD_SET_TCK_FREQUENCY 0x11
47 #define CMD_GET_TCK_FREQUENCY 0x12
48 #define CMD_MEASURE_MAX_TCK_FREQ 0x15
49 #define CMD_MEASURE_RTCK_RESPONSE 0x16
50 #define CMD_TAP_SHIFT 0x17
51 #define CMD_SET_TAPHW_STATE 0x20
52 #define CMD_GET_TAPHW_STATE 0x21
53 #define CMD_TGPWR_SETUP 0x22
54
55 /* Global USB buffers */
56 static uint8_t usb_in_buffer[ARMJTAGEW_IN_BUFFER_SIZE];
57 static uint8_t usb_out_buffer[ARMJTAGEW_OUT_BUFFER_SIZE];
58
59 /* Queue command functions */
60 static void armjtagew_end_state(tap_state_t state);
61 static void armjtagew_state_move(void);
62 static void armjtagew_path_move(int num_states, tap_state_t *path);
63 static void armjtagew_runtest(int num_cycles);
64 static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command);
65 static void armjtagew_reset(int trst, int srst);
66 //static void armjtagew_simple_command(uint8_t command);
67 static int armjtagew_get_status(void);
68
69 /* tap buffer functions */
70 static void armjtagew_tap_init(void);
71 static int armjtagew_tap_execute(void);
72 static void armjtagew_tap_ensure_space(int scans, int bits);
73 static void armjtagew_tap_append_step(int tms, int tdi);
74 static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command);
75
76 /* ARM-JTAG-EW lowlevel functions */
77 struct armjtagew {
78 struct usb_dev_handle* usb_handle;
79 };
80
81 static struct armjtagew *armjtagew_usb_open(void);
82 static void armjtagew_usb_close(struct armjtagew *armjtagew);
83 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length);
84 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length);
85 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length);
86
87 /* helper functions */
88 static int armjtagew_get_version_info(void);
89
90 #ifdef _DEBUG_USB_COMMS_
91 static void armjtagew_debug_buffer(uint8_t *buffer, int length);
92 #endif
93
94 static struct armjtagew* armjtagew_handle;
95
96
97
98 /***************************************************************************/
99 /* External interface implementation */
100
101 static int armjtagew_execute_queue(void)
102 {
103 struct jtag_command *cmd = jtag_command_queue;
104 int scan_size;
105 enum scan_type type;
106 uint8_t *buffer;
107
108 while (cmd != NULL)
109 {
110 switch (cmd->type)
111 {
112 case JTAG_RUNTEST:
113 DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \
114 cmd->cmd.runtest->end_state);
115
116 armjtagew_end_state(cmd->cmd.runtest->end_state);
117 armjtagew_runtest(cmd->cmd.runtest->num_cycles);
118 break;
119
120 case JTAG_STATEMOVE:
121 DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state);
122
123 armjtagew_end_state(cmd->cmd.statemove->end_state);
124 armjtagew_state_move();
125 break;
126
127 case JTAG_PATHMOVE:
128 DEBUG_JTAG_IO("pathmove: %i states, end in %i", \
129 cmd->cmd.pathmove->num_states, \
130 cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
131
132 armjtagew_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
133 break;
134
135 case JTAG_SCAN:
136 DEBUG_JTAG_IO("scan end in %i", cmd->cmd.scan->end_state);
137
138 armjtagew_end_state(cmd->cmd.scan->end_state);
139
140 scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
141 DEBUG_JTAG_IO("scan input, length = %d", scan_size);
142
143 #ifdef _DEBUG_USB_COMMS_
144 armjtagew_debug_buffer(buffer, (scan_size + 7) / 8);
145 #endif
146 type = jtag_scan_type(cmd->cmd.scan);
147 armjtagew_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size, cmd->cmd.scan);
148 break;
149
150 case JTAG_RESET:
151 DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
152
153 armjtagew_tap_execute();
154
155 if (cmd->cmd.reset->trst == 1)
156 {
157 tap_set_state(TAP_RESET);
158 }
159 armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
160 break;
161
162 case JTAG_SLEEP:
163 DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us);
164 armjtagew_tap_execute();
165 jtag_sleep(cmd->cmd.sleep->us);
166 break;
167
168 default:
169 LOG_ERROR("BUG: unknown JTAG command type encountered");
170 exit(-1);
171 }
172 cmd = cmd->next;
173 }
174
175 return armjtagew_tap_execute();
176 }
177
178
179 /* Sets speed in kHz. */
180 static int armjtagew_speed(int speed)
181 {
182 int result;
183 int speed_real;
184
185
186 usb_out_buffer[0] = CMD_SET_TCK_FREQUENCY;
187 buf_set_u32(usb_out_buffer + 1, 0, 32, speed);
188
189 result = armjtagew_usb_message(armjtagew_handle, 4, 4);
190
191 if (result < 0)
192 {
193 LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result);
194 return ERROR_JTAG_DEVICE_ERROR;
195 }
196
197 usb_out_buffer[0] = CMD_GET_TCK_FREQUENCY;
198 result = armjtagew_usb_message(armjtagew_handle, 1, 4);
199 speed_real = (int)buf_get_u32(usb_in_buffer,0,32);
200 if (result < 0)
201 {
202 LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result);
203 return ERROR_JTAG_DEVICE_ERROR;
204 }
205 else
206 {
207 LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
208 }
209
210 return ERROR_OK;
211 }
212
213
214 static int armjtagew_khz(int khz, int *jtag_speed)
215 {
216 *jtag_speed = khz;
217
218 return ERROR_OK;
219 }
220
221 static int armjtagew_init(void)
222 {
223 int check_cnt;
224
225 armjtagew_handle = armjtagew_usb_open();
226
227 if (armjtagew_handle == 0)
228 {
229 LOG_ERROR("Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
230 return ERROR_JTAG_INIT_FAILED;
231 }
232
233 check_cnt = 0;
234 while (check_cnt < 3)
235 {
236 if (armjtagew_get_version_info() == ERROR_OK)
237 {
238 /* attempt to get status */
239 armjtagew_get_status();
240 break;
241 }
242
243 check_cnt++;
244 }
245
246 if (check_cnt == 3)
247 {
248 LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
249 }
250
251 LOG_INFO("ARM-JTAG-EW JTAG Interface ready");
252
253 armjtagew_reset(0, 0);
254 armjtagew_tap_init();
255
256 return ERROR_OK;
257 }
258
259 static int armjtagew_quit(void)
260 {
261 armjtagew_usb_close(armjtagew_handle);
262 return ERROR_OK;
263 }
264
265 /***************************************************************************/
266 /* Queue command implementations */
267
268 static void armjtagew_end_state(tap_state_t state)
269 {
270 if (tap_is_state_stable(state))
271 {
272 tap_set_end_state(state);
273 }
274 else
275 {
276 LOG_ERROR("BUG: %i is not a valid end state", state);
277 exit(-1);
278 }
279 }
280
281 /* Goes to the end state. */
282 static void armjtagew_state_move(void)
283 {
284 int i;
285 int tms = 0;
286 uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
287 int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
288
289 for (i = 0; i < tms_count; i++)
290 {
291 tms = (tms_scan >> i) & 1;
292 armjtagew_tap_append_step(tms, 0);
293 }
294
295 tap_set_state(tap_get_end_state());
296 }
297
298 static void armjtagew_path_move(int num_states, tap_state_t *path)
299 {
300 int i;
301
302 for (i = 0; i < num_states; i++)
303 {
304 /*
305 * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
306 * Either handle that here, or update the documentation with examples
307 * how to fix that in the configuration files.
308 */
309 if (path[i] == tap_state_transition(tap_get_state(), false))
310 {
311 armjtagew_tap_append_step(0, 0);
312 }
313 else if (path[i] == tap_state_transition(tap_get_state(), true))
314 {
315 armjtagew_tap_append_step(1, 0);
316 }
317 else
318 {
319 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(path[i]));
320 exit(-1);
321 }
322
323 tap_set_state(path[i]);
324 }
325
326 tap_set_end_state(tap_get_state());
327 }
328
329 static void armjtagew_runtest(int num_cycles)
330 {
331 int i;
332
333 tap_state_t saved_end_state = tap_get_end_state();
334
335 /* only do a state_move when we're not already in IDLE */
336 if (tap_get_state() != TAP_IDLE)
337 {
338 armjtagew_end_state(TAP_IDLE);
339 armjtagew_state_move();
340 }
341
342 /* execute num_cycles */
343 for (i = 0; i < num_cycles; i++)
344 {
345 armjtagew_tap_append_step(0, 0);
346 }
347
348 /* finish in end_state */
349 armjtagew_end_state(saved_end_state);
350 if (tap_get_state() != tap_get_end_state())
351 {
352 armjtagew_state_move();
353 }
354 }
355
356 static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
357 {
358 tap_state_t saved_end_state;
359
360 armjtagew_tap_ensure_space(1, scan_size + 8);
361
362 saved_end_state = tap_get_end_state();
363
364 /* Move to appropriate scan state */
365 armjtagew_end_state(ir_scan ? TAP_IRSHIFT : TAP_DRSHIFT);
366
367 armjtagew_state_move();
368 armjtagew_end_state(saved_end_state);
369
370 /* Scan */
371 armjtagew_tap_append_scan(scan_size, buffer, command);
372
373 /* We are in Exit1, go to Pause */
374 armjtagew_tap_append_step(0, 0);
375
376 tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE);
377
378 if (tap_get_state() != tap_get_end_state())
379 {
380 armjtagew_state_move();
381 }
382 }
383
384 static void armjtagew_reset(int trst, int srst)
385 {
386 const uint8_t trst_mask = (1u << 5);
387 const uint8_t srst_mask = (1u << 6);
388 uint8_t val = 0;
389 uint8_t outp_en = 0;
390 uint8_t change_mask = 0;
391 int result;
392
393 LOG_DEBUG("trst: %i, srst: %i", trst, srst);
394
395 if (srst == 0)
396 {
397 val |= srst_mask;
398 outp_en &= ~srst_mask; /* tristate */
399 change_mask |= srst_mask;
400 }
401 else if (srst == 1)
402 {
403 val &= ~srst_mask;
404 outp_en |= srst_mask;
405 change_mask |= srst_mask;
406 }
407
408 if (trst == 0)
409 {
410 val |= trst_mask;
411 outp_en &= ~trst_mask; /* tristate */
412 change_mask |= trst_mask;
413 }
414 else if (trst == 1)
415 {
416 val &= ~trst_mask;
417 outp_en |= trst_mask;
418 change_mask |= trst_mask;
419 }
420
421 usb_out_buffer[0] = CMD_SET_TAPHW_STATE;
422 usb_out_buffer[1] = val;
423 usb_out_buffer[2] = outp_en;
424 usb_out_buffer[3] = change_mask;
425 result = armjtagew_usb_write(armjtagew_handle, 4);
426 if (result != 4)
427 {
428 LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
429 }
430 }
431
432
433 static int armjtagew_get_status(void)
434 {
435 int result;
436
437 usb_out_buffer[0] = CMD_GET_TAPHW_STATE;
438 result = armjtagew_usb_message(armjtagew_handle, 1, 12);
439
440 if (result == 0)
441 {
442 unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16);
443 LOG_INFO("U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s\n",
444 (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
445 (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
446 (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
447 (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
448 usb_in_buffer[9],
449 usb_in_buffer[11] ? "OVERCURRENT" : "OK",
450 usb_in_buffer[10] ? "enabled" : "disabled");
451
452 if (u_tg < 1500)
453 {
454 LOG_ERROR("Vref too low. Check Target Power\n");
455 }
456 }
457 else
458 {
459 LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)\n", result);
460 }
461
462 return ERROR_OK;
463 }
464
465 static int armjtagew_get_version_info(void)
466 {
467 int result;
468 char sn[16];
469 char auxinfo[257];
470
471 /* query hardware version */
472 usb_out_buffer[0] = CMD_GET_VERSION;
473 result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256);
474
475 if (result != 0)
476 {
477 LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)\n", result);
478 return ERROR_JTAG_DEVICE_ERROR;
479 }
480
481
482 memcpy(sn, usb_in_buffer + 4, 15);
483 sn[15] = '\0';
484 memcpy(auxinfo, usb_in_buffer + 4+15, 256);
485 auxinfo[256] = '\0';
486
487 LOG_INFO("ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \
488 usb_in_buffer[1], usb_in_buffer[0], \
489 isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X', \
490 sn, auxinfo);
491 return ERROR_OK;
492 }
493
494 COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
495 {
496 if (armjtagew_get_version_info() == ERROR_OK)
497 {
498 /* attempt to get status */
499 armjtagew_get_status();
500 }
501
502 return ERROR_OK;
503 }
504
505 static int armjtagew_register_commands(struct command_context *cmd_ctx)
506 {
507 register_command(cmd_ctx, NULL, "armjtagew_info",
508 &armjtagew_handle_armjtagew_info_command, COMMAND_EXEC,
509 "query armjtagew info");
510 return ERROR_OK;
511 }
512
513 struct jtag_interface armjtagew_interface = {
514 .name = "arm-jtag-ew",
515 .execute_queue = &armjtagew_execute_queue,
516 .speed = &armjtagew_speed,
517 .khz = &armjtagew_khz,
518 .register_commands = &armjtagew_register_commands,
519 .init = &armjtagew_init,
520 .quit = &armjtagew_quit,
521 };
522
523 /***************************************************************************/
524 /* ARM-JTAG-EW tap functions */
525
526 /* 2048 is the max value we can use here */
527 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
528
529 static int tap_length;
530 static uint8_t tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE];
531 static uint8_t tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE];
532 static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE];
533
534 struct pending_scan_result {
535 int first; /* First bit position in tdo_buffer to read */
536 int length; /* Number of bits to read */
537 struct scan_command *command; /* Corresponding scan command */
538 uint8_t *buffer;
539 };
540
541 #define MAX_PENDING_SCAN_RESULTS 256
542
543 static int pending_scan_results_length;
544 static struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS];
545
546 static int last_tms;
547
548 static void armjtagew_tap_init(void)
549 {
550 tap_length = 0;
551 pending_scan_results_length = 0;
552 }
553
554 static void armjtagew_tap_ensure_space(int scans, int bits)
555 {
556 int available_scans = MAX_PENDING_SCAN_RESULTS - pending_scan_results_length;
557 int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
558
559 if (scans > available_scans || bits > available_bits)
560 {
561 armjtagew_tap_execute();
562 }
563 }
564
565 static void armjtagew_tap_append_step(int tms, int tdi)
566 {
567 last_tms = tms;
568 int index = tap_length / 8;
569
570 if (index < ARMJTAGEW_TAP_BUFFER_SIZE)
571 {
572 int bit_index = tap_length % 8;
573 uint8_t bit = 1 << bit_index;
574
575 if (tms)
576 {
577 tms_buffer[index] |= bit;
578 }
579 else
580 {
581 tms_buffer[index] &= ~bit;
582 }
583
584 if (tdi)
585 {
586 tdi_buffer[index] |= bit;
587 }
588 else
589 {
590 tdi_buffer[index] &= ~bit;
591 }
592
593 tap_length++;
594 }
595 else
596 {
597 LOG_ERROR("armjtagew_tap_append_step, overflow");
598 }
599 }
600
601 void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
602 {
603 struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length];
604 int i;
605
606 pending_scan_result->first = tap_length;
607 pending_scan_result->length = length;
608 pending_scan_result->command = command;
609 pending_scan_result->buffer = buffer;
610
611 for (i = 0; i < length; i++)
612 {
613 armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
614 }
615 pending_scan_results_length++;
616 }
617
618 /* Pad and send a tap sequence to the device, and receive the answer.
619 * For the purpose of padding we assume that we are in idle or pause state. */
620 static int armjtagew_tap_execute(void)
621 {
622 int byte_length;
623 int tms_offset;
624 int tdi_offset;
625 int i;
626 int result;
627
628 if (tap_length > 0)
629 {
630 /* Pad last byte so that tap_length is divisible by 8 */
631 while (tap_length % 8 != 0)
632 {
633 /* More of the last TMS value keeps us in the same state,
634 * analogous to free-running JTAG interfaces. */
635 armjtagew_tap_append_step(last_tms, 0);
636 }
637
638 byte_length = tap_length / 8;
639
640 usb_out_buffer[0] = CMD_TAP_SHIFT;
641 buf_set_u32(usb_out_buffer + 1, 0, 16, byte_length);
642
643 tms_offset = 3;
644 for (i = 0; i < byte_length; i++)
645 {
646 usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i],8);
647 }
648
649 tdi_offset = tms_offset + byte_length;
650 for (i = 0; i < byte_length; i++)
651 {
652 usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i],8);
653 }
654
655 result = armjtagew_usb_message(armjtagew_handle, 3 + 2 * byte_length, byte_length + 4);
656
657 if (result == 0)
658 {
659 int stat;
660
661 stat = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
662 if (stat) {
663 LOG_ERROR("armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command", stat);
664 return ERROR_JTAG_QUEUE_FAILED;
665 }
666
667 for (i = 0; i < byte_length; i++)
668 {
669 tdo_buffer[i] = flip_u32(usb_in_buffer[i],8);
670 }
671
672 for (i = 0; i < pending_scan_results_length; i++)
673 {
674 struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[i];
675 uint8_t *buffer = pending_scan_result->buffer;
676 int length = pending_scan_result->length;
677 int first = pending_scan_result->first;
678 struct scan_command *command = pending_scan_result->command;
679
680 /* Copy to buffer */
681 buf_set_buf(tdo_buffer, first, buffer, 0, length);
682
683 DEBUG_JTAG_IO("pending scan result, length = %d", length);
684
685 #ifdef _DEBUG_USB_COMMS_
686 armjtagew_debug_buffer(buffer, byte_length);
687 #endif
688
689 if (jtag_read_buffer(buffer, command) != ERROR_OK)
690 {
691 armjtagew_tap_init();
692 return ERROR_JTAG_QUEUE_FAILED;
693 }
694
695 if (pending_scan_result->buffer != NULL)
696 {
697 free(pending_scan_result->buffer);
698 }
699 }
700 }
701 else
702 {
703 LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d", result, byte_length);
704 return ERROR_JTAG_QUEUE_FAILED;
705 }
706
707 armjtagew_tap_init();
708 }
709
710 return ERROR_OK;
711 }
712
713 /*****************************************************************************/
714 /* JLink USB low-level functions */
715
716 static struct armjtagew* armjtagew_usb_open()
717 {
718 usb_init();
719
720 const uint16_t vids[] = { USB_VID, 0 };
721 const uint16_t pids[] = { USB_PID, 0 };
722 struct usb_dev_handle *dev;
723 if (jtag_usb_open(vids, pids, &dev) != ERROR_OK)
724 return NULL;
725
726 struct armjtagew *result = malloc(sizeof(struct armjtagew));
727 result->usb_handle = dev;
728
729 #if 0
730 /* usb_set_configuration required under win32 */
731 usb_set_configuration(dev, dev->config[0].bConfigurationValue);
732 #endif
733 usb_claim_interface(dev, 0);
734 #if 0
735 /*
736 * This makes problems under Mac OS X. And is not needed
737 * under Windows. Hopefully this will not break a linux build
738 */
739 usb_set_altinterface(dev, 0);
740 #endif
741 return result;
742 }
743
744 static void armjtagew_usb_close(struct armjtagew *armjtagew)
745 {
746 usb_close(armjtagew->usb_handle);
747 free(armjtagew);
748 }
749
750 /* Send a message and receive the reply. */
751 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
752 {
753 int result;
754
755 result = armjtagew_usb_write(armjtagew, out_length);
756 if (result == out_length)
757 {
758 result = armjtagew_usb_read(armjtagew, in_length);
759 if (result != in_length)
760 {
761 LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", in_length, result);
762 return -1;
763 }
764 }
765 else
766 {
767 LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
768 return -1;
769 }
770 return 0;
771 }
772
773 /* Write data from out_buffer to USB. */
774 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
775 {
776 int result;
777
778 if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE)
779 {
780 LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)", out_length, ARMJTAGEW_OUT_BUFFER_SIZE);
781 return -1;
782 }
783
784 result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, \
785 (char*)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT);
786
787 DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
788
789 #ifdef _DEBUG_USB_COMMS_
790 armjtagew_debug_buffer(usb_out_buffer, out_length);
791 #endif
792 return result;
793 }
794
795 /* Read data from USB into in_buffer. */
796 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
797 {
798 int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, \
799 (char*)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT);
800
801 DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result);
802
803 #ifdef _DEBUG_USB_COMMS_
804 armjtagew_debug_buffer(usb_in_buffer, result);
805 #endif
806 return result;
807 }
808
809
810 #ifdef _DEBUG_USB_COMMS_
811 #define BYTES_PER_LINE 16
812
813 static void armjtagew_debug_buffer(uint8_t *buffer, int length)
814 {
815 char line[81];
816 char s[4];
817 int i;
818 int j;
819
820 for (i = 0; i < length; i += BYTES_PER_LINE)
821 {
822 snprintf(line, 5, "%04x", i);
823 for (j = i; j < i + BYTES_PER_LINE && j < length; j++)
824 {
825 snprintf(s, 4, " %02x", buffer[j]);
826 strcat(line, s);
827 }
828 LOG_DEBUG("%s", line);
829 }
830 }
831 #endif
832

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)