89158368043559385211bbc965e2b6c612f5be71
[openocd.git] / src / jtag / drivers / cmsis_dap_usb.c
1 /***************************************************************************
2 * Copyright (C) 2016 by Maksym Hilliaka *
3 * oter@frozen-team.com *
4 * *
5 * Copyright (C) 2016 by Phillip Pearson *
6 * pp@myelin.co.nz *
7 * *
8 * Copyright (C) 2014 by Paul Fertser *
9 * fercerpav@gmail.com *
10 * *
11 * Copyright (C) 2013 by mike brown *
12 * mike@theshedworks.org.uk *
13 * *
14 * Copyright (C) 2013 by Spencer Oliver *
15 * spen@spen-soft.co.uk *
16 * *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
21 * *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
26 * *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
29 ***************************************************************************/
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <transport/transport.h>
36 #include <jtag/swd.h>
37 #include <jtag/interface.h>
38 #include <jtag/commands.h>
39 #include <jtag/tcl.h>
40
41 #include <hidapi.h>
42
43 /*
44 * See CMSIS-DAP documentation:
45 * Version 0.01 - Beta.
46 */
47
48 /* USB Config */
49
50 /* Known vid/pid pairs:
51 * VID 0xc251: Keil Software
52 * PID 0xf001: LPC-Link-II CMSIS_DAP
53 * PID 0xf002: OPEN-SDA CMSIS_DAP (Freedom Board)
54 * PID 0x2722: Keil ULINK2 CMSIS-DAP
55 *
56 * VID 0x0d28: mbed Software
57 * PID 0x0204: MBED CMSIS-DAP
58 */
59
60 #define MAX_USB_IDS 8
61 /* vid = pid = 0 marks the end of the list */
62 static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 };
63 static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 };
64 static wchar_t *cmsis_dap_serial;
65 static bool swd_mode;
66
67 #define PACKET_SIZE (64 + 1) /* 64 bytes plus report id */
68 #define USB_TIMEOUT 1000
69
70 /* CMSIS-DAP General Commands */
71 #define CMD_DAP_INFO 0x00
72 #define CMD_DAP_LED 0x01
73 #define CMD_DAP_CONNECT 0x02
74 #define CMD_DAP_DISCONNECT 0x03
75 #define CMD_DAP_WRITE_ABORT 0x08
76 #define CMD_DAP_DELAY 0x09
77 #define CMD_DAP_RESET_TARGET 0x0A
78
79 /* CMD_INFO */
80 #define INFO_ID_VENDOR 0x01 /* string */
81 #define INFO_ID_PRODUCT 0x02 /* string */
82 #define INFO_ID_SERNUM 0x03 /* string */
83 #define INFO_ID_FW_VER 0x04 /* string */
84 #define INFO_ID_TD_VEND 0x05 /* string */
85 #define INFO_ID_TD_NAME 0x06 /* string */
86 #define INFO_ID_CAPS 0xf0 /* byte */
87 #define INFO_ID_PKT_CNT 0xfe /* byte */
88 #define INFO_ID_PKT_SZ 0xff /* short */
89
90 #define INFO_CAPS_SWD 0x01
91 #define INFO_CAPS_JTAG 0x02
92
93 /* CMD_LED */
94 #define LED_ID_CONNECT 0x00
95 #define LED_ID_RUN 0x01
96
97 #define LED_OFF 0x00
98 #define LED_ON 0x01
99
100 /* CMD_CONNECT */
101 #define CONNECT_DEFAULT 0x00
102 #define CONNECT_SWD 0x01
103 #define CONNECT_JTAG 0x02
104
105 /* CMSIS-DAP Common SWD/JTAG Commands */
106 #define CMD_DAP_DELAY 0x09
107 #define CMD_DAP_SWJ_PINS 0x10
108 #define CMD_DAP_SWJ_CLOCK 0x11
109 #define CMD_DAP_SWJ_SEQ 0x12
110
111 /*
112 * PINS
113 * Bit 0: SWCLK/TCK
114 * Bit 1: SWDIO/TMS
115 * Bit 2: TDI
116 * Bit 3: TDO
117 * Bit 5: nTRST
118 * Bit 7: nRESET
119 */
120
121 #define SWJ_PIN_TCK (1<<0)
122 #define SWJ_PIN_TMS (1<<1)
123 #define SWJ_PIN_TDI (1<<2)
124 #define SWJ_PIN_TDO (1<<3)
125 #define SWJ_PIN_TRST (1<<5)
126 #define SWJ_PIN_SRST (1<<7)
127
128 /* CMSIS-DAP SWD Commands */
129 #define CMD_DAP_SWD_CONFIGURE 0x13
130
131 /* CMSIS-DAP JTAG Commands */
132 #define CMD_DAP_JTAG_SEQ 0x14
133 #define CMD_DAP_JTAG_CONFIGURE 0x15
134 #define CMD_DAP_JTAG_IDCODE 0x16
135
136 /* CMSIS-DAP JTAG sequence info masks */
137 /* Number of bits to clock through (0 means 64) */
138 #define DAP_JTAG_SEQ_TCK 0x3F
139 /* TMS will be set during the sequence if this bit is set */
140 #define DAP_JTAG_SEQ_TMS 0x40
141 /* TDO output will be captured if this bit is set */
142 #define DAP_JTAG_SEQ_TDO 0x80
143
144
145 /* CMSIS-DAP Transfer Commands */
146 #define CMD_DAP_TFER_CONFIGURE 0x04
147 #define CMD_DAP_TFER 0x05
148 #define CMD_DAP_TFER_BLOCK 0x06
149 #define CMD_DAP_TFER_ABORT 0x07
150
151 /* DAP Status Code */
152 #define DAP_OK 0
153 #define DAP_ERROR 0xFF
154
155 /* CMSIS-DAP Vendor Commands
156 * None as yet... */
157
158 static const char * const info_caps_str[] = {
159 "SWD Supported",
160 "JTAG Supported"
161 };
162
163 /* max clock speed (kHz) */
164 #define DAP_MAX_CLOCK 5000
165
166 struct cmsis_dap {
167 hid_device *dev_handle;
168 uint16_t packet_size;
169 int packet_count;
170 uint8_t *packet_buffer;
171 uint8_t caps;
172 uint8_t mode;
173 };
174
175 struct pending_transfer_result {
176 uint8_t cmd;
177 uint32_t data;
178 void *buffer;
179 };
180
181 struct pending_request_block {
182 struct pending_transfer_result *transfers;
183 int transfer_count;
184 };
185
186 struct pending_scan_result {
187 /** Offset in bytes in the CMD_DAP_JTAG_SEQ response buffer. */
188 unsigned first;
189 /** Number of bits to read. */
190 unsigned length;
191 /** Location to store the result */
192 uint8_t *buffer;
193 /** Offset in the destination buffer */
194 unsigned buffer_offset;
195 };
196
197 /* Up to MIN(packet_count, MAX_PENDING_REQUESTS) requests may be issued
198 * until the first response arrives */
199 #define MAX_PENDING_REQUESTS 3
200
201 /* Pending requests are organized as a FIFO - circular buffer */
202 /* Each block in FIFO can contain up to pending_queue_len transfers */
203 static int pending_queue_len;
204 static struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS];
205 static int pending_fifo_put_idx, pending_fifo_get_idx;
206 static int pending_fifo_block_count;
207
208 /* pointers to buffers that will receive jtag scan results on the next flush */
209 #define MAX_PENDING_SCAN_RESULTS 256
210 static int pending_scan_result_count;
211 static struct pending_scan_result pending_scan_results[MAX_PENDING_SCAN_RESULTS];
212
213 /* queued JTAG sequences that will be executed on the next flush */
214 #define QUEUED_SEQ_BUF_LEN (cmsis_dap_handle->packet_size - 3)
215 static int queued_seq_count;
216 static int queued_seq_buf_end;
217 static int queued_seq_tdo_ptr;
218 static uint8_t queued_seq_buf[1024]; /* TODO: make dynamic / move into cmsis object */
219
220 static int queued_retval;
221
222 static uint8_t output_pins = SWJ_PIN_SRST | SWJ_PIN_TRST;
223
224 static struct cmsis_dap *cmsis_dap_handle;
225
226 static int cmsis_dap_usb_open(void)
227 {
228 hid_device *dev = NULL;
229 int i;
230 struct hid_device_info *devs, *cur_dev;
231 unsigned short target_vid, target_pid;
232 bool found = false;
233
234 target_vid = 0;
235 target_pid = 0;
236
237 if (hid_init() != 0) {
238 LOG_ERROR("unable to open HIDAPI");
239 return ERROR_FAIL;
240 }
241
242 /*
243 * The CMSIS-DAP specification stipulates:
244 * "The Product String must contain "CMSIS-DAP" somewhere in the string. This is used by the
245 * debuggers to identify a CMSIS-DAP compliant Debug Unit that is connected to a host computer."
246 */
247 devs = hid_enumerate(0x0, 0x0);
248 cur_dev = devs;
249 while (NULL != cur_dev) {
250 if (0 == cmsis_dap_vid[0]) {
251 if (NULL == cur_dev->product_string) {
252 LOG_DEBUG("Cannot read product string of device 0x%x:0x%x",
253 cur_dev->vendor_id, cur_dev->product_id);
254 } else {
255 if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) {
256 /* if the user hasn't specified VID:PID *and*
257 * product string contains "CMSIS-DAP", pick it
258 */
259 found = true;
260 }
261 }
262 } else {
263 /* otherwise, exhaustively compare against all VID:PID in list */
264 for (i = 0; cmsis_dap_vid[i] || cmsis_dap_pid[i]; i++) {
265 if ((cmsis_dap_vid[i] == cur_dev->vendor_id) && (cmsis_dap_pid[i] == cur_dev->product_id))
266 found = true;
267 }
268
269 if (cmsis_dap_vid[i] || cmsis_dap_pid[i])
270 found = true;
271 }
272
273 if (found) {
274 /* we have found an adapter, so exit further checks */
275 /* check serial number matches if given */
276 if (cmsis_dap_serial != NULL) {
277 if ((cur_dev->serial_number != NULL) && wcscmp(cmsis_dap_serial, cur_dev->serial_number) == 0) {
278 break;
279 }
280 } else
281 break;
282
283 found = false;
284 }
285
286 cur_dev = cur_dev->next;
287 }
288
289 if (NULL != cur_dev) {
290 target_vid = cur_dev->vendor_id;
291 target_pid = cur_dev->product_id;
292 }
293
294 if (target_vid == 0 && target_pid == 0) {
295 LOG_ERROR("unable to find CMSIS-DAP device");
296 hid_free_enumeration(devs);
297 return ERROR_FAIL;
298 }
299
300 dev = hid_open_path(cur_dev->path);
301 hid_free_enumeration(devs);
302
303 if (dev == NULL) {
304 LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
305 return ERROR_FAIL;
306 }
307
308 struct cmsis_dap *dap = malloc(sizeof(struct cmsis_dap));
309 if (dap == NULL) {
310 LOG_ERROR("unable to allocate memory");
311 return ERROR_FAIL;
312 }
313
314 dap->dev_handle = dev;
315 dap->caps = 0;
316 dap->mode = 0;
317
318 cmsis_dap_handle = dap;
319
320 /* allocate default packet buffer, may be changed later.
321 * currently with HIDAPI we have no way of getting the output report length
322 * without this info we cannot communicate with the adapter.
323 * For the moment we ahve to hard code the packet size */
324
325 int packet_size = PACKET_SIZE;
326
327 /* atmel cmsis-dap uses 512 byte reports */
328 /* except when it doesn't e.g. with mEDBG on SAMD10 Xplained
329 * board */
330 /* TODO: HID report descriptor should be parsed instead of
331 * hardcoding a match by VID */
332 if (target_vid == 0x03eb && target_pid != 0x2145)
333 packet_size = 512 + 1;
334
335 cmsis_dap_handle->packet_buffer = malloc(packet_size);
336 cmsis_dap_handle->packet_size = packet_size;
337
338 if (cmsis_dap_handle->packet_buffer == NULL) {
339 LOG_ERROR("unable to allocate memory");
340 return ERROR_FAIL;
341 }
342
343 return ERROR_OK;
344 }
345
346 static void cmsis_dap_usb_close(struct cmsis_dap *dap)
347 {
348 hid_close(dap->dev_handle);
349 hid_exit();
350
351 free(cmsis_dap_handle->packet_buffer);
352 free(cmsis_dap_handle);
353 cmsis_dap_handle = NULL;
354 free(cmsis_dap_serial);
355 cmsis_dap_serial = NULL;
356
357 for (int i = 0; i < MAX_PENDING_REQUESTS; i++) {
358 free(pending_fifo[i].transfers);
359 pending_fifo[i].transfers = NULL;
360 }
361 }
362
363 static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen)
364 {
365 #ifdef CMSIS_DAP_JTAG_DEBUG
366 LOG_DEBUG("cmsis-dap usb xfer cmd=%02X", dap->packet_buffer[1]);
367 #endif
368 /* Pad the rest of the TX buffer with 0's */
369 memset(dap->packet_buffer + txlen, 0, dap->packet_size - txlen);
370
371 /* write data to device */
372 int retval = hid_write(dap->dev_handle, dap->packet_buffer, dap->packet_size);
373 if (retval == -1) {
374 LOG_ERROR("error writing data: %ls", hid_error(dap->dev_handle));
375 return ERROR_FAIL;
376 }
377
378 return ERROR_OK;
379 }
380
381 /* Send a message and receive the reply */
382 static int cmsis_dap_usb_xfer(struct cmsis_dap *dap, int txlen)
383 {
384 if (pending_fifo_block_count) {
385 LOG_ERROR("pending %d blocks, flushing", pending_fifo_block_count);
386 while (pending_fifo_block_count) {
387 hid_read_timeout(dap->dev_handle, dap->packet_buffer, dap->packet_size, 10);
388 pending_fifo_block_count--;
389 }
390 pending_fifo_put_idx = 0;
391 pending_fifo_get_idx = 0;
392 }
393
394 int retval = cmsis_dap_usb_write(dap, txlen);
395 if (retval != ERROR_OK)
396 return retval;
397
398 /* get reply */
399 retval = hid_read_timeout(dap->dev_handle, dap->packet_buffer, dap->packet_size, USB_TIMEOUT);
400 if (retval == -1 || retval == 0) {
401 LOG_DEBUG("error reading data: %ls", hid_error(dap->dev_handle));
402 return ERROR_FAIL;
403 }
404
405 return ERROR_OK;
406 }
407
408 static int cmsis_dap_cmd_DAP_SWJ_Pins(uint8_t pins, uint8_t mask, uint32_t delay, uint8_t *input)
409 {
410 int retval;
411 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
412
413 buffer[0] = 0; /* report number */
414 buffer[1] = CMD_DAP_SWJ_PINS;
415 buffer[2] = pins;
416 buffer[3] = mask;
417 buffer[4] = delay & 0xff;
418 buffer[5] = (delay >> 8) & 0xff;
419 buffer[6] = (delay >> 16) & 0xff;
420 buffer[7] = (delay >> 24) & 0xff;
421 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 8);
422
423 if (retval != ERROR_OK) {
424 LOG_ERROR("CMSIS-DAP command CMD_DAP_SWJ_PINS failed.");
425 return ERROR_JTAG_DEVICE_ERROR;
426 }
427
428 if (input)
429 *input = buffer[1];
430
431 return ERROR_OK;
432 }
433
434 static int cmsis_dap_cmd_DAP_SWJ_Clock(uint32_t swj_clock)
435 {
436 int retval;
437 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
438
439 /* set clock in Hz */
440 swj_clock *= 1000;
441 buffer[0] = 0; /* report number */
442 buffer[1] = CMD_DAP_SWJ_CLOCK;
443 buffer[2] = swj_clock & 0xff;
444 buffer[3] = (swj_clock >> 8) & 0xff;
445 buffer[4] = (swj_clock >> 16) & 0xff;
446 buffer[5] = (swj_clock >> 24) & 0xff;
447 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 6);
448
449 if (retval != ERROR_OK || buffer[1] != DAP_OK) {
450 LOG_ERROR("CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed.");
451 return ERROR_JTAG_DEVICE_ERROR;
452 }
453
454 return ERROR_OK;
455 }
456
457 /* clock a sequence of bits out on TMS, to change JTAG states */
458 static int cmsis_dap_cmd_DAP_SWJ_Sequence(uint8_t s_len, const uint8_t *sequence)
459 {
460 int retval;
461 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
462
463 #ifdef CMSIS_DAP_JTAG_DEBUG
464 LOG_DEBUG("cmsis-dap TMS sequence: len=%d", s_len);
465 for (int i = 0; i < DIV_ROUND_UP(s_len, 8); ++i)
466 printf("%02X ", sequence[i]);
467
468 printf("\n");
469 #endif
470
471 buffer[0] = 0; /* report number */
472 buffer[1] = CMD_DAP_SWJ_SEQ;
473 buffer[2] = s_len;
474 bit_copy(&buffer[3], 0, sequence, 0, s_len);
475
476 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, DIV_ROUND_UP(s_len, 8) + 3);
477
478 if (retval != ERROR_OK || buffer[1] != DAP_OK)
479 return ERROR_FAIL;
480
481 return ERROR_OK;
482 }
483
484 static int cmsis_dap_cmd_DAP_Info(uint8_t info, uint8_t **data)
485 {
486 int retval;
487 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
488
489 buffer[0] = 0; /* report number */
490 buffer[1] = CMD_DAP_INFO;
491 buffer[2] = info;
492 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 3);
493
494 if (retval != ERROR_OK) {
495 LOG_ERROR("CMSIS-DAP command CMD_INFO failed.");
496 return ERROR_JTAG_DEVICE_ERROR;
497 }
498
499 *data = &(buffer[1]);
500
501 return ERROR_OK;
502 }
503
504 static int cmsis_dap_cmd_DAP_LED(uint8_t led, uint8_t state)
505 {
506 int retval;
507 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
508
509 buffer[0] = 0; /* report number */
510 buffer[1] = CMD_DAP_LED;
511 buffer[2] = led;
512 buffer[3] = state;
513 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 4);
514
515 if (retval != ERROR_OK || buffer[1] != 0x00) {
516 LOG_ERROR("CMSIS-DAP command CMD_LED failed.");
517 return ERROR_JTAG_DEVICE_ERROR;
518 }
519
520 return ERROR_OK;
521 }
522
523 static int cmsis_dap_cmd_DAP_Connect(uint8_t mode)
524 {
525 int retval;
526 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
527
528 buffer[0] = 0; /* report number */
529 buffer[1] = CMD_DAP_CONNECT;
530 buffer[2] = mode;
531 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 3);
532
533 if (retval != ERROR_OK) {
534 LOG_ERROR("CMSIS-DAP command CMD_CONNECT failed.");
535 return ERROR_JTAG_DEVICE_ERROR;
536 }
537
538 if (buffer[1] != mode) {
539 LOG_ERROR("CMSIS-DAP failed to connect in mode (%d)", mode);
540 return ERROR_JTAG_DEVICE_ERROR;
541 }
542
543 return ERROR_OK;
544 }
545
546 static int cmsis_dap_cmd_DAP_Disconnect(void)
547 {
548 int retval;
549 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
550
551 buffer[0] = 0; /* report number */
552 buffer[1] = CMD_DAP_DISCONNECT;
553 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 2);
554
555 if (retval != ERROR_OK || buffer[1] != DAP_OK) {
556 LOG_ERROR("CMSIS-DAP command CMD_DISCONNECT failed.");
557 return ERROR_JTAG_DEVICE_ERROR;
558 }
559
560 return ERROR_OK;
561 }
562
563 static int cmsis_dap_cmd_DAP_TFER_Configure(uint8_t idle, uint16_t retry_count, uint16_t match_retry)
564 {
565 int retval;
566 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
567
568 buffer[0] = 0; /* report number */
569 buffer[1] = CMD_DAP_TFER_CONFIGURE;
570 buffer[2] = idle;
571 buffer[3] = retry_count & 0xff;
572 buffer[4] = (retry_count >> 8) & 0xff;
573 buffer[5] = match_retry & 0xff;
574 buffer[6] = (match_retry >> 8) & 0xff;
575 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 7);
576
577 if (retval != ERROR_OK || buffer[1] != DAP_OK) {
578 LOG_ERROR("CMSIS-DAP command CMD_TFER_Configure failed.");
579 return ERROR_JTAG_DEVICE_ERROR;
580 }
581
582 return ERROR_OK;
583 }
584
585 static int cmsis_dap_cmd_DAP_SWD_Configure(uint8_t cfg)
586 {
587 int retval;
588 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
589
590 buffer[0] = 0; /* report number */
591 buffer[1] = CMD_DAP_SWD_CONFIGURE;
592 buffer[2] = cfg;
593 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 3);
594
595 if (retval != ERROR_OK || buffer[1] != DAP_OK) {
596 LOG_ERROR("CMSIS-DAP command CMD_SWD_Configure failed.");
597 return ERROR_JTAG_DEVICE_ERROR;
598 }
599
600 return ERROR_OK;
601 }
602
603 #if 0
604 static int cmsis_dap_cmd_DAP_Delay(uint16_t delay_us)
605 {
606 int retval;
607 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
608
609 buffer[0] = 0; /* report number */
610 buffer[1] = CMD_DAP_DELAY;
611 buffer[2] = delay_us & 0xff;
612 buffer[3] = (delay_us >> 8) & 0xff;
613 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, 4);
614
615 if (retval != ERROR_OK || buffer[1] != DAP_OK) {
616 LOG_ERROR("CMSIS-DAP command CMD_Delay failed.");
617 return ERROR_JTAG_DEVICE_ERROR;
618 }
619
620 return ERROR_OK;
621 }
622 #endif
623
624 static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap)
625 {
626 uint8_t *buffer = dap->packet_buffer;
627 struct pending_request_block *block = &pending_fifo[pending_fifo_put_idx];
628
629 LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %d", block->transfer_count, pending_fifo_put_idx);
630
631 if (queued_retval != ERROR_OK) {
632 LOG_DEBUG("Skipping due to previous errors: %d", queued_retval);
633 goto skip;
634 }
635
636 if (block->transfer_count == 0)
637 goto skip;
638
639 size_t idx = 0;
640 buffer[idx++] = 0; /* report number */
641 buffer[idx++] = CMD_DAP_TFER;
642 buffer[idx++] = 0x00; /* DAP Index */
643 buffer[idx++] = block->transfer_count;
644
645 for (int i = 0; i < block->transfer_count; i++) {
646 struct pending_transfer_result *transfer = &(block->transfers[i]);
647 uint8_t cmd = transfer->cmd;
648 uint32_t data = transfer->data;
649
650 LOG_DEBUG_IO("%s %s reg %x %"PRIx32,
651 cmd & SWD_CMD_APnDP ? "AP" : "DP",
652 cmd & SWD_CMD_RnW ? "read" : "write",
653 (cmd & SWD_CMD_A32) >> 1, data);
654
655 /* When proper WAIT handling is implemented in the
656 * common SWD framework, this kludge can be
657 * removed. However, this might lead to minor
658 * performance degradation as the adapter wouldn't be
659 * able to automatically retry anything (because ARM
660 * has forgotten to implement sticky error flags
661 * clearing). See also comments regarding
662 * cmsis_dap_cmd_DAP_TFER_Configure() and
663 * cmsis_dap_cmd_DAP_SWD_Configure() in
664 * cmsis_dap_init().
665 */
666 if (!(cmd & SWD_CMD_RnW) &&
667 !(cmd & SWD_CMD_APnDP) &&
668 (cmd & SWD_CMD_A32) >> 1 == DP_CTRL_STAT &&
669 (data & CORUNDETECT)) {
670 LOG_DEBUG("refusing to enable sticky overrun detection");
671 data &= ~CORUNDETECT;
672 }
673
674 buffer[idx++] = (cmd >> 1) & 0x0f;
675 if (!(cmd & SWD_CMD_RnW)) {
676 buffer[idx++] = (data) & 0xff;
677 buffer[idx++] = (data >> 8) & 0xff;
678 buffer[idx++] = (data >> 16) & 0xff;
679 buffer[idx++] = (data >> 24) & 0xff;
680 }
681 }
682
683 queued_retval = cmsis_dap_usb_write(dap, idx);
684 if (queued_retval != ERROR_OK)
685 goto skip;
686
687 pending_fifo_put_idx = (pending_fifo_put_idx + 1) % dap->packet_count;
688 pending_fifo_block_count++;
689 if (pending_fifo_block_count > dap->packet_count)
690 LOG_ERROR("too much pending writes %d", pending_fifo_block_count);
691
692 return;
693
694 skip:
695 block->transfer_count = 0;
696 }
697
698 static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
699 {
700 uint8_t *buffer = dap->packet_buffer;
701 struct pending_request_block *block = &pending_fifo[pending_fifo_get_idx];
702
703 if (pending_fifo_block_count == 0)
704 LOG_ERROR("no pending write");
705
706 /* get reply */
707 int retval = hid_read_timeout(dap->dev_handle, dap->packet_buffer, dap->packet_size, timeout_ms);
708 if (retval == 0 && timeout_ms < USB_TIMEOUT)
709 return;
710
711 if (retval == -1 || retval == 0) {
712 LOG_DEBUG("error reading data: %ls", hid_error(dap->dev_handle));
713 queued_retval = ERROR_FAIL;
714 goto skip;
715 }
716
717 if (buffer[2] & 0x08) {
718 LOG_DEBUG("CMSIS-DAP Protocol Error @ %d (wrong parity)", buffer[1]);
719 queued_retval = ERROR_FAIL;
720 goto skip;
721 }
722 uint8_t ack = buffer[2] & 0x07;
723 if (ack != SWD_ACK_OK) {
724 LOG_DEBUG("SWD ack not OK @ %d %s", buffer[1],
725 ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK");
726 queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL;
727 goto skip;
728 }
729
730 if (block->transfer_count != buffer[1])
731 LOG_ERROR("CMSIS-DAP transfer count mismatch: expected %d, got %d",
732 block->transfer_count, buffer[1]);
733
734 LOG_DEBUG_IO("Received results of %d queued transactions FIFO index %d", buffer[1], pending_fifo_get_idx);
735 size_t idx = 3;
736 for (int i = 0; i < buffer[1]; i++) {
737 struct pending_transfer_result *transfer = &(block->transfers[i]);
738 if (transfer->cmd & SWD_CMD_RnW) {
739 static uint32_t last_read;
740 uint32_t data = le_to_h_u32(&buffer[idx]);
741 uint32_t tmp = data;
742 idx += 4;
743
744 LOG_DEBUG_IO("Read result: %"PRIx32, data);
745
746 /* Imitate posted AP reads */
747 if ((transfer->cmd & SWD_CMD_APnDP) ||
748 ((transfer->cmd & SWD_CMD_A32) >> 1 == DP_RDBUFF)) {
749 tmp = last_read;
750 last_read = data;
751 }
752
753 if (transfer->buffer)
754 *(uint32_t *)(transfer->buffer) = tmp;
755 }
756 }
757
758 skip:
759 block->transfer_count = 0;
760 pending_fifo_get_idx = (pending_fifo_get_idx + 1) % dap->packet_count;
761 pending_fifo_block_count--;
762 }
763
764 static int cmsis_dap_swd_run_queue(void)
765 {
766 if (pending_fifo_block_count)
767 cmsis_dap_swd_read_process(cmsis_dap_handle, 0);
768
769 cmsis_dap_swd_write_from_queue(cmsis_dap_handle);
770
771 while (pending_fifo_block_count)
772 cmsis_dap_swd_read_process(cmsis_dap_handle, USB_TIMEOUT);
773
774 pending_fifo_put_idx = 0;
775 pending_fifo_get_idx = 0;
776
777 int retval = queued_retval;
778 queued_retval = ERROR_OK;
779
780 return retval;
781 }
782
783 static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
784 {
785 if (pending_fifo[pending_fifo_put_idx].transfer_count == pending_queue_len) {
786 if (pending_fifo_block_count)
787 cmsis_dap_swd_read_process(cmsis_dap_handle, 0);
788
789 /* Not enough room in the queue. Run the queue. */
790 cmsis_dap_swd_write_from_queue(cmsis_dap_handle);
791
792 if (pending_fifo_block_count >= cmsis_dap_handle->packet_count)
793 cmsis_dap_swd_read_process(cmsis_dap_handle, USB_TIMEOUT);
794 }
795
796 if (queued_retval != ERROR_OK)
797 return;
798
799 struct pending_request_block *block = &pending_fifo[pending_fifo_put_idx];
800 struct pending_transfer_result *transfer = &(block->transfers[block->transfer_count]);
801 transfer->data = data;
802 transfer->cmd = cmd;
803 if (cmd & SWD_CMD_RnW) {
804 /* Queue a read transaction */
805 transfer->buffer = dst;
806 }
807 block->transfer_count++;
808 }
809
810 static void cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
811 {
812 assert(!(cmd & SWD_CMD_RnW));
813 cmsis_dap_swd_queue_cmd(cmd, NULL, value);
814 }
815
816 static void cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
817 {
818 assert(cmd & SWD_CMD_RnW);
819 cmsis_dap_swd_queue_cmd(cmd, value, 0);
820 }
821
822 static int cmsis_dap_get_serial_info(void)
823 {
824 uint8_t *data;
825
826 int retval = cmsis_dap_cmd_DAP_Info(INFO_ID_SERNUM, &data);
827 if (retval != ERROR_OK)
828 return retval;
829
830 if (data[0]) /* strlen */
831 LOG_INFO("CMSIS-DAP: Serial# = %s", &data[1]);
832
833 return ERROR_OK;
834 }
835
836 static int cmsis_dap_get_version_info(void)
837 {
838 uint8_t *data;
839
840 /* INFO_ID_FW_VER - string */
841 int retval = cmsis_dap_cmd_DAP_Info(INFO_ID_FW_VER, &data);
842 if (retval != ERROR_OK)
843 return retval;
844
845 if (data[0]) /* strlen */
846 LOG_INFO("CMSIS-DAP: FW Version = %s", &data[1]);
847
848 return ERROR_OK;
849 }
850
851 static int cmsis_dap_get_caps_info(void)
852 {
853 uint8_t *data;
854
855 /* INFO_ID_CAPS - byte */
856 int retval = cmsis_dap_cmd_DAP_Info(INFO_ID_CAPS, &data);
857 if (retval != ERROR_OK)
858 return retval;
859
860 if (data[0] == 1) {
861 uint8_t caps = data[1];
862
863 cmsis_dap_handle->caps = caps;
864
865 if (caps & INFO_CAPS_SWD)
866 LOG_INFO("CMSIS-DAP: %s", info_caps_str[0]);
867 if (caps & INFO_CAPS_JTAG)
868 LOG_INFO("CMSIS-DAP: %s", info_caps_str[1]);
869 }
870
871 return ERROR_OK;
872 }
873
874 static int cmsis_dap_get_status(void)
875 {
876 uint8_t d;
877
878 int retval = cmsis_dap_cmd_DAP_SWJ_Pins(0, 0, 0, &d);
879
880 if (retval == ERROR_OK) {
881 LOG_INFO("SWCLK/TCK = %d SWDIO/TMS = %d TDI = %d TDO = %d nTRST = %d nRESET = %d",
882 (d & SWJ_PIN_TCK) ? 1 : 0,
883 (d & SWJ_PIN_TMS) ? 1 : 0,
884 (d & SWJ_PIN_TDI) ? 1 : 0,
885 (d & SWJ_PIN_TDO) ? 1 : 0,
886 (d & SWJ_PIN_TRST) ? 1 : 0,
887 (d & SWJ_PIN_SRST) ? 1 : 0);
888 }
889
890 return retval;
891 }
892
893 static int cmsis_dap_swd_switch_seq(enum swd_special_seq seq)
894 {
895 const uint8_t *s;
896 unsigned int s_len;
897 int retval;
898
899 if ((output_pins & (SWJ_PIN_SRST | SWJ_PIN_TRST)) == (SWJ_PIN_SRST | SWJ_PIN_TRST)) {
900 /* Following workaround deasserts reset on most adapters.
901 * Do not reconnect if a reset line is active!
902 * Reconnecting would break connecting under reset. */
903
904 /* First disconnect before connecting, Atmel EDBG needs it for SAMD/R/L/C */
905 cmsis_dap_cmd_DAP_Disconnect();
906
907 /* When we are reconnecting, DAP_Connect needs to be rerun, at
908 * least on Keil ULINK-ME */
909 retval = cmsis_dap_cmd_DAP_Connect(CONNECT_SWD);
910 if (retval != ERROR_OK)
911 return retval;
912 }
913
914 switch (seq) {
915 case LINE_RESET:
916 LOG_DEBUG("SWD line reset");
917 s = swd_seq_line_reset;
918 s_len = swd_seq_line_reset_len;
919 break;
920 case JTAG_TO_SWD:
921 LOG_DEBUG("JTAG-to-SWD");
922 s = swd_seq_jtag_to_swd;
923 s_len = swd_seq_jtag_to_swd_len;
924 break;
925 case SWD_TO_JTAG:
926 LOG_DEBUG("SWD-to-JTAG");
927 s = swd_seq_swd_to_jtag;
928 s_len = swd_seq_swd_to_jtag_len;
929 break;
930 default:
931 LOG_ERROR("Sequence %d not supported", seq);
932 return ERROR_FAIL;
933 }
934
935 retval = cmsis_dap_cmd_DAP_SWJ_Sequence(s_len, s);
936 if (retval != ERROR_OK)
937 return retval;
938
939 /* Atmel EDBG needs renew clock setting after SWJ_Sequence
940 * otherwise default frequency is used */
941 return cmsis_dap_cmd_DAP_SWJ_Clock(jtag_get_speed_khz());
942 }
943
944 static int cmsis_dap_swd_open(void)
945 {
946 int retval;
947
948 if (!(cmsis_dap_handle->caps & INFO_CAPS_SWD)) {
949 LOG_ERROR("CMSIS-DAP: SWD not supported");
950 return ERROR_JTAG_DEVICE_ERROR;
951 }
952
953 retval = cmsis_dap_cmd_DAP_Connect(CONNECT_SWD);
954 if (retval != ERROR_OK)
955 return retval;
956
957 /* Add more setup here.??... */
958
959 LOG_INFO("CMSIS-DAP: Interface Initialised (SWD)");
960 return ERROR_OK;
961 }
962
963 static int cmsis_dap_init(void)
964 {
965 int retval;
966 uint8_t *data;
967
968 retval = cmsis_dap_usb_open();
969 if (retval != ERROR_OK)
970 return retval;
971
972 retval = cmsis_dap_get_caps_info();
973 if (retval != ERROR_OK)
974 return retval;
975
976 retval = cmsis_dap_get_version_info();
977 if (retval != ERROR_OK)
978 return retval;
979
980 retval = cmsis_dap_get_serial_info();
981 if (retval != ERROR_OK)
982 return retval;
983
984 if (swd_mode) {
985 retval = cmsis_dap_swd_open();
986 if (retval != ERROR_OK)
987 return retval;
988 } else {
989 /* Connect in JTAG mode */
990 if (!(cmsis_dap_handle->caps & INFO_CAPS_JTAG)) {
991 LOG_ERROR("CMSIS-DAP: JTAG not supported");
992 return ERROR_JTAG_DEVICE_ERROR;
993 }
994
995 retval = cmsis_dap_cmd_DAP_Connect(CONNECT_JTAG);
996 if (retval != ERROR_OK)
997 return retval;
998
999 LOG_INFO("CMSIS-DAP: Interface Initialised (JTAG)");
1000 }
1001
1002 /* Be conservative and supress submiting multiple HID requests
1003 * until we get packet count info from the adaptor */
1004 cmsis_dap_handle->packet_count = 1;
1005 pending_queue_len = 12;
1006
1007 /* INFO_ID_PKT_SZ - short */
1008 retval = cmsis_dap_cmd_DAP_Info(INFO_ID_PKT_SZ, &data);
1009 if (retval != ERROR_OK)
1010 return retval;
1011
1012 if (data[0] == 2) { /* short */
1013 uint16_t pkt_sz = data[1] + (data[2] << 8);
1014
1015 /* 4 bytes of command header + 5 bytes per register
1016 * write. For bulk read sequences just 4 bytes are
1017 * needed per transfer, so this is suboptimal. */
1018 pending_queue_len = (pkt_sz - 4) / 5;
1019
1020 if (cmsis_dap_handle->packet_size != pkt_sz + 1) {
1021 /* reallocate buffer */
1022 cmsis_dap_handle->packet_size = pkt_sz + 1;
1023 cmsis_dap_handle->packet_buffer = realloc(cmsis_dap_handle->packet_buffer,
1024 cmsis_dap_handle->packet_size);
1025 if (cmsis_dap_handle->packet_buffer == NULL) {
1026 LOG_ERROR("unable to reallocate memory");
1027 return ERROR_FAIL;
1028 }
1029 }
1030
1031 LOG_DEBUG("CMSIS-DAP: Packet Size = %" PRId16, pkt_sz);
1032 }
1033
1034 /* INFO_ID_PKT_CNT - byte */
1035 retval = cmsis_dap_cmd_DAP_Info(INFO_ID_PKT_CNT, &data);
1036 if (retval != ERROR_OK)
1037 return retval;
1038
1039 if (data[0] == 1) { /* byte */
1040 int pkt_cnt = data[1];
1041 if (pkt_cnt > 1)
1042 cmsis_dap_handle->packet_count = MIN(MAX_PENDING_REQUESTS, pkt_cnt);
1043
1044 LOG_DEBUG("CMSIS-DAP: Packet Count = %d", pkt_cnt);
1045 }
1046
1047 LOG_DEBUG("Allocating FIFO for %d pending HID requests", cmsis_dap_handle->packet_count);
1048 for (int i = 0; i < cmsis_dap_handle->packet_count; i++) {
1049 pending_fifo[i].transfers = malloc(pending_queue_len * sizeof(struct pending_transfer_result));
1050 if (!pending_fifo[i].transfers) {
1051 LOG_ERROR("Unable to allocate memory for CMSIS-DAP queue");
1052 return ERROR_FAIL;
1053 }
1054 }
1055
1056
1057 retval = cmsis_dap_get_status();
1058 if (retval != ERROR_OK)
1059 return ERROR_FAIL;
1060
1061 /* Now try to connect to the target
1062 * TODO: This is all SWD only @ present */
1063 retval = cmsis_dap_cmd_DAP_SWJ_Clock(jtag_get_speed_khz());
1064 if (retval != ERROR_OK)
1065 return ERROR_FAIL;
1066
1067 /* Ask CMSIS-DAP to automatically retry on receiving WAIT for
1068 * up to 64 times. This must be changed to 0 if sticky
1069 * overrun detection is enabled. */
1070 retval = cmsis_dap_cmd_DAP_TFER_Configure(0, 64, 0);
1071 if (retval != ERROR_OK)
1072 return ERROR_FAIL;
1073
1074 if (swd_mode) {
1075 /* Data Phase (bit 2) must be set to 1 if sticky overrun
1076 * detection is enabled */
1077 retval = cmsis_dap_cmd_DAP_SWD_Configure(0); /* 1 TRN, no Data Phase */
1078 if (retval != ERROR_OK)
1079 return ERROR_FAIL;
1080 }
1081 /* Both LEDs on */
1082 retval = cmsis_dap_cmd_DAP_LED(LED_ID_CONNECT, LED_ON);
1083 if (retval != ERROR_OK)
1084 return ERROR_FAIL;
1085
1086 retval = cmsis_dap_cmd_DAP_LED(LED_ID_RUN, LED_ON);
1087 if (retval != ERROR_OK)
1088 return ERROR_FAIL;
1089
1090 /* support connecting with srst asserted */
1091 enum reset_types jtag_reset_config = jtag_get_reset_config();
1092
1093 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
1094 if (jtag_reset_config & RESET_SRST_NO_GATING) {
1095 retval = cmsis_dap_cmd_DAP_SWJ_Pins(0, SWJ_PIN_SRST, 0, NULL);
1096 if (retval != ERROR_OK)
1097 return ERROR_FAIL;
1098 LOG_INFO("Connecting under reset");
1099 }
1100 }
1101 LOG_INFO("CMSIS-DAP: Interface ready");
1102
1103 return ERROR_OK;
1104 }
1105
1106 static int cmsis_dap_swd_init(void)
1107 {
1108 swd_mode = true;
1109 return ERROR_OK;
1110 }
1111
1112 static int cmsis_dap_quit(void)
1113 {
1114 cmsis_dap_cmd_DAP_Disconnect();
1115 /* Both LEDs off */
1116 cmsis_dap_cmd_DAP_LED(LED_ID_RUN, LED_OFF);
1117 cmsis_dap_cmd_DAP_LED(LED_ID_CONNECT, LED_OFF);
1118
1119 cmsis_dap_usb_close(cmsis_dap_handle);
1120
1121 return ERROR_OK;
1122 }
1123
1124 static int cmsis_dap_reset(int trst, int srst)
1125 {
1126 /* Set both TRST and SRST even if they're not enabled as
1127 * there's no way to tristate them */
1128
1129 output_pins = 0;
1130 if (!srst)
1131 output_pins |= SWJ_PIN_SRST;
1132 if (!trst)
1133 output_pins |= SWJ_PIN_TRST;
1134
1135 int retval = cmsis_dap_cmd_DAP_SWJ_Pins(output_pins,
1136 SWJ_PIN_TRST | SWJ_PIN_SRST, 0, NULL);
1137 if (retval != ERROR_OK)
1138 LOG_ERROR("CMSIS-DAP: Interface reset failed");
1139 return retval;
1140 }
1141
1142 static void cmsis_dap_execute_sleep(struct jtag_command *cmd)
1143 {
1144 #if 0
1145 int retval = cmsis_dap_cmd_DAP_Delay(cmd->cmd.sleep->us);
1146 if (retval != ERROR_OK)
1147 #endif
1148 jtag_sleep(cmd->cmd.sleep->us);
1149 }
1150
1151 /* Set TMS high for five TCK clocks, to move the TAP to the Test-Logic-Reset state */
1152 static int cmsis_dap_execute_tlr_reset(struct jtag_command *cmd)
1153 {
1154 LOG_INFO("cmsis-dap JTAG TLR_RESET");
1155 uint8_t seq = 0xff;
1156 int ret = cmsis_dap_cmd_DAP_SWJ_Sequence(8, &seq);
1157 if (ret == ERROR_OK)
1158 tap_set_state(TAP_RESET);
1159 return ret;
1160 }
1161
1162 /* Set new end state */
1163 static void cmsis_dap_end_state(tap_state_t state)
1164 {
1165 if (tap_is_state_stable(state))
1166 tap_set_end_state(state);
1167 else {
1168 LOG_ERROR("BUG: %i is not a valid end state", state);
1169 exit(-1);
1170 }
1171 }
1172
1173 #ifdef SPRINT_BINARY
1174 static void sprint_binary(char *s, const uint8_t *buf, int offset, int len)
1175 {
1176 if (!len)
1177 return;
1178
1179 /*
1180 buf = { 0x18 } len=5 should result in: 11000
1181 buf = { 0xff 0x18 } len=13 should result in: 11111111 11000
1182 buf = { 0xc0 0x18 } offset=3 len=10 should result in: 11000 11000
1183 i=3 there means i/8 = 0 so c = 0xFF, and
1184 */
1185 for (int i = offset; i < offset + len; ++i) {
1186 uint8_t c = buf[i / 8], mask = 1 << (i % 8);
1187 if ((i != offset) && !(i % 8))
1188 putchar(' ');
1189 *s++ = (c & mask) ? '1' : '0';
1190 }
1191 *s = 0;
1192 }
1193 #endif
1194
1195 #ifdef CMSIS_DAP_JTAG_DEBUG
1196 static void debug_parse_cmsis_buf(const uint8_t *cmd, int cmdlen)
1197 {
1198 /* cmd is a usb packet to go to the cmsis-dap interface */
1199 printf("cmsis-dap buffer (%d b): ", cmdlen);
1200 for (int i = 0; i < cmdlen; ++i)
1201 printf(" %02x", cmd[i]);
1202 printf("\n");
1203 switch (cmd[1]) {
1204 case CMD_DAP_JTAG_SEQ: {
1205 printf("cmsis-dap jtag sequence command %02x (n=%d)\n", cmd[1], cmd[2]);
1206 /*
1207 * #2 = number of sequences
1208 * #3 = sequence info 1
1209 * #4...4+n_bytes-1 = sequence 1
1210 * #4+n_bytes = sequence info 2
1211 * #5+n_bytes = sequence 2 (single bit)
1212 */
1213 int pos = 3;
1214 for (int seq = 0; seq < cmd[2]; ++seq) {
1215 uint8_t info = cmd[pos++];
1216 int len = info & DAP_JTAG_SEQ_TCK;
1217 if (len == 0)
1218 len = 64;
1219 printf(" sequence %d starting %d: info %02x (len=%d tms=%d read_tdo=%d): ",
1220 seq, pos, info, len, info & DAP_JTAG_SEQ_TMS, info & DAP_JTAG_SEQ_TDO);
1221 for (int i = 0; i < DIV_ROUND_UP(len, 8); ++i)
1222 printf(" %02x", cmd[pos+i]);
1223 pos += DIV_ROUND_UP(len, 8);
1224 printf("\n");
1225 }
1226 if (pos != cmdlen) {
1227 printf("BUFFER LENGTH MISMATCH looks like %d but %d specified", pos, cmdlen);
1228 exit(-1);
1229 }
1230
1231 break;
1232 }
1233 default:
1234 LOG_DEBUG("unknown cmsis-dap command %02x", cmd[1]);
1235 break;
1236 }
1237 }
1238 #endif
1239
1240 static void cmsis_dap_flush(void)
1241 {
1242 if (!queued_seq_count)
1243 return;
1244
1245 LOG_DEBUG_IO("Flushing %d queued sequences (%d bytes) with %d pending scan results to capture",
1246 queued_seq_count, queued_seq_buf_end, pending_scan_result_count);
1247
1248 /* prep CMSIS-DAP packet */
1249 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
1250 buffer[0] = 0; /* report number */
1251 buffer[1] = CMD_DAP_JTAG_SEQ;
1252 buffer[2] = queued_seq_count;
1253 memcpy(buffer + 3, queued_seq_buf, queued_seq_buf_end);
1254
1255 #ifdef CMSIS_DAP_JTAG_DEBUG
1256 debug_parse_cmsis_buf(buffer, queued_seq_buf_end + 3);
1257 #endif
1258
1259 /* send command to USB device */
1260 int retval = cmsis_dap_usb_xfer(cmsis_dap_handle, queued_seq_buf_end + 3);
1261 if (retval != ERROR_OK || buffer[1] != DAP_OK) {
1262 LOG_ERROR("CMSIS-DAP command CMD_DAP_JTAG_SEQ failed.");
1263 exit(-1);
1264 }
1265
1266 #ifdef CMSIS_DAP_JTAG_DEBUG
1267 LOG_DEBUG_IO("USB response buf:");
1268 for (int c = 0; c < queued_seq_buf_end + 3; ++c)
1269 printf("%02X ", buffer[c]);
1270 printf("\n");
1271 #endif
1272
1273 /* copy scan results into client buffers */
1274 for (int i = 0; i < pending_scan_result_count; ++i) {
1275 struct pending_scan_result *scan = &pending_scan_results[i];
1276 LOG_DEBUG_IO("Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits",
1277 i, pending_scan_result_count, scan->length, scan->first + 2, scan->buffer_offset);
1278 #ifdef CMSIS_DAP_JTAG_DEBUG
1279 for (uint32_t b = 0; b < DIV_ROUND_UP(scan->length, 8); ++b)
1280 printf("%02X ", buffer[2+scan->first+b]);
1281 printf("\n");
1282 #endif
1283 bit_copy(scan->buffer, scan->buffer_offset, buffer + 2 + scan->first, 0, scan->length);
1284 }
1285
1286 /* reset */
1287 queued_seq_count = 0;
1288 queued_seq_buf_end = 0;
1289 queued_seq_tdo_ptr = 0;
1290 pending_scan_result_count = 0;
1291 }
1292
1293 /* queue a sequence of bits to clock out TDI / in TDO, executing if the buffer is full.
1294 *
1295 * sequence=NULL means clock out zeros on TDI
1296 * tdo_buffer=NULL means don't capture TDO
1297 */
1298 static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int s_offset,
1299 bool tms, uint8_t *tdo_buffer, int tdo_buffer_offset)
1300 {
1301 LOG_DEBUG_IO("[at %d] %d bits, tms %s, seq offset %d, tdo buf %p, tdo offset %d",
1302 queued_seq_buf_end,
1303 s_len, tms ? "HIGH" : "LOW", s_offset, tdo_buffer, tdo_buffer_offset);
1304
1305 if (s_len == 0)
1306 return;
1307
1308 if (s_len > 64) {
1309 LOG_DEBUG_IO("START JTAG SEQ SPLIT");
1310 for (int offset = 0; offset < s_len; offset += 64) {
1311 int len = s_len - offset;
1312 if (len > 64)
1313 len = 64;
1314 LOG_DEBUG_IO("Splitting long jtag sequence: %d-bit chunk starting at offset %d", len, offset);
1315 cmsis_dap_add_jtag_sequence(
1316 len,
1317 sequence,
1318 s_offset + offset,
1319 tms,
1320 tdo_buffer,
1321 tdo_buffer == NULL ? 0 : (tdo_buffer_offset + offset)
1322 );
1323 }
1324 LOG_DEBUG_IO("END JTAG SEQ SPLIT");
1325 return;
1326 }
1327
1328 int cmd_len = 1 + DIV_ROUND_UP(s_len, 8);
1329 if (queued_seq_count >= 255 || queued_seq_buf_end + cmd_len > QUEUED_SEQ_BUF_LEN)
1330 /* empty out the buffer */
1331 cmsis_dap_flush();
1332
1333 ++queued_seq_count;
1334
1335 /* control byte */
1336 queued_seq_buf[queued_seq_buf_end] =
1337 (tms ? DAP_JTAG_SEQ_TMS : 0) |
1338 (tdo_buffer != NULL ? DAP_JTAG_SEQ_TDO : 0) |
1339 (s_len == 64 ? 0 : s_len);
1340
1341 if (sequence != NULL)
1342 bit_copy(&queued_seq_buf[queued_seq_buf_end + 1], 0, sequence, s_offset, s_len);
1343 else
1344 memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8));
1345
1346 queued_seq_buf_end += cmd_len;
1347
1348 if (tdo_buffer != NULL) {
1349 struct pending_scan_result *scan = &pending_scan_results[pending_scan_result_count++];
1350 scan->first = queued_seq_tdo_ptr;
1351 queued_seq_tdo_ptr += DIV_ROUND_UP(s_len, 8);
1352 scan->length = s_len;
1353 scan->buffer = tdo_buffer;
1354 scan->buffer_offset = tdo_buffer_offset;
1355 }
1356 }
1357
1358 /* queue a sequence of bits to clock out TMS, executing if the buffer is full */
1359 static void cmsis_dap_add_tms_sequence(const uint8_t *sequence, int s_len)
1360 {
1361 LOG_DEBUG_IO("%d bits: %02X", s_len, *sequence);
1362 /* we use a series of CMD_DAP_JTAG_SEQ commands to toggle TMS,
1363 because even though it seems ridiculously inefficient, it
1364 allows us to combine TMS and scan sequences into the same
1365 USB packet. */
1366 /* TODO: combine runs of the same tms value */
1367 for (int i = 0; i < s_len; ++i) {
1368 bool bit = (sequence[i / 8] & (1 << (i % 8))) != 0;
1369 cmsis_dap_add_jtag_sequence(1, NULL, 0, bit, NULL, 0);
1370 }
1371 }
1372
1373 /* Move to the end state by queuing a sequence to clock into TMS */
1374 static void cmsis_dap_state_move(void)
1375 {
1376 uint8_t tms_scan;
1377 uint8_t tms_scan_bits;
1378
1379 tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
1380 tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
1381
1382 LOG_DEBUG_IO("state move from %s to %s: %d clocks, %02X on tms",
1383 tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state()),
1384 tms_scan_bits, tms_scan);
1385 cmsis_dap_add_tms_sequence(&tms_scan, tms_scan_bits);
1386
1387 tap_set_state(tap_get_end_state());
1388 }
1389
1390
1391 /* Execute a JTAG scan operation by queueing TMS and TDI/TDO sequences */
1392 static void cmsis_dap_execute_scan(struct jtag_command *cmd)
1393 {
1394 LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
1395 jtag_scan_type(cmd->cmd.scan));
1396
1397 /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */
1398 while (cmd->cmd.scan->num_fields > 0
1399 && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) {
1400 cmd->cmd.scan->num_fields--;
1401 LOG_DEBUG("discarding trailing empty field");
1402 }
1403
1404 if (cmd->cmd.scan->num_fields == 0) {
1405 LOG_DEBUG("empty scan, doing nothing");
1406 return;
1407 }
1408
1409 if (cmd->cmd.scan->ir_scan) {
1410 if (tap_get_state() != TAP_IRSHIFT) {
1411 cmsis_dap_end_state(TAP_IRSHIFT);
1412 cmsis_dap_state_move();
1413 }
1414 } else {
1415 if (tap_get_state() != TAP_DRSHIFT) {
1416 cmsis_dap_end_state(TAP_DRSHIFT);
1417 cmsis_dap_state_move();
1418 }
1419 }
1420
1421 cmsis_dap_end_state(cmd->cmd.scan->end_state);
1422
1423 struct scan_field *field = cmd->cmd.scan->fields;
1424 unsigned scan_size = 0;
1425
1426 for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) {
1427 scan_size += field->num_bits;
1428 LOG_DEBUG_IO("%s%s field %d/%d %d bits",
1429 field->in_value ? "in" : "",
1430 field->out_value ? "out" : "",
1431 i,
1432 cmd->cmd.scan->num_fields,
1433 field->num_bits);
1434
1435 if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) {
1436 LOG_DEBUG_IO("Last field and have to move out of SHIFT state");
1437 /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap
1438 * movement. This last field can't have length zero, it was checked above. */
1439 cmsis_dap_add_jtag_sequence(
1440 field->num_bits - 1, /* number of bits to clock */
1441 field->out_value, /* output sequence */
1442 0, /* output offset */
1443 false, /* TMS low */
1444 field->in_value,
1445 0);
1446
1447 /* Clock the last bit out, with TMS high */
1448 uint8_t last_bit = 0;
1449 if (field->out_value)
1450 bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
1451 cmsis_dap_add_jtag_sequence(
1452 1,
1453 &last_bit,
1454 0,
1455 true,
1456 field->in_value,
1457 field->num_bits - 1);
1458 tap_set_state(tap_state_transition(tap_get_state(), 1));
1459
1460 /* Now clock one more cycle, with TMS low, to get us into a PAUSE state */
1461 cmsis_dap_add_jtag_sequence(
1462 1,
1463 &last_bit,
1464 0,
1465 false,
1466 NULL,
1467 0);
1468 tap_set_state(tap_state_transition(tap_get_state(), 0));
1469 } else {
1470 LOG_DEBUG_IO("Internal field, staying in SHIFT state afterwards");
1471 /* Clocking part of a sequence into DR or IR with TMS=0,
1472 leaving TMS=0 at the end so we can continue later */
1473 cmsis_dap_add_jtag_sequence(
1474 field->num_bits,
1475 field->out_value,
1476 0,
1477 false,
1478 field->in_value,
1479 0);
1480 }
1481 }
1482
1483 if (tap_get_state() != tap_get_end_state()) {
1484 cmsis_dap_end_state(tap_get_end_state());
1485 cmsis_dap_state_move();
1486 }
1487
1488 LOG_DEBUG_IO("%s scan, %i bits, end in %s",
1489 (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
1490 tap_state_name(tap_get_end_state()));
1491 }
1492
1493 static void cmsis_dap_pathmove(int num_states, tap_state_t *path)
1494 {
1495 int i;
1496 uint8_t tms0 = 0x00;
1497 uint8_t tms1 = 0xff;
1498
1499 for (i = 0; i < num_states; i++) {
1500 if (path[i] == tap_state_transition(tap_get_state(), false))
1501 cmsis_dap_add_tms_sequence(&tms0, 1);
1502 else if (path[i] == tap_state_transition(tap_get_state(), true))
1503 cmsis_dap_add_tms_sequence(&tms1, 1);
1504 else {
1505 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition.",
1506 tap_state_name(tap_get_state()), tap_state_name(path[i]));
1507 exit(-1);
1508 }
1509
1510 tap_set_state(path[i]);
1511 }
1512
1513 cmsis_dap_end_state(tap_get_state());
1514 }
1515
1516 static void cmsis_dap_execute_pathmove(struct jtag_command *cmd)
1517 {
1518 LOG_DEBUG_IO("pathmove: %i states, end in %i",
1519 cmd->cmd.pathmove->num_states,
1520 cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
1521
1522 cmsis_dap_pathmove(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
1523 }
1524
1525 static void cmsis_dap_stableclocks(int num_cycles)
1526 {
1527 int i;
1528
1529 uint8_t tms = tap_get_state() == TAP_RESET;
1530 /* TODO: Perform optimizations? */
1531 /* Execute num_cycles. */
1532 for (i = 0; i < num_cycles; i++)
1533 cmsis_dap_add_tms_sequence(&tms, 1);
1534 }
1535
1536 static void cmsis_dap_runtest(int num_cycles)
1537 {
1538 tap_state_t saved_end_state = tap_get_end_state();
1539
1540 /* Only do a state_move when we're not already in IDLE. */
1541 if (tap_get_state() != TAP_IDLE) {
1542 cmsis_dap_end_state(TAP_IDLE);
1543 cmsis_dap_state_move();
1544 }
1545 cmsis_dap_stableclocks(num_cycles);
1546
1547 /* Finish in end_state. */
1548 cmsis_dap_end_state(saved_end_state);
1549
1550 if (tap_get_state() != tap_get_end_state())
1551 cmsis_dap_state_move();
1552 }
1553
1554 static void cmsis_dap_execute_runtest(struct jtag_command *cmd)
1555 {
1556 LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles,
1557 cmd->cmd.runtest->end_state);
1558
1559 cmsis_dap_end_state(cmd->cmd.runtest->end_state);
1560 cmsis_dap_runtest(cmd->cmd.runtest->num_cycles);
1561 }
1562
1563 static void cmsis_dap_execute_stableclocks(struct jtag_command *cmd)
1564 {
1565 LOG_DEBUG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles);
1566 cmsis_dap_stableclocks(cmd->cmd.runtest->num_cycles);
1567 }
1568
1569 static void cmsis_dap_execute_tms(struct jtag_command *cmd)
1570 {
1571 LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits);
1572 cmsis_dap_cmd_DAP_SWJ_Sequence(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits);
1573 }
1574
1575 /* TODO: Is there need to call cmsis_dap_flush() for the JTAG_PATHMOVE,
1576 * JTAG_RUNTEST, JTAG_STABLECLOCKS? */
1577 static void cmsis_dap_execute_command(struct jtag_command *cmd)
1578 {
1579 switch (cmd->type) {
1580 case JTAG_SLEEP:
1581 cmsis_dap_flush();
1582 cmsis_dap_execute_sleep(cmd);
1583 break;
1584 case JTAG_TLR_RESET:
1585 cmsis_dap_flush();
1586 cmsis_dap_execute_tlr_reset(cmd);
1587 break;
1588 case JTAG_SCAN:
1589 cmsis_dap_execute_scan(cmd);
1590 break;
1591 case JTAG_PATHMOVE:
1592 cmsis_dap_execute_pathmove(cmd);
1593 break;
1594 case JTAG_RUNTEST:
1595 cmsis_dap_execute_runtest(cmd);
1596 break;
1597 case JTAG_STABLECLOCKS:
1598 cmsis_dap_execute_stableclocks(cmd);
1599 break;
1600 case JTAG_TMS:
1601 cmsis_dap_execute_tms(cmd);
1602 break;
1603 default:
1604 LOG_ERROR("BUG: unknown JTAG command type 0x%X encountered", cmd->type);
1605 exit(-1);
1606 }
1607 }
1608
1609 static int cmsis_dap_execute_queue(void)
1610 {
1611 struct jtag_command *cmd = jtag_command_queue;
1612
1613 while (cmd != NULL) {
1614 cmsis_dap_execute_command(cmd);
1615 cmd = cmd->next;
1616 }
1617
1618 cmsis_dap_flush();
1619
1620 return ERROR_OK;
1621 }
1622
1623 static int cmsis_dap_speed(int speed)
1624 {
1625 if (speed > DAP_MAX_CLOCK)
1626 LOG_INFO("High speed (adapter speed %d) may be limited by adapter firmware.", speed);
1627
1628 if (speed == 0) {
1629 LOG_ERROR("RTCK not supported. Set nonzero \"adapter speed\".");
1630 return ERROR_JTAG_NOT_IMPLEMENTED;
1631 }
1632
1633 return cmsis_dap_cmd_DAP_SWJ_Clock(speed);
1634 }
1635
1636 static int cmsis_dap_speed_div(int speed, int *khz)
1637 {
1638 *khz = speed;
1639 return ERROR_OK;
1640 }
1641
1642 static int cmsis_dap_khz(int khz, int *jtag_speed)
1643 {
1644 *jtag_speed = khz;
1645 return ERROR_OK;
1646 }
1647
1648 COMMAND_HANDLER(cmsis_dap_handle_info_command)
1649 {
1650 if (cmsis_dap_get_version_info() == ERROR_OK)
1651 cmsis_dap_get_status();
1652
1653 return ERROR_OK;
1654 }
1655
1656 COMMAND_HANDLER(cmsis_dap_handle_cmd_command)
1657 {
1658 int retval;
1659 unsigned i;
1660 uint8_t *buffer = cmsis_dap_handle->packet_buffer;
1661
1662 buffer[0] = 0; /* report number */
1663
1664 for (i = 0; i < CMD_ARGC; i++)
1665 buffer[i + 1] = strtoul(CMD_ARGV[i], NULL, 16);
1666
1667 retval = cmsis_dap_usb_xfer(cmsis_dap_handle, CMD_ARGC + 1);
1668
1669 if (retval != ERROR_OK) {
1670 LOG_ERROR("CMSIS-DAP command failed.");
1671 return ERROR_JTAG_DEVICE_ERROR;
1672 }
1673
1674 LOG_INFO("Returned data %02" PRIx8 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8,
1675 buffer[1], buffer[2], buffer[3], buffer[4]);
1676
1677 return ERROR_OK;
1678 }
1679
1680 COMMAND_HANDLER(cmsis_dap_handle_vid_pid_command)
1681 {
1682 if (CMD_ARGC > MAX_USB_IDS * 2) {
1683 LOG_WARNING("ignoring extra IDs in cmsis_dap_vid_pid "
1684 "(maximum is %d pairs)", MAX_USB_IDS);
1685 CMD_ARGC = MAX_USB_IDS * 2;
1686 }
1687 if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
1688 LOG_WARNING("incomplete cmsis_dap_vid_pid configuration directive");
1689 if (CMD_ARGC < 2)
1690 return ERROR_COMMAND_SYNTAX_ERROR;
1691 /* remove the incomplete trailing id */
1692 CMD_ARGC -= 1;
1693 }
1694
1695 unsigned i;
1696 for (i = 0; i < CMD_ARGC; i += 2) {
1697 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], cmsis_dap_vid[i >> 1]);
1698 COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], cmsis_dap_pid[i >> 1]);
1699 }
1700
1701 /*
1702 * Explicitly terminate, in case there are multiples instances of
1703 * cmsis_dap_vid_pid.
1704 */
1705 cmsis_dap_vid[i >> 1] = cmsis_dap_pid[i >> 1] = 0;
1706
1707 return ERROR_OK;
1708 }
1709
1710 COMMAND_HANDLER(cmsis_dap_handle_serial_command)
1711 {
1712 if (CMD_ARGC == 1) {
1713 size_t len = mbstowcs(NULL, CMD_ARGV[0], 0);
1714 cmsis_dap_serial = calloc(len + 1, sizeof(wchar_t));
1715 if (cmsis_dap_serial == NULL) {
1716 LOG_ERROR("unable to allocate memory");
1717 return ERROR_OK;
1718 }
1719 if (mbstowcs(cmsis_dap_serial, CMD_ARGV[0], len + 1) == (size_t)-1) {
1720 free(cmsis_dap_serial);
1721 cmsis_dap_serial = NULL;
1722 LOG_ERROR("unable to convert serial");
1723 }
1724 } else {
1725 LOG_ERROR("expected exactly one argument to cmsis_dap_serial <serial-number>");
1726 }
1727
1728 return ERROR_OK;
1729 }
1730
1731 static const struct command_registration cmsis_dap_subcommand_handlers[] = {
1732 {
1733 .name = "info",
1734 .handler = &cmsis_dap_handle_info_command,
1735 .mode = COMMAND_EXEC,
1736 .usage = "",
1737 .help = "show cmsis-dap info",
1738 },
1739 {
1740 .name = "cmd",
1741 .handler = &cmsis_dap_handle_cmd_command,
1742 .mode = COMMAND_EXEC,
1743 .usage = "",
1744 .help = "issue cmsis-dap command",
1745 },
1746 COMMAND_REGISTRATION_DONE
1747 };
1748
1749 static const struct command_registration cmsis_dap_command_handlers[] = {
1750 {
1751 .name = "cmsis-dap",
1752 .mode = COMMAND_ANY,
1753 .help = "perform CMSIS-DAP management",
1754 .usage = "<cmd>",
1755 .chain = cmsis_dap_subcommand_handlers,
1756 },
1757 {
1758 .name = "cmsis_dap_vid_pid",
1759 .handler = &cmsis_dap_handle_vid_pid_command,
1760 .mode = COMMAND_CONFIG,
1761 .help = "the vendor ID and product ID of the CMSIS-DAP device",
1762 .usage = "(vid pid)* ",
1763 },
1764 {
1765 .name = "cmsis_dap_serial",
1766 .handler = &cmsis_dap_handle_serial_command,
1767 .mode = COMMAND_CONFIG,
1768 .help = "set the serial number of the adapter",
1769 .usage = "serial_string",
1770 },
1771 COMMAND_REGISTRATION_DONE
1772 };
1773
1774 static const struct swd_driver cmsis_dap_swd_driver = {
1775 .init = cmsis_dap_swd_init,
1776 .switch_seq = cmsis_dap_swd_switch_seq,
1777 .read_reg = cmsis_dap_swd_read_reg,
1778 .write_reg = cmsis_dap_swd_write_reg,
1779 .run = cmsis_dap_swd_run_queue,
1780 };
1781
1782 static const char * const cmsis_dap_transport[] = { "swd", "jtag", NULL };
1783
1784 static struct jtag_interface cmsis_dap_interface = {
1785 .supported = DEBUG_CAP_TMS_SEQ,
1786 .execute_queue = cmsis_dap_execute_queue,
1787 };
1788
1789 struct adapter_driver cmsis_dap_adapter_driver = {
1790 .name = "cmsis-dap",
1791 .transports = cmsis_dap_transport,
1792 .commands = cmsis_dap_command_handlers,
1793
1794 .init = cmsis_dap_init,
1795 .quit = cmsis_dap_quit,
1796 .reset = cmsis_dap_reset,
1797 .speed = cmsis_dap_speed,
1798 .khz = cmsis_dap_khz,
1799 .speed_div = cmsis_dap_speed_div,
1800
1801 .jtag_ops = &cmsis_dap_interface,
1802 .swd_ops = &cmsis_dap_swd_driver,
1803 };

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)