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

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)