OpenOCD
cmsis_dap.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2021 by Adrian Negreanu *
5  * groleo@gmail.com *
6  * *
7  * Copyright (C) 2018 by MickaĆ«l Thomas *
8  * mickael9@gmail.com *
9  * *
10  * Copyright (C) 2016 by Maksym Hilliaka *
11  * oter@frozen-team.com *
12  * *
13  * Copyright (C) 2016 by Phillip Pearson *
14  * pp@myelin.co.nz *
15  * *
16  * Copyright (C) 2014 by Paul Fertser *
17  * fercerpav@gmail.com *
18  * *
19  * Copyright (C) 2013 by mike brown *
20  * mike@theshedworks.org.uk *
21  * *
22  * Copyright (C) 2013 by Spencer Oliver *
23  * spen@spen-soft.co.uk *
24  ***************************************************************************/
25 
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include <transport/transport.h>
31 #include "helper/replacements.h"
32 #include <jtag/adapter.h>
33 #include <jtag/swd.h>
34 #include <jtag/interface.h>
35 #include <jtag/commands.h>
36 #include <jtag/tcl.h>
37 #include <target/cortex_m.h>
38 
39 #include "cmsis_dap.h"
40 #include "libusb_helper.h"
41 
42 static const struct cmsis_dap_backend *const cmsis_dap_backends[] = {
43 #if BUILD_CMSIS_DAP_USB == 1
45 #endif
46 
47 #if BUILD_CMSIS_DAP_HID == 1
49 #endif
50 };
51 
52 /* USB Config */
53 
54 /* Known vid/pid pairs:
55  * VID 0xc251: Keil Software
56  * PID 0xf001: LPC-Link-II CMSIS_DAP
57  * PID 0xf002: OPEN-SDA CMSIS_DAP (Freedom Board)
58  * PID 0x2722: Keil ULINK2 CMSIS-DAP
59  * PID 0x2750: Keil ULINKplus CMSIS-DAP
60  *
61  * VID 0x0d28: mbed Software
62  * PID 0x0204: MBED CMSIS-DAP
63  */
64 
65 #define MAX_USB_IDS 8
66 /* vid = pid = 0 marks the end of the list */
67 static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 };
68 static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 };
69 static int cmsis_dap_backend = -1;
70 static bool swd_mode;
71 
72 /* CMSIS-DAP General Commands */
73 #define CMD_DAP_INFO 0x00
74 #define CMD_DAP_LED 0x01
75 #define CMD_DAP_CONNECT 0x02
76 #define CMD_DAP_DISCONNECT 0x03
77 #define CMD_DAP_WRITE_ABORT 0x08
78 #define CMD_DAP_DELAY 0x09
79 #define CMD_DAP_RESET_TARGET 0x0A
80 
81 /* CMD_INFO */
82 #define INFO_ID_VENDOR 0x01 /* string */
83 #define INFO_ID_PRODUCT 0x02 /* string */
84 #define INFO_ID_SERNUM 0x03 /* string */
85 #define INFO_ID_FW_VER 0x04 /* string */
86 #define INFO_ID_TD_VEND 0x05 /* string */
87 #define INFO_ID_TD_NAME 0x06 /* string */
88 #define INFO_ID_CAPS 0xf0 /* byte */
89 #define INFO_ID_PKT_CNT 0xfe /* byte */
90 #define INFO_ID_PKT_SZ 0xff /* short */
91 #define INFO_ID_SWO_BUF_SZ 0xfd /* word */
92 
93 #define INFO_CAPS_SWD BIT(0)
94 #define INFO_CAPS_JTAG BIT(1)
95 #define INFO_CAPS_SWO_UART BIT(2)
96 #define INFO_CAPS_SWO_MANCHESTER BIT(3)
97 #define INFO_CAPS_ATOMIC_CMDS BIT(4)
98 #define INFO_CAPS_TEST_DOMAIN_TIMER BIT(5)
99 #define INFO_CAPS_SWO_STREAMING_TRACE BIT(6)
100 #define INFO_CAPS_UART_PORT BIT(7)
101 #define INFO_CAPS_USB_COM_PORT BIT(8)
102 #define INFO_CAPS__NUM_CAPS 9
103 
104 /* CMD_LED */
105 #define LED_ID_CONNECT 0x00
106 #define LED_ID_RUN 0x01
107 
108 #define LED_OFF 0x00
109 #define LED_ON 0x01
110 
111 /* CMD_CONNECT */
112 #define CONNECT_DEFAULT 0x00
113 #define CONNECT_SWD 0x01
114 #define CONNECT_JTAG 0x02
115 
116 /* CMSIS-DAP Common SWD/JTAG Commands */
117 #define CMD_DAP_DELAY 0x09
118 #define CMD_DAP_SWJ_PINS 0x10
119 #define CMD_DAP_SWJ_CLOCK 0x11
120 #define CMD_DAP_SWJ_SEQ 0x12
121 
122 /*
123  * PINS
124  * Bit 0: SWCLK/TCK
125  * Bit 1: SWDIO/TMS
126  * Bit 2: TDI
127  * Bit 3: TDO
128  * Bit 5: nTRST
129  * Bit 7: nRESET
130  */
131 
132 #define SWJ_PIN_TCK (1<<0)
133 #define SWJ_PIN_TMS (1<<1)
134 #define SWJ_PIN_TDI (1<<2)
135 #define SWJ_PIN_TDO (1<<3)
136 #define SWJ_PIN_TRST (1<<5)
137 #define SWJ_PIN_SRST (1<<7)
138 
139 /* CMSIS-DAP SWD Commands */
140 #define CMD_DAP_SWD_CONFIGURE 0x13
141 #define CMD_DAP_SWD_SEQUENCE 0x1D
142 
143 /* CMSIS-DAP JTAG Commands */
144 #define CMD_DAP_JTAG_SEQ 0x14
145 #define CMD_DAP_JTAG_CONFIGURE 0x15
146 #define CMD_DAP_JTAG_IDCODE 0x16
147 
148 /* CMSIS-DAP JTAG sequence info masks */
149 /* Number of bits to clock through (0 means 64) */
150 #define DAP_JTAG_SEQ_TCK 0x3F
151 /* TMS will be set during the sequence if this bit is set */
152 #define DAP_JTAG_SEQ_TMS 0x40
153 /* TDO output will be captured if this bit is set */
154 #define DAP_JTAG_SEQ_TDO 0x80
155 
156 
157 /* CMSIS-DAP Transfer Commands */
158 #define CMD_DAP_TFER_CONFIGURE 0x04
159 #define CMD_DAP_TFER 0x05
160 #define CMD_DAP_TFER_BLOCK 0x06
161 #define CMD_DAP_TFER_ABORT 0x07
162 
163 /* DAP Status Code */
164 #define DAP_OK 0
165 #define DAP_ERROR 0xFF
166 
167 /* CMSIS-DAP SWO Commands */
168 #define CMD_DAP_SWO_TRANSPORT 0x17
169 #define CMD_DAP_SWO_MODE 0x18
170 #define CMD_DAP_SWO_BAUDRATE 0x19
171 #define CMD_DAP_SWO_CONTROL 0x1A
172 #define CMD_DAP_SWO_STATUS 0x1B
173 #define CMD_DAP_SWO_DATA 0x1C
174 #define CMD_DAP_SWO_EX_STATUS 0x1E
175 
176 /* SWO transport mode for reading trace data */
177 #define DAP_SWO_TRANSPORT_NONE 0
178 #define DAP_SWO_TRANSPORT_DATA 1
179 #define DAP_SWO_TRANSPORT_WINUSB 2
180 
181 /* SWO trace capture mode */
182 #define DAP_SWO_MODE_OFF 0
183 #define DAP_SWO_MODE_UART 1
184 #define DAP_SWO_MODE_MANCHESTER 2
185 
186 /* SWO trace data capture */
187 #define DAP_SWO_CONTROL_STOP 0
188 #define DAP_SWO_CONTROL_START 1
189 
190 /* SWO trace status */
191 #define DAP_SWO_STATUS_CAPTURE_INACTIVE 0
192 #define DAP_SWO_STATUS_CAPTURE_ACTIVE 1
193 #define DAP_SWO_STATUS_CAPTURE_MASK BIT(0)
194 #define DAP_SWO_STATUS_STREAM_ERROR_MASK BIT(6)
195 #define DAP_SWO_STATUS_BUFFER_OVERRUN_MASK BIT(7)
196 
197 /* CMSIS-DAP Vendor Commands
198  * None as yet... */
199 
200 static const char * const info_caps_str[INFO_CAPS__NUM_CAPS] = {
201  "SWD supported",
202  "JTAG supported",
203  "SWO-UART supported",
204  "SWO-MANCHESTER supported",
205  "Atomic commands supported",
206  "Test domain timer supported",
207  "SWO streaming trace supported",
208  "UART communication port supported",
209  "UART via USB COM port supported",
210 };
211 
213  uint8_t cmd;
214  uint32_t data;
215  void *buffer;
216 };
217 
221 };
222 
223 struct pending_scan_result {
225  unsigned first;
227  unsigned length;
229  uint8_t *buffer;
231  unsigned buffer_offset;
232 };
233 
234 /* Up to MIN(packet_count, MAX_PENDING_REQUESTS) requests may be issued
235  * until the first response arrives */
236 #define MAX_PENDING_REQUESTS 3
237 
238 /* Pending requests are organized as a FIFO - circular buffer */
239 /* Each block in FIFO can contain up to pending_queue_len transfers */
240 static int pending_queue_len;
244 
245 /* pointers to buffers that will receive jtag scan results on the next flush */
246 #define MAX_PENDING_SCAN_RESULTS 256
249 
250 /* queued JTAG sequences that will be executed on the next flush */
251 #define QUEUED_SEQ_BUF_LEN (cmsis_dap_handle->packet_size - 3)
252 static int queued_seq_count;
255 static uint8_t queued_seq_buf[1024]; /* TODO: make dynamic / move into cmsis object */
256 
257 static int queued_retval;
258 
260 
262 
263 
264 static int cmsis_dap_quit(void);
265 
266 static int cmsis_dap_open(void)
267 {
268  const struct cmsis_dap_backend *backend = NULL;
269 
270  struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap));
271  if (!dap) {
272  LOG_ERROR("unable to allocate memory");
273  return ERROR_FAIL;
274  }
275 
276  if (cmsis_dap_backend >= 0) {
277  /* Use forced backend */
280  backend = NULL;
281  } else {
282  /* Try all backends */
283  for (unsigned int i = 0; i < ARRAY_SIZE(cmsis_dap_backends); i++) {
286  break;
287  else
288  backend = NULL;
289  }
290  }
291 
292  if (!backend) {
293  LOG_ERROR("unable to find a matching CMSIS-DAP device");
294  free(dap);
295  return ERROR_FAIL;
296  }
297 
298  dap->backend = backend;
299 
300  cmsis_dap_handle = dap;
301 
302  return ERROR_OK;
303 }
304 
305 static void cmsis_dap_close(struct cmsis_dap *dap)
306 {
307  if (dap->backend) {
308  dap->backend->close(dap);
309  dap->backend = NULL;
310  }
311 
313  free(cmsis_dap_handle);
315 
316  for (int i = 0; i < MAX_PENDING_REQUESTS; i++) {
317  free(pending_fifo[i].transfers);
319  }
320 }
321 
322 static void cmsis_dap_flush_read(struct cmsis_dap *dap)
323 {
324  unsigned int i;
325  /* Some CMSIS-DAP adapters keep buffered packets over
326  * USB close/open so we need to flush up to 64 old packets
327  * to be sure all buffers are empty */
328  for (i = 0; i < 64; i++) {
329  int retval = dap->backend->read(dap, 10);
330  if (retval == ERROR_TIMEOUT_REACHED)
331  break;
332  }
333  if (i)
334  LOG_DEBUG("Flushed %u packets", i);
335 }
336 
337 /* Send a message and receive the reply */
338 static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen)
339 {
341  LOG_ERROR("pending %d blocks, flushing", pending_fifo_block_count);
342  while (pending_fifo_block_count) {
343  dap->backend->read(dap, 10);
345  }
348  }
349 
350  uint8_t current_cmd = cmsis_dap_handle->command[0];
351  int retval = dap->backend->write(dap, txlen, LIBUSB_TIMEOUT_MS);
352  if (retval < 0)
353  return retval;
354 
355  /* get reply */
356  retval = dap->backend->read(dap, LIBUSB_TIMEOUT_MS);
357  if (retval < 0)
358  return retval;
359 
360  uint8_t *resp = cmsis_dap_handle->response;
361  if (resp[0] == DAP_ERROR) {
362  LOG_ERROR("CMSIS-DAP command 0x%" PRIx8 " not implemented", current_cmd);
363  return ERROR_NOT_IMPLEMENTED;
364  }
365 
366  if (resp[0] != current_cmd) {
367  LOG_ERROR("CMSIS-DAP command mismatch. Sent 0x%" PRIx8
368  " received 0x%" PRIx8, current_cmd, resp[0]);
369 
371  return ERROR_FAIL;
372  }
373 
374  return ERROR_OK;
375 }
376 
377 static int cmsis_dap_cmd_dap_swj_pins(uint8_t pins, uint8_t mask, uint32_t delay, uint8_t *input)
378 {
379  uint8_t *command = cmsis_dap_handle->command;
380 
382  command[1] = pins;
383  command[2] = mask;
384  h_u32_to_le(&command[3], delay);
385 
386  int retval = cmsis_dap_xfer(cmsis_dap_handle, 7);
387  if (retval != ERROR_OK) {
388  LOG_ERROR("CMSIS-DAP command CMD_DAP_SWJ_PINS failed.");
390  }
391 
392  if (input)
393  *input = cmsis_dap_handle->response[1];
394 
395  return ERROR_OK;
396 }
397 
398 static int cmsis_dap_cmd_dap_swj_clock(uint32_t swj_clock)
399 {
400  uint8_t *command = cmsis_dap_handle->command;
401 
402  /* set clock in Hz */
403  swj_clock *= 1000;
404 
406  h_u32_to_le(&command[1], swj_clock);
407 
408  int retval = cmsis_dap_xfer(cmsis_dap_handle, 5);
409  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
410  LOG_ERROR("CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed.");
412  }
413 
414  return ERROR_OK;
415 }
416 
417 /* clock a sequence of bits out on TMS, to change JTAG states */
418 static int cmsis_dap_cmd_dap_swj_sequence(uint8_t s_len, const uint8_t *sequence)
419 {
420  uint8_t *command = cmsis_dap_handle->command;
421 
422 #ifdef CMSIS_DAP_JTAG_DEBUG
423  LOG_DEBUG("cmsis-dap TMS sequence: len=%d", s_len);
424  for (int i = 0; i < DIV_ROUND_UP(s_len, 8); ++i)
425  printf("%02X ", sequence[i]);
426 
427  printf("\n");
428 #endif
429 
431  command[1] = s_len;
432  bit_copy(&command[2], 0, sequence, 0, s_len);
433 
434  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2 + DIV_ROUND_UP(s_len, 8));
435  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK)
436  return ERROR_FAIL;
437 
438  return ERROR_OK;
439 }
440 
441 static int cmsis_dap_cmd_dap_info(uint8_t info, uint8_t **data)
442 {
443  uint8_t *command = cmsis_dap_handle->command;
444 
445  command[0] = CMD_DAP_INFO;
446  command[1] = info;
447 
448  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2);
449  if (retval != ERROR_OK) {
450  LOG_ERROR("CMSIS-DAP command CMD_INFO failed.");
452  }
453 
454  *data = &cmsis_dap_handle->response[1];
455 
456  return ERROR_OK;
457 }
458 
459 static int cmsis_dap_cmd_dap_led(uint8_t led, uint8_t state)
460 {
461  uint8_t *command = cmsis_dap_handle->command;
462 
463  command[0] = CMD_DAP_LED;
464  command[1] = led;
465  command[2] = state;
466 
467  int retval = cmsis_dap_xfer(cmsis_dap_handle, 3);
468  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
469  LOG_ERROR("CMSIS-DAP command CMD_LED failed.");
471  }
472 
473  return ERROR_OK;
474 }
475 
476 static int cmsis_dap_cmd_dap_connect(uint8_t mode)
477 {
478  uint8_t *command = cmsis_dap_handle->command;
479 
481  command[1] = mode;
482 
483  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2);
484  if (retval != ERROR_OK) {
485  LOG_ERROR("CMSIS-DAP command CMD_CONNECT failed.");
487  }
488 
489  if (cmsis_dap_handle->response[1] != mode) {
490  LOG_ERROR("CMSIS-DAP failed to connect in mode (%d)", mode);
492  }
493 
494  return ERROR_OK;
495 }
496 
498 {
499  uint8_t *command = cmsis_dap_handle->command;
500 
502 
503  int retval = cmsis_dap_xfer(cmsis_dap_handle, 1);
504  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
505  LOG_ERROR("CMSIS-DAP command CMD_DISCONNECT failed.");
507  }
508 
509  return ERROR_OK;
510 }
511 
512 static int cmsis_dap_cmd_dap_tfer_configure(uint8_t idle, uint16_t retry_count, uint16_t match_retry)
513 {
514  uint8_t *command = cmsis_dap_handle->command;
515 
517  command[1] = idle;
518  h_u16_to_le(&command[2], retry_count);
519  h_u16_to_le(&command[4], match_retry);
520 
521  int retval = cmsis_dap_xfer(cmsis_dap_handle, 6);
522  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
523  LOG_ERROR("CMSIS-DAP command CMD_TFER_Configure failed.");
525  }
526 
527  return ERROR_OK;
528 }
529 
530 static int cmsis_dap_cmd_dap_swd_configure(uint8_t cfg)
531 {
532  uint8_t *command = cmsis_dap_handle->command;
533 
535  command[1] = cfg;
536 
537  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2);
538  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
539  LOG_ERROR("CMSIS-DAP command CMD_SWD_Configure failed.");
541  }
542 
543  return ERROR_OK;
544 }
545 
546 #if 0
547 static int cmsis_dap_cmd_dap_delay(uint16_t delay_us)
548 {
549  uint8_t *command = cmsis_dap_handle->command;
550 
551  command[0] = CMD_DAP_DELAY;
553 
554  int retval = cmsis_dap_xfer(cmsis_dap_handle, 3);
555  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
556  LOG_ERROR("CMSIS-DAP command CMD_Delay failed.");
558  }
559 
560  return ERROR_OK;
561 }
562 #endif
563 
564 static int cmsis_dap_metacmd_targetsel(uint32_t instance_id)
565 {
566  uint8_t *command = cmsis_dap_handle->command;
567  const uint32_t SEQ_RD = 0x80, SEQ_WR = 0x00;
568 
569  /* SWD multi-drop requires a transfer ala CMD_DAP_TFER,
570  but with no expectation of an SWD ACK response. In
571  CMSIS-DAP v1.20 and v2.00, CMD_DAP_SWD_SEQUENCE was
572  added to allow this special sequence to be generated.
573  The purpose of this operation is to select the target
574  corresponding to the instance_id that is written */
575 
576  LOG_DEBUG_IO("DP write reg TARGETSEL %" PRIx32, instance_id);
577 
578  size_t idx = 0;
579  command[idx++] = CMD_DAP_SWD_SEQUENCE;
580  command[idx++] = 3; /* sequence count */
581 
582  /* sequence 0: packet request for TARGETSEL */
583  command[idx++] = SEQ_WR | 8;
584  command[idx++] = SWD_CMD_START | swd_cmd(false, false, DP_TARGETSEL) | SWD_CMD_STOP | SWD_CMD_PARK;
585 
586  /* sequence 1: read Trn ACK Trn, no expectation for target to ACK */
587  command[idx++] = SEQ_RD | 5;
588 
589  /* sequence 2: WDATA plus parity */
590  command[idx++] = SEQ_WR | (32 + 1);
591  h_u32_to_le(command + idx, instance_id);
592  idx += 4;
593  command[idx++] = parity_u32(instance_id);
594 
595  int retval = cmsis_dap_xfer(cmsis_dap_handle, idx);
596  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
597  LOG_ERROR("CMSIS-DAP command SWD_Sequence failed.");
599  }
600 
601  return ERROR_OK;
602 }
603 
610 {
611  uint8_t *command = cmsis_dap_handle->command;
612 
614  command[1] = transport;
615 
616  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2);
617  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
618  LOG_ERROR("CMSIS-DAP: command CMD_SWO_Transport(%d) failed.", transport);
620  }
621 
622  return ERROR_OK;
623 }
624 
629 static int cmsis_dap_cmd_dap_swo_mode(uint8_t mode)
630 {
631  uint8_t *command = cmsis_dap_handle->command;
632 
634  command[1] = mode;
635 
636  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2);
637  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
638  LOG_ERROR("CMSIS-DAP: command CMD_SWO_Mode(%d) failed.", mode);
640  }
641 
642  return ERROR_OK;
643 }
644 
655  uint32_t in_baudrate,
656  uint32_t *dev_baudrate)
657 {
658  uint8_t *command = cmsis_dap_handle->command;
659 
661  h_u32_to_le(&command[1], in_baudrate);
662 
663  int retval = cmsis_dap_xfer(cmsis_dap_handle, 5);
664  uint32_t rvbr = le_to_h_u32(&cmsis_dap_handle->response[1]);
665  if (retval != ERROR_OK || rvbr == 0) {
666  LOG_ERROR("CMSIS-DAP: command CMD_SWO_Baudrate(%u) -> %u failed.", in_baudrate, rvbr);
667  if (dev_baudrate)
668  *dev_baudrate = 0;
670  }
671 
672  if (dev_baudrate)
673  *dev_baudrate = rvbr;
674 
675  return ERROR_OK;
676 }
677 
684 static int cmsis_dap_cmd_dap_swo_control(uint8_t control)
685 {
686  uint8_t *command = cmsis_dap_handle->command;
687 
689  command[1] = control;
690 
691  int retval = cmsis_dap_xfer(cmsis_dap_handle, 2);
692  if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) {
693  LOG_ERROR("CMSIS-DAP: command CMD_SWO_Control(%d) failed.", control);
695  }
696 
697  return ERROR_OK;
698 }
699 
709  uint8_t *trace_status,
710  size_t *trace_count)
711 {
712  uint8_t *command = cmsis_dap_handle->command;
713 
715 
716  int retval = cmsis_dap_xfer(cmsis_dap_handle, 1);
717  if (retval != ERROR_OK) {
718  LOG_ERROR("CMSIS-DAP: command CMD_SWO_Status failed.");
720  }
721 
722  if (trace_status)
724  if (trace_count)
725  *trace_count = le_to_h_u32(&cmsis_dap_handle->response[2]);
726 
727  return ERROR_OK;
728 }
729 
738  size_t max_trace_count,
739  uint8_t *trace_status,
740  size_t *trace_count,
741  uint8_t *data)
742 {
743  uint8_t *command = cmsis_dap_handle->command;
744 
746  h_u16_to_le(&command[1], max_trace_count);
747 
748  int retval = cmsis_dap_xfer(cmsis_dap_handle, 3);
749  if (retval != ERROR_OK) {
750  LOG_ERROR("CMSIS-DAP: command CMD_SWO_Data failed.");
752  }
753 
755  *trace_count = le_to_h_u16(&cmsis_dap_handle->response[2]);
756 
757  if (*trace_count > 0)
758  memcpy(data, &cmsis_dap_handle->response[4], *trace_count);
759 
760  return ERROR_OK;
761 }
762 
764 {
765  uint8_t *command = cmsis_dap_handle->command;
767 
768  LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %d", block->transfer_count, pending_fifo_put_idx);
769 
770  if (queued_retval != ERROR_OK) {
771  LOG_DEBUG("Skipping due to previous errors: %d", queued_retval);
772  goto skip;
773  }
774 
775  if (block->transfer_count == 0)
776  goto skip;
777 
778  command[0] = CMD_DAP_TFER;
779  command[1] = 0x00; /* DAP Index */
780  command[2] = block->transfer_count;
781  size_t idx = 3;
782 
783  for (int i = 0; i < block->transfer_count; i++) {
784  struct pending_transfer_result *transfer = &(block->transfers[i]);
785  uint8_t cmd = transfer->cmd;
786  uint32_t data = transfer->data;
787 
788  LOG_DEBUG_IO("%s %s reg %x %" PRIx32,
789  cmd & SWD_CMD_APNDP ? "AP" : "DP",
790  cmd & SWD_CMD_RNW ? "read" : "write",
791  (cmd & SWD_CMD_A32) >> 1, data);
792 
793  /* When proper WAIT handling is implemented in the
794  * common SWD framework, this kludge can be
795  * removed. However, this might lead to minor
796  * performance degradation as the adapter wouldn't be
797  * able to automatically retry anything (because ARM
798  * has forgotten to implement sticky error flags
799  * clearing). See also comments regarding
800  * cmsis_dap_cmd_dap_tfer_configure() and
801  * cmsis_dap_cmd_dap_swd_configure() in
802  * cmsis_dap_init().
803  */
804  if (!(cmd & SWD_CMD_RNW) &&
805  !(cmd & SWD_CMD_APNDP) &&
806  (cmd & SWD_CMD_A32) >> 1 == DP_CTRL_STAT &&
807  (data & CORUNDETECT)) {
808  LOG_DEBUG("refusing to enable sticky overrun detection");
809  data &= ~CORUNDETECT;
810  }
811 
812  command[idx++] = (cmd >> 1) & 0x0f;
813  if (!(cmd & SWD_CMD_RNW)) {
814  h_u32_to_le(&command[idx], data);
815  idx += 4;
816  }
817  }
818 
819  int retval = dap->backend->write(dap, idx, LIBUSB_TIMEOUT_MS);
820  if (retval < 0) {
821  queued_retval = retval;
822  goto skip;
823  } else {
825  }
826 
830  LOG_ERROR("too much pending writes %d", pending_fifo_block_count);
831 
832  return;
833 
834 skip:
835  block->transfer_count = 0;
836 }
837 
838 static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
839 {
841 
842  if (pending_fifo_block_count == 0)
843  LOG_ERROR("no pending write");
844 
845  /* get reply */
846  int retval = dap->backend->read(dap, timeout_ms);
847  if (retval == ERROR_TIMEOUT_REACHED && timeout_ms < LIBUSB_TIMEOUT_MS)
848  return;
849 
850  if (retval <= 0) {
851  LOG_DEBUG("error reading data");
853  goto skip;
854  }
855 
856  uint8_t *resp = dap->response;
857  if (resp[0] != CMD_DAP_TFER) {
858  LOG_ERROR("CMSIS-DAP command mismatch. Expected 0x%x received 0x%" PRIx8,
859  CMD_DAP_TFER, resp[0]);
861  goto skip;
862  }
863 
864  uint8_t transfer_count = resp[1];
865  uint8_t ack = resp[2] & 0x07;
866  if (resp[2] & 0x08) {
867  LOG_DEBUG("CMSIS-DAP Protocol Error @ %d (wrong parity)", transfer_count);
869  goto skip;
870  }
871  if (ack != SWD_ACK_OK) {
872  LOG_DEBUG("SWD ack not OK @ %d %s", transfer_count,
873  ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK");
875  /* TODO: use results of transfers completed before the error occurred? */
876  goto skip;
877  }
878 
879  if (block->transfer_count != transfer_count)
880  LOG_ERROR("CMSIS-DAP transfer count mismatch: expected %d, got %d",
882 
883  LOG_DEBUG_IO("Received results of %d queued transactions FIFO index %d",
885  size_t idx = 3;
886  for (int i = 0; i < transfer_count; i++) {
887  struct pending_transfer_result *transfer = &(block->transfers[i]);
888  if (transfer->cmd & SWD_CMD_RNW) {
889  static uint32_t last_read;
890  uint32_t data = le_to_h_u32(&resp[idx]);
891  uint32_t tmp = data;
892  idx += 4;
893 
894  LOG_DEBUG_IO("Read result: %" PRIx32, data);
895 
896  /* Imitate posted AP reads */
897  if ((transfer->cmd & SWD_CMD_APNDP) ||
898  ((transfer->cmd & SWD_CMD_A32) >> 1 == DP_RDBUFF)) {
899  tmp = last_read;
900  last_read = data;
901  }
902 
903  if (transfer->buffer)
904  *(uint32_t *)(transfer->buffer) = tmp;
905  }
906  }
907 
908 skip:
909  block->transfer_count = 0;
912 }
913 
914 static int cmsis_dap_swd_run_queue(void)
915 {
918 
920 
923 
926 
927  int retval = queued_retval;
929 
930  return retval;
931 }
932 
933 static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
934 {
935  bool targetsel_cmd = swd_cmd(false, false, DP_TARGETSEL) == cmd;
936 
938  || targetsel_cmd) {
941 
942  /* Not enough room in the queue. Run the queue. */
944 
947  }
948 
949  if (queued_retval != ERROR_OK)
950  return;
951 
952  if (targetsel_cmd) {
954  return;
955  }
956 
958  struct pending_transfer_result *transfer = &(block->transfers[block->transfer_count]);
959  transfer->data = data;
960  transfer->cmd = cmd;
961  if (cmd & SWD_CMD_RNW) {
962  /* Queue a read transaction */
963  transfer->buffer = dst;
964  }
965  block->transfer_count++;
966 }
967 
968 static void cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
969 {
970  assert(!(cmd & SWD_CMD_RNW));
972 }
973 
974 static void cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
975 {
976  assert(cmd & SWD_CMD_RNW);
977  cmsis_dap_swd_queue_cmd(cmd, value, 0);
978 }
979 
981 {
982  uint8_t *data;
983 
985  if (retval != ERROR_OK)
986  return retval;
987 
988  if (data[0]) /* strlen */
989  LOG_INFO("CMSIS-DAP: Serial# = %s", &data[1]);
990 
991  return ERROR_OK;
992 }
993 
995 {
996  uint8_t *data;
997 
998  /* INFO_ID_FW_VER - string */
1000  if (retval != ERROR_OK)
1001  return retval;
1002 
1003  if (data[0]) /* strlen */
1004  LOG_INFO("CMSIS-DAP: FW Version = %s", &data[1]);
1005 
1006  return ERROR_OK;
1007 }
1008 
1009 static int cmsis_dap_get_caps_info(void)
1010 {
1011  uint8_t *data;
1012 
1013  /* INFO_ID_CAPS - byte */
1014  int retval = cmsis_dap_cmd_dap_info(INFO_ID_CAPS, &data);
1015  if (retval != ERROR_OK)
1016  return retval;
1017 
1018  if (data[0] == 1 || data[0] == 2) {
1019  uint16_t caps = data[1];
1020  if (data[0] == 2)
1021  caps |= (uint16_t)data[2] << 8;
1022 
1024 
1025  for (int i = 0; i < INFO_CAPS__NUM_CAPS; ++i) {
1026  if (caps & BIT(i))
1027  LOG_INFO("CMSIS-DAP: %s", info_caps_str[i]);
1028  }
1029  }
1030 
1031  return ERROR_OK;
1032 }
1033 
1034 static int cmsis_dap_get_swo_buf_sz(uint32_t *swo_buf_sz)
1035 {
1036  uint8_t *data;
1037 
1038  /* INFO_ID_SWO_BUF_SZ - word */
1040  if (retval != ERROR_OK)
1041  return retval;
1042 
1043  if (data[0] != 4)
1044  return ERROR_FAIL;
1045 
1046  *swo_buf_sz = le_to_h_u32(&data[1]);
1047 
1048  LOG_INFO("CMSIS-DAP: SWO Trace Buffer Size = %u bytes", *swo_buf_sz);
1049 
1050  return ERROR_OK;
1051 }
1052 
1053 static int cmsis_dap_get_status(void)
1054 {
1055  uint8_t d;
1056 
1057  int retval = cmsis_dap_cmd_dap_swj_pins(0, 0, 0, &d);
1058 
1059  if (retval == ERROR_OK) {
1060  LOG_INFO("SWCLK/TCK = %d SWDIO/TMS = %d TDI = %d TDO = %d nTRST = %d nRESET = %d",
1061  (d & SWJ_PIN_TCK) ? 1 : 0,
1062  (d & SWJ_PIN_TMS) ? 1 : 0,
1063  (d & SWJ_PIN_TDI) ? 1 : 0,
1064  (d & SWJ_PIN_TDO) ? 1 : 0,
1065  (d & SWJ_PIN_TRST) ? 1 : 0,
1066  (d & SWJ_PIN_SRST) ? 1 : 0);
1067  }
1068 
1069  return retval;
1070 }
1071 
1073 {
1074  const uint8_t *s;
1075  unsigned int s_len;
1076  int retval;
1077 
1079  /* Following workaround deasserts reset on most adapters.
1080  * Do not reconnect if a reset line is active!
1081  * Reconnecting would break connecting under reset. */
1082 
1083  /* First disconnect before connecting, Atmel EDBG needs it for SAMD/R/L/C */
1085 
1086  /* When we are reconnecting, DAP_Connect needs to be rerun, at
1087  * least on Keil ULINK-ME */
1089  if (retval != ERROR_OK)
1090  return retval;
1091  }
1092 
1093  switch (seq) {
1094  case LINE_RESET:
1095  LOG_DEBUG_IO("SWD line reset");
1096  s = swd_seq_line_reset;
1097  s_len = swd_seq_line_reset_len;
1098  break;
1099  case JTAG_TO_SWD:
1100  LOG_DEBUG("JTAG-to-SWD");
1101  s = swd_seq_jtag_to_swd;
1102  s_len = swd_seq_jtag_to_swd_len;
1103  break;
1104  case JTAG_TO_DORMANT:
1105  LOG_DEBUG("JTAG-to-DORMANT");
1108  break;
1109  case SWD_TO_JTAG:
1110  LOG_DEBUG("SWD-to-JTAG");
1111  s = swd_seq_swd_to_jtag;
1112  s_len = swd_seq_swd_to_jtag_len;
1113  break;
1114  case SWD_TO_DORMANT:
1115  LOG_DEBUG("SWD-to-DORMANT");
1118  break;
1119  case DORMANT_TO_SWD:
1120  LOG_DEBUG("DORMANT-to-SWD");
1123  break;
1124  case DORMANT_TO_JTAG:
1125  LOG_DEBUG("DORMANT-to-JTAG");
1128  break;
1129  default:
1130  LOG_ERROR("Sequence %d not supported", seq);
1131  return ERROR_FAIL;
1132  }
1133 
1134  retval = cmsis_dap_cmd_dap_swj_sequence(s_len, s);
1135  if (retval != ERROR_OK)
1136  return retval;
1137 
1138  /* Atmel EDBG needs renew clock setting after SWJ_Sequence
1139  * otherwise default frequency is used */
1141 }
1142 
1143 static int cmsis_dap_swd_open(void)
1144 {
1145  if (!(cmsis_dap_handle->caps & INFO_CAPS_SWD)) {
1146  LOG_ERROR("CMSIS-DAP: SWD not supported");
1147  return ERROR_JTAG_DEVICE_ERROR;
1148  }
1149 
1150  int retval = cmsis_dap_cmd_dap_connect(CONNECT_SWD);
1151  if (retval != ERROR_OK)
1152  return retval;
1153 
1154  /* Add more setup here.??... */
1155 
1156  LOG_INFO("CMSIS-DAP: Interface Initialised (SWD)");
1157  return ERROR_OK;
1158 }
1159 
1160 static int cmsis_dap_init(void)
1161 {
1162  uint8_t *data;
1163 
1164  int retval = cmsis_dap_open();
1165  if (retval != ERROR_OK)
1166  return retval;
1167 
1169 
1170  retval = cmsis_dap_get_caps_info();
1171  if (retval != ERROR_OK)
1172  return retval;
1173 
1174  retval = cmsis_dap_get_version_info();
1175  if (retval != ERROR_OK)
1176  return retval;
1177 
1178  retval = cmsis_dap_get_serial_info();
1179  if (retval != ERROR_OK)
1180  return retval;
1181 
1182  if (swd_mode) {
1183  retval = cmsis_dap_swd_open();
1184  if (retval != ERROR_OK)
1185  return retval;
1186  } else {
1187  /* Connect in JTAG mode */
1188  if (!(cmsis_dap_handle->caps & INFO_CAPS_JTAG)) {
1189  LOG_ERROR("CMSIS-DAP: JTAG not supported");
1190  return ERROR_JTAG_DEVICE_ERROR;
1191  }
1192 
1194  if (retval != ERROR_OK)
1195  return retval;
1196 
1197  LOG_INFO("CMSIS-DAP: Interface Initialised (JTAG)");
1198  }
1199 
1200  /* Be conservative and suppress submitting multiple HID requests
1201  * until we get packet count info from the adaptor */
1203  pending_queue_len = 12;
1204 
1205  /* INFO_ID_PKT_SZ - short */
1207  if (retval != ERROR_OK)
1208  goto init_err;
1209 
1210  if (data[0] == 2) { /* short */
1211  uint16_t pkt_sz = data[1] + (data[2] << 8);
1212  if (pkt_sz != cmsis_dap_handle->packet_size) {
1213 
1214  /* 4 bytes of command header + 5 bytes per register
1215  * write. For bulk read sequences just 4 bytes are
1216  * needed per transfer, so this is suboptimal. */
1217  pending_queue_len = (pkt_sz - 4) / 5;
1218 
1221  if (retval != ERROR_OK)
1222  goto init_err;
1223 
1224  LOG_DEBUG("CMSIS-DAP: Packet Size = %" PRIu16, pkt_sz);
1225  }
1226  }
1227 
1228  /* INFO_ID_PKT_CNT - byte */
1230  if (retval != ERROR_OK)
1231  goto init_err;
1232 
1233  if (data[0] == 1) { /* byte */
1234  int pkt_cnt = data[1];
1235  if (pkt_cnt > 1)
1237 
1238  LOG_DEBUG("CMSIS-DAP: Packet Count = %d", pkt_cnt);
1239  }
1240 
1241  LOG_DEBUG("Allocating FIFO for %d pending packets", cmsis_dap_handle->packet_count);
1242  for (int i = 0; i < cmsis_dap_handle->packet_count; i++) {
1243  pending_fifo[i].transfers = malloc(pending_queue_len * sizeof(struct pending_transfer_result));
1244  if (!pending_fifo[i].transfers) {
1245  LOG_ERROR("Unable to allocate memory for CMSIS-DAP queue");
1246  retval = ERROR_FAIL;
1247  goto init_err;
1248  }
1249  }
1250 
1251  /* Intentionally not checked for error, just logs an info message
1252  * not vital for further debugging */
1253  (void)cmsis_dap_get_status();
1254 
1255  /* Now try to connect to the target
1256  * TODO: This is all SWD only @ present */
1258  if (retval != ERROR_OK)
1259  goto init_err;
1260 
1261  /* Ask CMSIS-DAP to automatically retry on receiving WAIT for
1262  * up to 64 times. This must be changed to 0 if sticky
1263  * overrun detection is enabled. */
1264  retval = cmsis_dap_cmd_dap_tfer_configure(0, 64, 0);
1265  if (retval != ERROR_OK)
1266  goto init_err;
1267 
1268  if (swd_mode) {
1269  /* Data Phase (bit 2) must be set to 1 if sticky overrun
1270  * detection is enabled */
1271  retval = cmsis_dap_cmd_dap_swd_configure(0); /* 1 TRN, no Data Phase */
1272  if (retval != ERROR_OK)
1273  goto init_err;
1274  }
1275  /* Both LEDs on */
1276  /* Intentionally not checked for error, debugging will work
1277  * without LEDs */
1280 
1281  /* support connecting with srst asserted */
1283 
1286  retval = cmsis_dap_cmd_dap_swj_pins(0, SWJ_PIN_SRST, 0, NULL);
1287  if (retval != ERROR_OK)
1288  goto init_err;
1289  LOG_INFO("Connecting under reset");
1290  }
1291  }
1292  LOG_INFO("CMSIS-DAP: Interface ready");
1293  return ERROR_OK;
1294 
1295 init_err:
1296  cmsis_dap_quit();
1297  return retval;
1298 }
1299 
1300 static int cmsis_dap_swd_init(void)
1301 {
1302  swd_mode = true;
1303  return ERROR_OK;
1304 }
1305 
1306 static int cmsis_dap_quit(void)
1307 {
1309 
1310  /* Both LEDs off */
1313 
1315 
1316  return ERROR_OK;
1317 }
1318 
1319 static int cmsis_dap_reset(int trst, int srst)
1320 {
1321  /* Set both TRST and SRST even if they're not enabled as
1322  * there's no way to tristate them */
1323 
1324  output_pins = 0;
1325  if (!srst)
1327  if (!trst)
1329 
1332  if (retval != ERROR_OK)
1333  LOG_ERROR("CMSIS-DAP: Interface reset failed");
1334  return retval;
1335 }
1336 
1338 {
1339 #if 0
1340  int retval = cmsis_dap_cmd_dap_delay(cmd->cmd.sleep->us);
1341  if (retval != ERROR_OK)
1342 #endif
1343  jtag_sleep(cmd->cmd.sleep->us);
1344 }
1345 
1346 /* Set TMS high for five TCK clocks, to move the TAP to the Test-Logic-Reset state */
1348 {
1349  LOG_INFO("cmsis-dap JTAG TLR_RESET");
1350  uint8_t seq = 0xff;
1351 
1352  int retval = cmsis_dap_cmd_dap_swj_sequence(8, &seq);
1353  if (retval == ERROR_OK)
1355  return retval;
1356 }
1357 
1358 /* Set new end state */
1360 {
1363  else {
1364  LOG_ERROR("BUG: %i is not a valid end state", state);
1365  exit(-1);
1366  }
1367 }
1368 
1369 #ifdef SPRINT_BINARY
1370 static void sprint_binary(char *s, const uint8_t *buf, int offset, int len)
1371 {
1372  if (!len)
1373  return;
1374 
1375  /*
1376  buf = { 0x18 } len=5 should result in: 11000
1377  buf = { 0xff 0x18 } len=13 should result in: 11111111 11000
1378  buf = { 0xc0 0x18 } offset=3 len=10 should result in: 11000 11000
1379  i=3 there means i/8 = 0 so c = 0xFF, and
1380  */
1381  for (int i = offset; i < offset + len; ++i) {
1382  uint8_t c = buf[i / 8], mask = 1 << (i % 8);
1383  if ((i != offset) && !(i % 8))
1384  putchar(' ');
1385  *s++ = (c & mask) ? '1' : '0';
1386  }
1387  *s = 0;
1388 }
1389 #endif
1390 
1391 #ifdef CMSIS_DAP_JTAG_DEBUG
1392 static void debug_parse_cmsis_buf(const uint8_t *cmd, int cmdlen)
1393 {
1394  /* cmd is a usb packet to go to the cmsis-dap interface */
1395  printf("cmsis-dap buffer (%d b): ", cmdlen);
1396  for (int i = 0; i < cmdlen; ++i)
1397  printf(" %02x", cmd[i]);
1398  printf("\n");
1399  switch (cmd[0]) {
1400  case CMD_DAP_JTAG_SEQ: {
1401  printf("cmsis-dap jtag sequence command %02x (n=%d)\n", cmd[0], cmd[1]);
1402  /*
1403  * #1 = number of sequences
1404  * #2 = sequence info 1
1405  * #3...4+n_bytes-1 = sequence 1
1406  * #4+n_bytes = sequence info 2
1407  * #5+n_bytes = sequence 2 (single bit)
1408  */
1409  int pos = 2;
1410  for (int seq = 0; seq < cmd[1]; ++seq) {
1411  uint8_t info = cmd[pos++];
1412  int len = info & DAP_JTAG_SEQ_TCK;
1413  if (len == 0)
1414  len = 64;
1415  printf(" sequence %d starting %d: info %02x (len=%d tms=%d read_tdo=%d): ",
1416  seq, pos, info, len, info & DAP_JTAG_SEQ_TMS, info & DAP_JTAG_SEQ_TDO);
1417  for (int i = 0; i < DIV_ROUND_UP(len, 8); ++i)
1418  printf(" %02x", cmd[pos+i]);
1419  pos += DIV_ROUND_UP(len, 8);
1420  printf("\n");
1421  }
1422  if (pos != cmdlen) {
1423  printf("BUFFER LENGTH MISMATCH looks like %d but %d specified", pos, cmdlen);
1424  exit(-1);
1425  }
1426 
1427  break;
1428  }
1429  default:
1430  LOG_DEBUG("unknown cmsis-dap command %02x", cmd[1]);
1431  break;
1432  }
1433 }
1434 #endif
1435 
1436 static void cmsis_dap_flush(void)
1437 {
1438  if (!queued_seq_count)
1439  return;
1440 
1441  LOG_DEBUG_IO("Flushing %d queued sequences (%d bytes) with %d pending scan results to capture",
1443 
1444  /* prepare CMSIS-DAP packet */
1445  uint8_t *command = cmsis_dap_handle->command;
1449 
1450 #ifdef CMSIS_DAP_JTAG_DEBUG
1451  debug_parse_cmsis_buf(command, queued_seq_buf_end + 2);
1452 #endif
1453 
1454  /* send command to USB device */
1456 
1457  uint8_t *resp = cmsis_dap_handle->response;
1458  if (retval != ERROR_OK || resp[1] != DAP_OK) {
1459  LOG_ERROR("CMSIS-DAP command CMD_DAP_JTAG_SEQ failed.");
1460  exit(-1);
1461  }
1462 
1463 #ifdef CMSIS_DAP_JTAG_DEBUG
1464  LOG_DEBUG_IO("USB response buf:");
1465  for (int c = 0; c < queued_seq_buf_end + 3; ++c)
1466  printf("%02X ", resp[c]);
1467  printf("\n");
1468 #endif
1469 
1470  /* copy scan results into client buffers */
1471  for (int i = 0; i < pending_scan_result_count; ++i) {
1473  LOG_DEBUG_IO("Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits",
1474  i, pending_scan_result_count, scan->length, scan->first + 2, scan->buffer_offset);
1475 #ifdef CMSIS_DAP_JTAG_DEBUG
1476  for (uint32_t b = 0; b < DIV_ROUND_UP(scan->length, 8); ++b)
1477  printf("%02X ", resp[2+scan->first+b]);
1478  printf("\n");
1479 #endif
1480  bit_copy(scan->buffer, scan->buffer_offset, &resp[2 + scan->first], 0, scan->length);
1481  }
1482 
1483  /* reset */
1484  queued_seq_count = 0;
1485  queued_seq_buf_end = 0;
1486  queued_seq_tdo_ptr = 0;
1488 }
1489 
1490 /* queue a sequence of bits to clock out TDI / in TDO, executing if the buffer is full.
1491  *
1492  * sequence=NULL means clock out zeros on TDI
1493  * tdo_buffer=NULL means don't capture TDO
1494  */
1495 static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int s_offset,
1496  bool tms, uint8_t *tdo_buffer, int tdo_buffer_offset)
1497 {
1498  LOG_DEBUG_IO("[at %d] %d bits, tms %s, seq offset %d, tdo buf %p, tdo offset %d",
1500  s_len, tms ? "HIGH" : "LOW", s_offset, tdo_buffer, tdo_buffer_offset);
1501 
1502  if (s_len == 0)
1503  return;
1504 
1505  if (s_len > 64) {
1506  LOG_DEBUG_IO("START JTAG SEQ SPLIT");
1507  for (int offset = 0; offset < s_len; offset += 64) {
1508  int len = s_len - offset;
1509  if (len > 64)
1510  len = 64;
1511  LOG_DEBUG_IO("Splitting long jtag sequence: %d-bit chunk starting at offset %d", len, offset);
1513  len,
1514  sequence,
1515  s_offset + offset,
1516  tms,
1517  tdo_buffer,
1518  !tdo_buffer ? 0 : (tdo_buffer_offset + offset)
1519  );
1520  }
1521  LOG_DEBUG_IO("END JTAG SEQ SPLIT");
1522  return;
1523  }
1524 
1525  int cmd_len = 1 + DIV_ROUND_UP(s_len, 8);
1526  if (queued_seq_count >= 255 || queued_seq_buf_end + cmd_len > QUEUED_SEQ_BUF_LEN)
1527  /* empty out the buffer */
1528  cmsis_dap_flush();
1529 
1530  ++queued_seq_count;
1531 
1532  /* control byte */
1534  (tms ? DAP_JTAG_SEQ_TMS : 0) |
1535  (tdo_buffer ? DAP_JTAG_SEQ_TDO : 0) |
1536  (s_len == 64 ? 0 : s_len);
1537 
1538  if (sequence)
1539  bit_copy(&queued_seq_buf[queued_seq_buf_end + 1], 0, sequence, s_offset, s_len);
1540  else
1541  memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8));
1542 
1543  queued_seq_buf_end += cmd_len;
1544 
1545  if (tdo_buffer) {
1547  scan->first = queued_seq_tdo_ptr;
1548  queued_seq_tdo_ptr += DIV_ROUND_UP(s_len, 8);
1549  scan->length = s_len;
1550  scan->buffer = tdo_buffer;
1551  scan->buffer_offset = tdo_buffer_offset;
1552  }
1553 }
1554 
1555 /* queue a sequence of bits to clock out TMS, executing if the buffer is full */
1556 static void cmsis_dap_add_tms_sequence(const uint8_t *sequence, int s_len)
1557 {
1558  LOG_DEBUG_IO("%d bits: %02X", s_len, *sequence);
1559  /* we use a series of CMD_DAP_JTAG_SEQ commands to toggle TMS,
1560  because even though it seems ridiculously inefficient, it
1561  allows us to combine TMS and scan sequences into the same
1562  USB packet. */
1563  /* TODO: combine runs of the same tms value */
1564  for (int i = 0; i < s_len; ++i) {
1565  bool bit = (sequence[i / 8] & (1 << (i % 8))) != 0;
1567  }
1568 }
1569 
1570 /* Move to the end state by queuing a sequence to clock into TMS */
1571 static void cmsis_dap_state_move(void)
1572 {
1573  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
1574  uint8_t tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
1575 
1576  LOG_DEBUG_IO("state move from %s to %s: %d clocks, %02X on tms",
1578  tms_scan_bits, tms_scan);
1579  cmsis_dap_add_tms_sequence(&tms_scan, tms_scan_bits);
1580 
1582 }
1583 
1584 
1585 /* Execute a JTAG scan operation by queueing TMS and TDI/TDO sequences */
1587 {
1588  LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
1589  jtag_scan_type(cmd->cmd.scan));
1590 
1591  /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */
1592  while (cmd->cmd.scan->num_fields > 0
1593  && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) {
1594  cmd->cmd.scan->num_fields--;
1595  LOG_DEBUG("discarding trailing empty field");
1596  }
1597 
1598  if (cmd->cmd.scan->num_fields == 0) {
1599  LOG_DEBUG("empty scan, doing nothing");
1600  return;
1601  }
1602 
1603  if (cmd->cmd.scan->ir_scan) {
1604  if (tap_get_state() != TAP_IRSHIFT) {
1607  }
1608  } else {
1609  if (tap_get_state() != TAP_DRSHIFT) {
1612  }
1613  }
1614 
1615  cmsis_dap_end_state(cmd->cmd.scan->end_state);
1616 
1617  struct scan_field *field = cmd->cmd.scan->fields;
1618  unsigned scan_size = 0;
1619 
1620  for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) {
1621  scan_size += field->num_bits;
1622  LOG_DEBUG_IO("%s%s field %d/%d %d bits",
1623  field->in_value ? "in" : "",
1624  field->out_value ? "out" : "",
1625  i,
1626  cmd->cmd.scan->num_fields,
1627  field->num_bits);
1628 
1629  if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) {
1630  LOG_DEBUG_IO("Last field and have to move out of SHIFT state");
1631  /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap
1632  * movement. This last field can't have length zero, it was checked above. */
1634  field->num_bits - 1, /* number of bits to clock */
1635  field->out_value, /* output sequence */
1636  0, /* output offset */
1637  false, /* TMS low */
1638  field->in_value,
1639  0);
1640 
1641  /* Clock the last bit out, with TMS high */
1642  uint8_t last_bit = 0;
1643  if (field->out_value)
1644  bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
1646  1,
1647  &last_bit,
1648  0,
1649  true,
1650  field->in_value,
1651  field->num_bits - 1);
1653 
1654  /* Now clock one more cycle, with TMS low, to get us into a PAUSE state */
1656  1,
1657  &last_bit,
1658  0,
1659  false,
1660  NULL,
1661  0);
1663  } else {
1664  LOG_DEBUG_IO("Internal field, staying in SHIFT state afterwards");
1665  /* Clocking part of a sequence into DR or IR with TMS=0,
1666  leaving TMS=0 at the end so we can continue later */
1668  field->num_bits,
1669  field->out_value,
1670  0,
1671  false,
1672  field->in_value,
1673  0);
1674  }
1675  }
1676 
1677  if (tap_get_state() != tap_get_end_state()) {
1680  }
1681 
1682  LOG_DEBUG_IO("%s scan, %i bits, end in %s",
1683  (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
1685 }
1686 
1687 static void cmsis_dap_pathmove(int num_states, tap_state_t *path)
1688 {
1689  uint8_t tms0 = 0x00;
1690  uint8_t tms1 = 0xff;
1691 
1692  for (int i = 0; i < num_states; i++) {
1693  if (path[i] == tap_state_transition(tap_get_state(), false))
1694  cmsis_dap_add_tms_sequence(&tms0, 1);
1695  else if (path[i] == tap_state_transition(tap_get_state(), true))
1696  cmsis_dap_add_tms_sequence(&tms1, 1);
1697  else {
1698  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition.",
1700  exit(-1);
1701  }
1702 
1703  tap_set_state(path[i]);
1704  }
1705 
1707 }
1708 
1710 {
1711  LOG_DEBUG_IO("pathmove: %i states, end in %i",
1712  cmd->cmd.pathmove->num_states,
1713  cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
1714 
1715  cmsis_dap_pathmove(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
1716 }
1717 
1718 static void cmsis_dap_stableclocks(int num_cycles)
1719 {
1720  uint8_t tms = tap_get_state() == TAP_RESET;
1721  /* TODO: Perform optimizations? */
1722  /* Execute num_cycles. */
1723  for (int i = 0; i < num_cycles; i++)
1724  cmsis_dap_add_tms_sequence(&tms, 1);
1725 }
1726 
1727 static void cmsis_dap_runtest(int num_cycles)
1728 {
1729  tap_state_t saved_end_state = tap_get_end_state();
1730 
1731  /* Only do a state_move when we're not already in IDLE. */
1732  if (tap_get_state() != TAP_IDLE) {
1735  }
1736  cmsis_dap_stableclocks(num_cycles);
1737 
1738  /* Finish in end_state. */
1739  cmsis_dap_end_state(saved_end_state);
1740 
1741  if (tap_get_state() != tap_get_end_state())
1743 }
1744 
1746 {
1747  LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles,
1748  cmd->cmd.runtest->end_state);
1749 
1750  cmsis_dap_end_state(cmd->cmd.runtest->end_state);
1751  cmsis_dap_runtest(cmd->cmd.runtest->num_cycles);
1752 }
1753 
1755 {
1756  LOG_DEBUG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles);
1757  cmsis_dap_stableclocks(cmd->cmd.runtest->num_cycles);
1758 }
1759 
1761 {
1762  LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits);
1763  cmsis_dap_cmd_dap_swj_sequence(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits);
1764 }
1765 
1766 /* TODO: Is there need to call cmsis_dap_flush() for the JTAG_PATHMOVE,
1767  * JTAG_RUNTEST, JTAG_STABLECLOCKS? */
1769 {
1770  switch (cmd->type) {
1771  case JTAG_SLEEP:
1772  cmsis_dap_flush();
1774  break;
1775  case JTAG_TLR_RESET:
1776  cmsis_dap_flush();
1778  break;
1779  case JTAG_SCAN:
1781  break;
1782  case JTAG_PATHMOVE:
1784  break;
1785  case JTAG_RUNTEST:
1787  break;
1788  case JTAG_STABLECLOCKS:
1790  break;
1791  case JTAG_TMS:
1793  break;
1794  default:
1795  LOG_ERROR("BUG: unknown JTAG command type 0x%X encountered", cmd->type);
1796  exit(-1);
1797  }
1798 }
1799 
1800 static int cmsis_dap_execute_queue(void)
1801 {
1803 
1804  while (cmd) {
1806  cmd = cmd->next;
1807  }
1808 
1809  cmsis_dap_flush();
1810 
1811  return ERROR_OK;
1812 }
1813 
1814 static int cmsis_dap_speed(int speed)
1815 {
1816  if (speed == 0) {
1817  LOG_ERROR("RTCK not supported. Set nonzero \"adapter speed\".");
1819  }
1820 
1821  return cmsis_dap_cmd_dap_swj_clock(speed);
1822 }
1823 
1824 static int cmsis_dap_speed_div(int speed, int *khz)
1825 {
1826  *khz = speed;
1827  return ERROR_OK;
1828 }
1829 
1830 static int cmsis_dap_khz(int khz, int *jtag_speed)
1831 {
1832  *jtag_speed = khz;
1833  return ERROR_OK;
1834 }
1835 
1836 static bool calculate_swo_prescaler(unsigned int traceclkin_freq,
1837  uint32_t trace_freq, uint16_t *prescaler)
1838 {
1839  unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq;
1840  if (presc == 0 || presc > TPIU_ACPR_MAX_SWOSCALER + 1)
1841  return false;
1842 
1843  /* Probe's UART speed must be within 3% of the TPIU's SWO baud rate. */
1844  unsigned int max_deviation = (traceclkin_freq * 3) / 100;
1845  if (presc * trace_freq < traceclkin_freq - max_deviation ||
1846  presc * trace_freq > traceclkin_freq + max_deviation)
1847  return false;
1848 
1849  *prescaler = presc;
1850 
1851  return true;
1852 }
1853 
1858  bool trace_enabled,
1859  enum tpiu_pin_protocol pin_protocol,
1860  uint32_t port_size,
1861  unsigned int *swo_freq,
1862  unsigned int traceclkin_hz,
1863  uint16_t *swo_prescaler)
1864 {
1865  int retval;
1866 
1867  if (!trace_enabled) {
1870  if (retval != ERROR_OK) {
1871  LOG_ERROR("Failed to disable the SWO-trace.");
1872  return retval;
1873  }
1874  }
1876  LOG_INFO("SWO-trace disabled.");
1877  return ERROR_OK;
1878  }
1879 
1882  LOG_ERROR("SWO-trace is not supported by the device.");
1883  return ERROR_FAIL;
1884  }
1885 
1886  uint8_t swo_mode;
1887  if (pin_protocol == TPIU_PIN_PROTOCOL_ASYNC_UART &&
1889  swo_mode = DAP_SWO_MODE_UART;
1890  } else if (pin_protocol == TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER &&
1892  swo_mode = DAP_SWO_MODE_MANCHESTER;
1893  } else {
1894  LOG_ERROR("Selected pin protocol is not supported.");
1895  return ERROR_FAIL;
1896  }
1897 
1898  if (*swo_freq == 0) {
1899  LOG_INFO("SWO-trace frequency autodetection not implemented.");
1900  return ERROR_FAIL;
1901  }
1902 
1904  if (retval != ERROR_OK)
1905  return retval;
1906 
1908 
1910  if (retval != ERROR_OK)
1911  return retval;
1912 
1914  if (retval != ERROR_OK)
1915  return retval;
1916 
1917  retval = cmsis_dap_cmd_dap_swo_mode(swo_mode);
1918  if (retval != ERROR_OK)
1919  return retval;
1920 
1921  retval = cmsis_dap_cmd_dap_swo_baudrate(*swo_freq, swo_freq);
1922  if (retval != ERROR_OK)
1923  return retval;
1924 
1925  if (!calculate_swo_prescaler(traceclkin_hz, *swo_freq,
1926  swo_prescaler)) {
1927  LOG_ERROR("SWO frequency is not suitable. Please choose a "
1928  "different frequency or use auto-detection.");
1929  return ERROR_FAIL;
1930  }
1931 
1932  LOG_INFO("SWO frequency: %u Hz.", *swo_freq);
1933  LOG_INFO("SWO prescaler: %u.", *swo_prescaler);
1934 
1936  if (retval != ERROR_OK)
1937  return retval;
1938 
1940 
1941  return ERROR_OK;
1942 }
1943 
1947 static int cmsis_dap_poll_trace(uint8_t *buf, size_t *size)
1948 {
1949  uint8_t trace_status;
1950  size_t trace_count;
1951 
1953  *size = 0;
1954  return ERROR_OK;
1955  }
1956 
1957  int retval = cmsis_dap_cmd_dap_swo_status(&trace_status, &trace_count);
1958  if (retval != ERROR_OK)
1959  return retval;
1961  return ERROR_FAIL;
1962 
1963  *size = trace_count < *size ? trace_count : *size;
1964  size_t read_so_far = 0;
1965  do {
1966  size_t rb = 0;
1967  uint32_t packet_size = cmsis_dap_handle->packet_size - 4 /*data-reply*/;
1968  uint32_t remaining = *size - read_so_far;
1969  if (remaining < packet_size)
1970  packet_size = remaining;
1971  retval = cmsis_dap_cmd_dap_swo_data(
1972  packet_size,
1973  &trace_status,
1974  &rb,
1975  &buf[read_so_far]);
1976  if (retval != ERROR_OK)
1977  return retval;
1979  return ERROR_FAIL;
1980 
1981  read_so_far += rb;
1982  } while (read_so_far < *size);
1983 
1984  return ERROR_OK;
1985 }
1986 
1987 COMMAND_HANDLER(cmsis_dap_handle_info_command)
1988 {
1991 
1992  return ERROR_OK;
1993 }
1994 
1995 COMMAND_HANDLER(cmsis_dap_handle_cmd_command)
1996 {
1997  uint8_t *command = cmsis_dap_handle->command;
1998 
1999  for (unsigned i = 0; i < CMD_ARGC; i++)
2001 
2002  int retval = cmsis_dap_xfer(cmsis_dap_handle, CMD_ARGC);
2003 
2004  if (retval != ERROR_OK) {
2005  LOG_ERROR("CMSIS-DAP command failed.");
2006  return ERROR_JTAG_DEVICE_ERROR;
2007  }
2008 
2009  uint8_t *resp = cmsis_dap_handle->response;
2010  LOG_INFO("Returned data %02" PRIx8 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8,
2011  resp[1], resp[2], resp[3], resp[4]);
2012 
2013  return ERROR_OK;
2014 }
2015 
2016 COMMAND_HANDLER(cmsis_dap_handle_vid_pid_command)
2017 {
2018  if (CMD_ARGC > MAX_USB_IDS * 2) {
2019  LOG_WARNING("ignoring extra IDs in cmsis_dap_vid_pid "
2020  "(maximum is %d pairs)", MAX_USB_IDS);
2021  CMD_ARGC = MAX_USB_IDS * 2;
2022  }
2023  if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
2024  LOG_WARNING("incomplete cmsis_dap_vid_pid configuration directive");
2025  if (CMD_ARGC < 2)
2027  /* remove the incomplete trailing id */
2028  CMD_ARGC -= 1;
2029  }
2030 
2031  unsigned i;
2032  for (i = 0; i < CMD_ARGC; i += 2) {
2033  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], cmsis_dap_vid[i >> 1]);
2034  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], cmsis_dap_pid[i >> 1]);
2035  }
2036 
2037  /*
2038  * Explicitly terminate, in case there are multiples instances of
2039  * cmsis_dap_vid_pid.
2040  */
2041  cmsis_dap_vid[i >> 1] = cmsis_dap_pid[i >> 1] = 0;
2042 
2043  return ERROR_OK;
2044 }
2045 
2046 COMMAND_HANDLER(cmsis_dap_handle_backend_command)
2047 {
2048  if (CMD_ARGC == 1) {
2049  if (strcmp(CMD_ARGV[0], "auto") == 0) {
2050  cmsis_dap_backend = -1; /* autoselect */
2051  } else {
2052  for (unsigned int i = 0; i < ARRAY_SIZE(cmsis_dap_backends); i++) {
2053  if (strcasecmp(cmsis_dap_backends[i]->name, CMD_ARGV[0]) == 0) {
2054  cmsis_dap_backend = i;
2055  return ERROR_OK;
2056  }
2057  }
2058 
2059  LOG_ERROR("invalid backend argument to cmsis_dap_backend <backend>");
2060  }
2061  } else {
2062  LOG_ERROR("expected exactly one argument to cmsis_dap_backend <backend>");
2063  }
2064 
2065  return ERROR_OK;
2066 }
2067 
2068 static const struct command_registration cmsis_dap_subcommand_handlers[] = {
2069  {
2070  .name = "info",
2071  .handler = &cmsis_dap_handle_info_command,
2072  .mode = COMMAND_EXEC,
2073  .usage = "",
2074  .help = "show cmsis-dap info",
2075  },
2076  {
2077  .name = "cmd",
2078  .handler = &cmsis_dap_handle_cmd_command,
2079  .mode = COMMAND_EXEC,
2080  .usage = "",
2081  .help = "issue cmsis-dap command",
2082  },
2084 };
2085 
2086 
2087 static const struct command_registration cmsis_dap_command_handlers[] = {
2088  {
2089  .name = "cmsis-dap",
2090  .mode = COMMAND_ANY,
2091  .help = "perform CMSIS-DAP management",
2092  .usage = "<cmd>",
2094  },
2095  {
2096  .name = "cmsis_dap_vid_pid",
2097  .handler = &cmsis_dap_handle_vid_pid_command,
2098  .mode = COMMAND_CONFIG,
2099  .help = "the vendor ID and product ID of the CMSIS-DAP device",
2100  .usage = "(vid pid)*",
2101  },
2102  {
2103  .name = "cmsis_dap_backend",
2104  .handler = &cmsis_dap_handle_backend_command,
2105  .mode = COMMAND_CONFIG,
2106  .help = "set the communication backend to use (USB bulk or HID).",
2107  .usage = "(auto | usb_bulk | hid)",
2108  },
2109 #if BUILD_CMSIS_DAP_USB
2110  {
2111  .name = "cmsis_dap_usb",
2113  .mode = COMMAND_ANY,
2114  .help = "USB bulk backend-specific commands",
2115  .usage = "<cmd>",
2116  },
2117 #endif
2119 };
2120 
2121 static const struct swd_driver cmsis_dap_swd_driver = {
2123  .switch_seq = cmsis_dap_swd_switch_seq,
2124  .read_reg = cmsis_dap_swd_read_reg,
2125  .write_reg = cmsis_dap_swd_write_reg,
2126  .run = cmsis_dap_swd_run_queue,
2127 };
2128 
2129 static const char * const cmsis_dap_transport[] = { "swd", "jtag", NULL };
2130 
2131 static struct jtag_interface cmsis_dap_interface = {
2133  .execute_queue = cmsis_dap_execute_queue,
2134 };
2135 
2137  .name = "cmsis-dap",
2138  .transports = cmsis_dap_transport,
2139  .commands = cmsis_dap_command_handlers,
2140 
2141  .init = cmsis_dap_init,
2142  .quit = cmsis_dap_quit,
2143  .reset = cmsis_dap_reset,
2144  .speed = cmsis_dap_speed,
2145  .khz = cmsis_dap_khz,
2146  .speed_div = cmsis_dap_speed_div,
2147  .config_trace = cmsis_dap_config_trace,
2148  .poll_trace = cmsis_dap_poll_trace,
2149 
2150  .jtag_ops = &cmsis_dap_interface,
2151  .swd_ops = &cmsis_dap_swd_driver,
2152 };
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
Definition: adapter.c:299
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
Definition: adapter.c:208
static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:514
#define SWD_ACK_FAULT
Definition: arm_adi_v5.h:33
#define DP_CTRL_STAT
Definition: arm_adi_v5.h:50
#define CORUNDETECT
Definition: arm_adi_v5.h:82
#define DP_RDBUFF
Definition: arm_adi_v5.h:58
swd_special_seq
Definition: arm_adi_v5.h:229
@ DORMANT_TO_JTAG
Definition: arm_adi_v5.h:236
@ JTAG_TO_SWD
Definition: arm_adi_v5.h:231
@ DORMANT_TO_SWD
Definition: arm_adi_v5.h:235
@ LINE_RESET
Definition: arm_adi_v5.h:230
@ JTAG_TO_DORMANT
Definition: arm_adi_v5.h:232
@ SWD_TO_DORMANT
Definition: arm_adi_v5.h:234
@ SWD_TO_JTAG
Definition: arm_adi_v5.h:233
#define DP_TARGETSEL
Definition: arm_adi_v5.h:59
#define SWD_ACK_WAIT
Definition: arm_adi_v5.h:32
#define SWD_ACK_OK
Definition: arm_adi_v5.h:31
tpiu_pin_protocol
Definition: arm_tpiu_swo.h:7
@ TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER
asynchronous output with Manchester coding
Definition: arm_tpiu_swo.h:9
@ TPIU_PIN_PROTOCOL_ASYNC_UART
asynchronous output with NRZ coding
Definition: arm_tpiu_swo.h:10
enum arm_mode mode
Definition: armv4_5.c:277
const char * name
Definition: armv4_5.c:76
static void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
Definition: binarybuffer.h:201
static int cmsis_dap_init(void)
Definition: cmsis_dap.c:1160
static int cmsis_dap_cmd_dap_swo_status(uint8_t *trace_status, size_t *trace_count)
Reads the SWO trace status.
Definition: cmsis_dap.c:708
static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap)
Definition: cmsis_dap.c:763
static int cmsis_dap_cmd_dap_swo_data(size_t max_trace_count, uint8_t *trace_status, size_t *trace_count, uint8_t *data)
Reads the captured SWO trace data from Trace Buffer.
Definition: cmsis_dap.c:737
#define DAP_SWO_MODE_MANCHESTER
Definition: cmsis_dap.c:184
#define MAX_PENDING_SCAN_RESULTS
Definition: cmsis_dap.c:246
static int cmsis_dap_get_status(void)
Definition: cmsis_dap.c:1053
static int cmsis_dap_reset(int trst, int srst)
Definition: cmsis_dap.c:1319
static int cmsis_dap_get_caps_info(void)
Definition: cmsis_dap.c:1009
#define MAX_PENDING_REQUESTS
Definition: cmsis_dap.c:236
#define INFO_CAPS__NUM_CAPS
Definition: cmsis_dap.c:102
#define CMD_DAP_INFO
Definition: cmsis_dap.c:73
static int queued_retval
Definition: cmsis_dap.c:257
#define INFO_ID_PKT_SZ
Definition: cmsis_dap.c:90
static int cmsis_dap_swd_switch_seq(enum swd_special_seq seq)
Definition: cmsis_dap.c:1072
static uint16_t cmsis_dap_vid[MAX_USB_IDS+1]
Definition: cmsis_dap.c:67
#define INFO_ID_CAPS
Definition: cmsis_dap.c:88
static void cmsis_dap_execute_runtest(struct jtag_command *cmd)
Definition: cmsis_dap.c:1745
static struct jtag_interface cmsis_dap_interface
Definition: cmsis_dap.c:2131
static int cmsis_dap_swd_open(void)
Definition: cmsis_dap.c:1143
#define DAP_SWO_STATUS_CAPTURE_MASK
Definition: cmsis_dap.c:193
#define DAP_JTAG_SEQ_TDO
Definition: cmsis_dap.c:154
static int cmsis_dap_cmd_dap_swo_control(uint8_t control)
Controls the SWO trace data capture.
Definition: cmsis_dap.c:684
static struct cmsis_dap * cmsis_dap_handle
Definition: cmsis_dap.c:261
static int cmsis_dap_cmd_dap_info(uint8_t info, uint8_t **data)
Definition: cmsis_dap.c:441
static struct pending_scan_result pending_scan_results[MAX_PENDING_SCAN_RESULTS]
Definition: cmsis_dap.c:248
static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int s_offset, bool tms, uint8_t *tdo_buffer, int tdo_buffer_offset)
Definition: cmsis_dap.c:1495
static int cmsis_dap_cmd_dap_swj_pins(uint8_t pins, uint8_t mask, uint32_t delay, uint8_t *input)
Definition: cmsis_dap.c:377
static int cmsis_dap_cmd_dap_swo_baudrate(uint32_t in_baudrate, uint32_t *dev_baudrate)
Sets the baudrate for capturing SWO trace data.
Definition: cmsis_dap.c:654
#define CMD_DAP_LED
Definition: cmsis_dap.c:74
static int cmsis_dap_speed_div(int speed, int *khz)
Definition: cmsis_dap.c:1824
#define CMD_DAP_SWJ_CLOCK
Definition: cmsis_dap.c:119
static int pending_fifo_block_count
Definition: cmsis_dap.c:243
static int cmsis_dap_cmd_dap_swd_configure(uint8_t cfg)
Definition: cmsis_dap.c:530
static bool calculate_swo_prescaler(unsigned int traceclkin_freq, uint32_t trace_freq, uint16_t *prescaler)
Definition: cmsis_dap.c:1836
#define SWJ_PIN_TMS
Definition: cmsis_dap.c:133
#define INFO_CAPS_JTAG
Definition: cmsis_dap.c:94
static struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS]
Definition: cmsis_dap.c:241
#define SWJ_PIN_TCK
Definition: cmsis_dap.c:132
#define INFO_ID_SWO_BUF_SZ
Definition: cmsis_dap.c:91
static int queued_seq_buf_end
Definition: cmsis_dap.c:253
#define DAP_OK
Definition: cmsis_dap.c:164
#define DAP_SWO_STATUS_CAPTURE_ACTIVE
Definition: cmsis_dap.c:192
static int queued_seq_count
Definition: cmsis_dap.c:252
static void cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: cmsis_dap.c:968
struct adapter_driver cmsis_dap_adapter_driver
Definition: cmsis_dap.c:2136
static int cmsis_dap_cmd_dap_swj_clock(uint32_t swj_clock)
Definition: cmsis_dap.c:398
static void cmsis_dap_flush(void)
Definition: cmsis_dap.c:1436
#define CMD_DAP_JTAG_SEQ
Definition: cmsis_dap.c:144
#define CMD_DAP_TFER_CONFIGURE
Definition: cmsis_dap.c:158
#define INFO_CAPS_SWO_UART
Definition: cmsis_dap.c:95
#define CMD_DAP_SWO_STATUS
Definition: cmsis_dap.c:172
#define CMD_DAP_SWD_CONFIGURE
Definition: cmsis_dap.c:140
static int cmsis_dap_quit(void)
Definition: cmsis_dap.c:1306
static bool swd_mode
Definition: cmsis_dap.c:70
static const struct swd_driver cmsis_dap_swd_driver
Definition: cmsis_dap.c:2121
#define DAP_SWO_TRANSPORT_DATA
Definition: cmsis_dap.c:178
#define CMD_DAP_DELAY
Definition: cmsis_dap.c:117
#define CMD_DAP_DISCONNECT
Definition: cmsis_dap.c:76
#define CMD_DAP_SWJ_SEQ
Definition: cmsis_dap.c:120
#define INFO_ID_FW_VER
Definition: cmsis_dap.c:85
#define MAX_USB_IDS
Definition: cmsis_dap.c:65
static int cmsis_dap_cmd_dap_disconnect(void)
Definition: cmsis_dap.c:497
static const char *const cmsis_dap_transport[]
Definition: cmsis_dap.c:2129
#define CONNECT_SWD
Definition: cmsis_dap.c:113
#define CONNECT_JTAG
Definition: cmsis_dap.c:114
static void cmsis_dap_runtest(int num_cycles)
Definition: cmsis_dap.c:1727
static int cmsis_dap_cmd_dap_tfer_configure(uint8_t idle, uint16_t retry_count, uint16_t match_retry)
Definition: cmsis_dap.c:512
static void cmsis_dap_execute_stableclocks(struct jtag_command *cmd)
Definition: cmsis_dap.c:1754
static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
Definition: cmsis_dap.c:838
static uint8_t queued_seq_buf[1024]
Definition: cmsis_dap.c:255
#define DAP_JTAG_SEQ_TMS
Definition: cmsis_dap.c:152
static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen)
Definition: cmsis_dap.c:338
#define CMD_DAP_SWO_MODE
Definition: cmsis_dap.c:169
#define LED_OFF
Definition: cmsis_dap.c:108
#define INFO_CAPS_SWD
Definition: cmsis_dap.c:93
static int cmsis_dap_get_serial_info(void)
Definition: cmsis_dap.c:980
static int pending_fifo_put_idx
Definition: cmsis_dap.c:242
static void cmsis_dap_flush_read(struct cmsis_dap *dap)
Definition: cmsis_dap.c:322
static int pending_scan_result_count
Definition: cmsis_dap.c:247
#define INFO_ID_PKT_CNT
Definition: cmsis_dap.c:89
#define LED_ID_RUN
Definition: cmsis_dap.c:106
#define CMD_DAP_CONNECT
Definition: cmsis_dap.c:75
static void cmsis_dap_execute_scan(struct jtag_command *cmd)
Definition: cmsis_dap.c:1586
static void cmsis_dap_execute_command(struct jtag_command *cmd)
Definition: cmsis_dap.c:1768
#define CMD_DAP_SWO_CONTROL
Definition: cmsis_dap.c:171
static void cmsis_dap_end_state(tap_state_t state)
Definition: cmsis_dap.c:1359
static int cmsis_dap_swd_run_queue(void)
Definition: cmsis_dap.c:914
#define INFO_ID_SERNUM
Definition: cmsis_dap.c:84
static int cmsis_dap_cmd_dap_connect(uint8_t mode)
Definition: cmsis_dap.c:476
#define CMD_DAP_TFER
Definition: cmsis_dap.c:159
#define CMD_DAP_SWO_TRANSPORT
Definition: cmsis_dap.c:168
static void cmsis_dap_execute_tms(struct jtag_command *cmd)
Definition: cmsis_dap.c:1760
static const struct cmsis_dap_backend *const cmsis_dap_backends[]
Definition: cmsis_dap.c:42
#define INFO_CAPS_SWO_MANCHESTER
Definition: cmsis_dap.c:96
static int queued_seq_tdo_ptr
Definition: cmsis_dap.c:254
static const char *const info_caps_str[INFO_CAPS__NUM_CAPS]
Definition: cmsis_dap.c:200
static const struct command_registration cmsis_dap_subcommand_handlers[]
Definition: cmsis_dap.c:2068
static int cmsis_dap_execute_queue(void)
Definition: cmsis_dap.c:1800
static void cmsis_dap_state_move(void)
Definition: cmsis_dap.c:1571
static int cmsis_dap_cmd_dap_swo_mode(uint8_t mode)
Sets the SWO trace capture mode.
Definition: cmsis_dap.c:629
static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
Definition: cmsis_dap.c:933
static uint8_t output_pins
Definition: cmsis_dap.c:259
#define SWJ_PIN_SRST
Definition: cmsis_dap.c:137
#define CMD_DAP_SWD_SEQUENCE
Definition: cmsis_dap.c:141
static int cmsis_dap_cmd_dap_swj_sequence(uint8_t s_len, const uint8_t *sequence)
Definition: cmsis_dap.c:418
static int cmsis_dap_khz(int khz, int *jtag_speed)
Definition: cmsis_dap.c:1830
static int pending_queue_len
Definition: cmsis_dap.c:240
static int cmsis_dap_metacmd_targetsel(uint32_t instance_id)
Definition: cmsis_dap.c:564
static void cmsis_dap_stableclocks(int num_cycles)
Definition: cmsis_dap.c:1718
static int cmsis_dap_backend
Definition: cmsis_dap.c:69
static void cmsis_dap_close(struct cmsis_dap *dap)
Definition: cmsis_dap.c:305
static int cmsis_dap_poll_trace(uint8_t *buf, size_t *size)
Definition: cmsis_dap.c:1947
#define CMD_DAP_SWO_BAUDRATE
Definition: cmsis_dap.c:170
static int cmsis_dap_swd_init(void)
Definition: cmsis_dap.c:1300
static void cmsis_dap_execute_sleep(struct jtag_command *cmd)
Definition: cmsis_dap.c:1337
#define LED_ID_CONNECT
Definition: cmsis_dap.c:105
static int cmsis_dap_open(void)
Definition: cmsis_dap.c:266
#define DAP_ERROR
Definition: cmsis_dap.c:165
COMMAND_HANDLER(cmsis_dap_handle_info_command)
Definition: cmsis_dap.c:1987
static int cmsis_dap_speed(int speed)
Definition: cmsis_dap.c:1814
#define QUEUED_SEQ_BUF_LEN
Definition: cmsis_dap.c:251
static void cmsis_dap_pathmove(int num_states, tap_state_t *path)
Definition: cmsis_dap.c:1687
static int pending_fifo_get_idx
Definition: cmsis_dap.c:242
static int cmsis_dap_cmd_dap_led(uint8_t led, uint8_t state)
Definition: cmsis_dap.c:459
static int cmsis_dap_cmd_dap_swo_transport(uint8_t transport)
Sets the SWO transport mode.
Definition: cmsis_dap.c:609
#define DAP_SWO_CONTROL_STOP
Definition: cmsis_dap.c:187
static void cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: cmsis_dap.c:974
#define SWJ_PIN_TRST
Definition: cmsis_dap.c:136
#define SWJ_PIN_TDI
Definition: cmsis_dap.c:134
static void cmsis_dap_execute_pathmove(struct jtag_command *cmd)
Definition: cmsis_dap.c:1709
static const struct command_registration cmsis_dap_command_handlers[]
Definition: cmsis_dap.c:2087
#define CMD_DAP_SWO_DATA
Definition: cmsis_dap.c:173
#define DAP_SWO_CONTROL_START
Definition: cmsis_dap.c:188
static int cmsis_dap_execute_tlr_reset(struct jtag_command *cmd)
Definition: cmsis_dap.c:1347
static int cmsis_dap_get_swo_buf_sz(uint32_t *swo_buf_sz)
Definition: cmsis_dap.c:1034
#define LED_ON
Definition: cmsis_dap.c:109
static int cmsis_dap_config_trace(bool trace_enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *swo_freq, unsigned int traceclkin_hz, uint16_t *swo_prescaler)
Definition: cmsis_dap.c:1857
#define DAP_SWO_MODE_UART
Definition: cmsis_dap.c:183
static void cmsis_dap_add_tms_sequence(const uint8_t *sequence, int s_len)
Definition: cmsis_dap.c:1556
static uint16_t cmsis_dap_pid[MAX_USB_IDS+1]
Definition: cmsis_dap.c:68
#define SWJ_PIN_TDO
Definition: cmsis_dap.c:135
static int cmsis_dap_get_version_info(void)
Definition: cmsis_dap.c:994
#define CMD_DAP_SWJ_PINS
Definition: cmsis_dap.c:118
#define DAP_JTAG_SEQ_TCK
Definition: cmsis_dap.c:150
const struct cmsis_dap_backend cmsis_dap_usb_backend
const struct command_registration cmsis_dap_usb_subcommand_handlers[]
const struct cmsis_dap_backend cmsis_dap_hid_backend
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:155
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:385
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:150
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:425
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
Definition: commands.c:36
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:162
@ JTAG_TLR_RESET
Definition: commands.h:137
@ JTAG_SCAN
Definition: commands.h:129
@ JTAG_PATHMOVE
Definition: commands.h:140
@ JTAG_STABLECLOCKS
Definition: commands.h:142
@ JTAG_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_TMS
Definition: commands.h:143
#define TPIU_ACPR_MAX_SWOSCALER
Definition: cortex_m.h:111
void delay_us(uint16_t delay)
Definition: delay.c:23
int mask
Definition: esirisc.c:1698
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
Definition: interface.c:200
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
Definition: interface.c:223
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
Definition: interface.c:48
tap_state_t tap_get_end_state(void)
For more information,.
Definition: interface.c:56
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
Definition: interface.c:190
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
Definition: interface.c:195
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
Definition: interface.c:37
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:189
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
Definition: interface.h:49
static enum reset_types jtag_reset_config
Definition: jtag/core.c:87
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1062
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1734
#define ERROR_JTAG_DEVICE_ERROR
Definition: jtag.h:555
@ TAP_RESET
Definition: jtag.h:55
@ TAP_IRSHIFT
Definition: jtag.h:50
@ TAP_IDLE
Definition: jtag.h:52
@ TAP_DRSHIFT
Definition: jtag.h:42
reset_types
Definition: jtag.h:212
@ RESET_SRST_NO_GATING
Definition: jtag.h:221
@ RESET_CNCT_UNDER_SRST
Definition: jtag.h:222
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define ERROR_JTAG_NOT_IMPLEMENTED
Definition: jtag.h:551
static struct scan_blk scan
Definition: lakemont.c:60
#define LIBUSB_TIMEOUT_MS
Definition: libusb_helper.h:26
#define ERROR_WAIT
Definition: log.h:162
#define ERROR_NOT_IMPLEMENTED
Definition: log.h:165
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define LOG_WARNING(expr ...)
Definition: log.h:120
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define ERROR_TIMEOUT_REACHED
Definition: log.h:164
#define LOG_INFO(expr ...)
Definition: log.h:117
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
static uint32_t bit(uint32_t value, unsigned int b)
Definition: opcodes.h:15
#define MIN(a, b)
Definition: replacements.h:22
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
#define BIT(nr)
Definition: stm32l4x.h:18
Represents a driver for a debugging interface.
Definition: interface.h:207
const char *const name
The name of the interface driver.
Definition: interface.h:209
int(* read)(struct cmsis_dap *dap, int timeout_ms)
Definition: cmsis_dap.h:31
int(* packet_buffer_alloc)(struct cmsis_dap *dap, unsigned int pkt_sz)
Definition: cmsis_dap.h:33
void(* close)(struct cmsis_dap *dap)
Definition: cmsis_dap.h:30
int(* open)(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], const char *serial)
Definition: cmsis_dap.h:29
int(* write)(struct cmsis_dap *dap, int len, int timeout_ms)
Definition: cmsis_dap.h:32
uint16_t caps
Definition: cmsis_dap.h:21
bool trace_enabled
Definition: cmsis_dap.h:24
uint8_t * response
Definition: cmsis_dap.h:20
uint16_t packet_size
Definition: cmsis_dap.h:15
uint8_t * command
Definition: cmsis_dap.h:19
uint8_t * packet_buffer
Definition: cmsis_dap.h:17
int packet_count
Definition: cmsis_dap.h:16
const struct cmsis_dap_backend * backend
Definition: cmsis_dap.h:14
uint32_t swo_buf_sz
Definition: cmsis_dap.h:23
const char * name
Definition: command.h:229
enum command_mode mode
Definition: command.h:232
Represents a driver for a debugging interface.
Definition: interface.h:184
unsigned supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:188
struct pending_transfer_result * transfers
Definition: cmsis_dap.c:219
unsigned first
Offset in bytes in the CMD_DAP_JTAG_SEQ response buffer.
Definition: cmsis_dap.c:225
uint8_t * buffer
Location to store the result.
Definition: arm-jtag-ew.c:520
unsigned length
Number of bits to read.
Definition: cmsis_dap.c:227
unsigned buffer_offset
Offset in the destination buffer.
Definition: cmsis_dap.c:231
This structure defines a single scan field in the scan.
Definition: jtag.h:86
int num_bits
The number of bits this field specifies.
Definition: jtag.h:88
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:92
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:90
Definition: osbdm.c:17
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Definition: swd.h:255
Wrapper for transport lifecycle operations.
Definition: transport.h:35
static const unsigned swd_seq_swd_to_jtag_len
Definition: swd.h:144
static const unsigned swd_seq_jtag_to_swd_len
Definition: swd.h:125
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
Definition: swd.h:230
#define SWD_CMD_A32
Definition: swd.h:19
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
Definition: swd.h:171
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
Definition: swd.h:199
static const unsigned swd_seq_dormant_to_swd_len
Definition: swd.h:190
#define SWD_CMD_PARK
Definition: swd.h:22
static uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver....
Definition: swd.h:35
#define SWD_CMD_APNDP
Definition: swd.h:17
static const unsigned swd_seq_jtag_to_dormant_len
Definition: swd.h:211
#define SWD_CMD_START
Definition: swd.h:16
#define SWD_CMD_RNW
Definition: swd.h:18
static const unsigned swd_seq_dormant_to_jtag_len
Definition: swd.h:244
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
Definition: swd.h:98
static const unsigned swd_seq_line_reset_len
Definition: swd.h:104
#define SWD_CMD_STOP
Definition: swd.h:21
static const unsigned swd_seq_swd_to_dormant_len
Definition: swd.h:159
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
Definition: swd.h:115
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
Definition: swd.h:136
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
Definition: swd.h:153
trace_status
Definition: trace.h:36
static uint16_t le_to_h_u16(const uint8_t *buf)
Definition: types.h:122
static void h_u32_to_le(uint8_t *buf, uint32_t val)
Definition: types.h:178
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static void h_u16_to_le(uint8_t *buf, uint16_t val)
Definition: types.h:208
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
Definition: types.h:265
static struct ublast_lowlevel_priv info
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t state[4]
Definition: vdebug.c:21