OpenOCD
ftdi.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /**************************************************************************
4 * Copyright (C) 2012 by Andreas Fritiofson *
5 * andreas.fritiofson@gmail.com *
6 ***************************************************************************/
7 
56 #ifdef HAVE_CONFIG_H
57 #include "config.h"
58 #endif
59 
60 /* project specific includes */
61 #include <jtag/adapter.h>
62 #include <jtag/interface.h>
63 #include <jtag/swd.h>
64 #include <transport/transport.h>
65 #include <helper/time_support.h>
66 #include <helper/log.h>
67 #include <helper/nvp.h>
68 
69 #if IS_CYGWIN == 1
70 #include <windows.h>
71 #endif
72 
73 #include <assert.h>
74 
75 /* FTDI access library includes */
76 #include "mpsse.h"
77 
78 #define JTAG_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
79 #define JTAG_MODE_ALT (LSB_FIRST | NEG_EDGE_IN | NEG_EDGE_OUT)
80 #define SWD_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
81 
82 static char *ftdi_device_desc;
83 static uint8_t ftdi_channel;
84 static uint8_t ftdi_jtag_mode = JTAG_MODE;
85 
86 static bool swd_mode;
87 
88 #define MAX_USB_IDS 8
89 /* vid = pid = 0 marks the end of the list */
90 static uint16_t ftdi_vid[MAX_USB_IDS + 1] = { 0 };
91 static uint16_t ftdi_pid[MAX_USB_IDS + 1] = { 0 };
92 
93 static struct mpsse_ctx *mpsse_ctx;
94 
95 struct signal {
96  const char *name;
97  uint16_t data_mask;
98  uint16_t input_mask;
99  uint16_t oe_mask;
102  bool invert_oe;
103  struct signal *next;
104 };
105 
106 static struct signal *signals;
107 
108 /* FIXME: Where to store per-instance data? We need an SWD context. */
109 static struct swd_cmd_queue_entry {
110  uint8_t cmd;
111  uint32_t *dst;
112  uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)];
114 static size_t swd_cmd_queue_length;
115 static size_t swd_cmd_queue_alloced;
116 static int queued_retval;
117 static int freq;
118 
119 static uint16_t output;
120 static uint16_t direction;
121 static uint16_t jtag_output_init;
122 static uint16_t jtag_direction_init;
123 
124 static int ftdi_swd_switch_seq(enum swd_special_seq seq);
125 
126 static struct signal *find_signal_by_name(const char *name)
127 {
128  for (struct signal *sig = signals; sig; sig = sig->next) {
129  if (strcmp(name, sig->name) == 0)
130  return sig;
131  }
132  return NULL;
133 }
134 
135 static struct signal *create_signal(const char *name)
136 {
137  struct signal **psig = &signals;
138  while (*psig)
139  psig = &(*psig)->next;
140 
141  *psig = calloc(1, sizeof(**psig));
142  if (!*psig)
143  return NULL;
144 
145  (*psig)->name = strdup(name);
146  if (!(*psig)->name) {
147  free(*psig);
148  *psig = NULL;
149  }
150  return *psig;
151 }
152 
153 static int ftdi_set_signal(const struct signal *s, char value)
154 {
155  bool data;
156  bool oe;
157 
158  if (s->data_mask == 0 && s->oe_mask == 0) {
159  LOG_ERROR("interface doesn't provide signal '%s'", s->name);
160  return ERROR_FAIL;
161  }
162  switch (value) {
163  case '0':
164  data = s->invert_data;
165  oe = !s->invert_oe;
166  break;
167  case '1':
168  if (s->data_mask == 0) {
169  LOG_ERROR("interface can't drive '%s' high", s->name);
170  return ERROR_FAIL;
171  }
172  data = !s->invert_data;
173  oe = !s->invert_oe;
174  break;
175  case 'z':
176  case 'Z':
177  if (s->oe_mask == 0) {
178  LOG_ERROR("interface can't tri-state '%s'", s->name);
179  return ERROR_FAIL;
180  }
181  data = s->invert_data;
182  oe = s->invert_oe;
183  break;
184  default:
185  LOG_ERROR("invalid signal level specifier \'%c\'(0x%02x)", value, value);
186  return ERROR_FAIL;
187  }
188 
189  uint16_t old_output = output;
190  uint16_t old_direction = direction;
191 
192  output = data ? output | s->data_mask : output & ~s->data_mask;
193  if (s->oe_mask == s->data_mask)
194  direction = oe ? direction | s->oe_mask : direction & ~s->oe_mask;
195  else
196  output = oe ? output | s->oe_mask : output & ~s->oe_mask;
197 
198  if ((output & 0xff) != (old_output & 0xff) || (direction & 0xff) != (old_direction & 0xff))
200  if ((output >> 8 != old_output >> 8) || (direction >> 8 != old_direction >> 8))
202 
203  return ERROR_OK;
204 }
205 
206 static int ftdi_get_signal(const struct signal *s, uint16_t *value_out)
207 {
208  uint8_t data_low = 0;
209  uint8_t data_high = 0;
210 
211  if (s->input_mask == 0) {
212  LOG_ERROR("interface doesn't provide signal '%s'", s->name);
213  return ERROR_FAIL;
214  }
215 
216  if (s->input_mask & 0xff)
218  if (s->input_mask >> 8)
220 
222 
223  *value_out = (((uint16_t)data_high) << 8) | data_low;
224 
225  if (s->invert_input)
226  *value_out = ~(*value_out);
227 
228  *value_out &= s->input_mask;
229 
230  return ERROR_OK;
231 }
232 
241 static void move_to_state(tap_state_t goal_state)
242 {
243  tap_state_t start_state = tap_get_state();
244 
245  /* goal_state is 1/2 of a tuple/pair of states which allow convenient
246  lookup of the required TMS pattern to move to this state from the
247  start state.
248  */
249 
250  /* do the 2 lookups */
251  uint8_t tms_bits = tap_get_tms_path(start_state, goal_state);
252  int tms_count = tap_get_tms_path_len(start_state, goal_state);
253  assert(tms_count <= 8);
254 
255  LOG_DEBUG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state));
256 
257  /* Track state transitions step by step */
258  for (int i = 0; i < tms_count; i++)
259  tap_set_state(tap_state_transition(tap_get_state(), (tms_bits >> i) & 1));
260 
262  &tms_bits,
263  0,
264  tms_count,
265  false,
267 }
268 
269 static int ftdi_speed(int speed)
270 {
271  int retval;
272  retval = mpsse_set_frequency(mpsse_ctx, speed);
273 
274  if (retval < 0) {
275  LOG_ERROR("couldn't set FTDI TCK speed");
276  return retval;
277  }
278 
279  if (!swd_mode && speed >= 10000000 && ftdi_jtag_mode != JTAG_MODE_ALT)
280  LOG_INFO("ftdi: if you experience problems at higher adapter clocks, try "
281  "the command \"ftdi tdo_sample_edge falling\"");
282  return ERROR_OK;
283 }
284 
285 static int ftdi_speed_div(int speed, int *khz)
286 {
287  *khz = speed / 1000;
288  return ERROR_OK;
289 }
290 
291 static int ftdi_khz(int khz, int *jtag_speed)
292 {
293  if (khz == 0 && !mpsse_is_high_speed(mpsse_ctx)) {
294  LOG_DEBUG("RCLK not supported");
295  return ERROR_FAIL;
296  }
297 
298  *jtag_speed = khz * 1000;
299  return ERROR_OK;
300 }
301 
303 {
306  else {
307  LOG_ERROR("BUG: %s is not a stable end state", tap_state_name(state));
308  exit(-1);
309  }
310 }
311 
313 {
314  int i;
315  uint8_t zero = 0;
316 
317  LOG_DEBUG_IO("runtest %i cycles, end in %s",
318  cmd->cmd.runtest->num_cycles,
319  tap_state_name(cmd->cmd.runtest->end_state));
320 
321  if (tap_get_state() != TAP_IDLE)
323 
324  /* TODO: Reuse ftdi_execute_stableclocks */
325  i = cmd->cmd.runtest->num_cycles;
326  while (i > 0) {
327  /* there are no state transitions in this code, so omit state tracking */
328  unsigned this_len = i > 7 ? 7 : i;
329  mpsse_clock_tms_cs_out(mpsse_ctx, &zero, 0, this_len, false, ftdi_jtag_mode);
330  i -= this_len;
331  }
332 
333  ftdi_end_state(cmd->cmd.runtest->end_state);
334 
335  if (tap_get_state() != tap_get_end_state())
337 
338  LOG_DEBUG_IO("runtest: %i, end in %s",
339  cmd->cmd.runtest->num_cycles,
341 }
342 
344 {
345  LOG_DEBUG_IO("statemove end in %s",
346  tap_state_name(cmd->cmd.statemove->end_state));
347 
348  ftdi_end_state(cmd->cmd.statemove->end_state);
349 
350  /* shortest-path move to desired end state */
353 }
354 
359 static void ftdi_execute_tms(struct jtag_command *cmd)
360 {
361  LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits);
362 
363  /* TODO: Missing tap state tracking, also missing from ft2232.c! */
365  cmd->cmd.tms->bits,
366  0,
367  cmd->cmd.tms->num_bits,
368  false,
370 }
371 
373 {
374  tap_state_t *path = cmd->cmd.pathmove->path;
375  int num_states = cmd->cmd.pathmove->num_states;
376 
377  LOG_DEBUG_IO("pathmove: %i states, current: %s end: %s", num_states,
379  tap_state_name(path[num_states-1]));
380 
381  int state_count = 0;
382  unsigned bit_count = 0;
383  uint8_t tms_byte = 0;
384 
385  LOG_DEBUG_IO("-");
386 
387  /* this loop verifies that the path is legal and logs each state in the path */
388  while (num_states--) {
389 
390  /* either TMS=0 or TMS=1 must work ... */
391  if (tap_state_transition(tap_get_state(), false)
392  == path[state_count])
393  buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
394  else if (tap_state_transition(tap_get_state(), true)
395  == path[state_count]) {
396  buf_set_u32(&tms_byte, bit_count++, 1, 0x1);
397 
398  /* ... or else the caller goofed BADLY */
399  } else {
400  LOG_ERROR("BUG: %s -> %s isn't a valid "
401  "TAP state transition",
403  tap_state_name(path[state_count]));
404  exit(-1);
405  }
406 
407  tap_set_state(path[state_count]);
408  state_count++;
409 
410  if (bit_count == 7 || num_states == 0) {
412  &tms_byte,
413  0,
414  bit_count,
415  false,
417  bit_count = 0;
418  }
419  }
421 }
422 
423 static void ftdi_execute_scan(struct jtag_command *cmd)
424 {
425  LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
426  jtag_scan_type(cmd->cmd.scan));
427 
428  /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */
429  while (cmd->cmd.scan->num_fields > 0
430  && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) {
431  cmd->cmd.scan->num_fields--;
432  LOG_DEBUG_IO("discarding trailing empty field");
433  }
434 
435  if (cmd->cmd.scan->num_fields == 0) {
436  LOG_DEBUG_IO("empty scan, doing nothing");
437  return;
438  }
439 
440  if (cmd->cmd.scan->ir_scan) {
441  if (tap_get_state() != TAP_IRSHIFT)
443  } else {
444  if (tap_get_state() != TAP_DRSHIFT)
446  }
447 
448  ftdi_end_state(cmd->cmd.scan->end_state);
449 
450  struct scan_field *field = cmd->cmd.scan->fields;
451  unsigned scan_size = 0;
452 
453  for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) {
454  scan_size += field->num_bits;
455  LOG_DEBUG_IO("%s%s field %d/%d %d bits",
456  field->in_value ? "in" : "",
457  field->out_value ? "out" : "",
458  i,
459  cmd->cmd.scan->num_fields,
460  field->num_bits);
461 
462  if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) {
463  /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap
464  * movement. This last field can't have length zero, it was checked above. */
466  field->out_value,
467  0,
468  field->in_value,
469  0,
470  field->num_bits - 1,
472  uint8_t last_bit = 0;
473  if (field->out_value)
474  bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
475 
476  /* If endstate is TAP_IDLE, clock out 1-1-0 (->EXIT1 ->UPDATE ->IDLE)
477  * Otherwise, clock out 1-0 (->EXIT1 ->PAUSE)
478  */
479  uint8_t tms_bits = 0x03;
481  &tms_bits,
482  0,
483  field->in_value,
484  field->num_bits - 1,
485  1,
486  last_bit,
489  if (tap_get_end_state() == TAP_IDLE) {
491  &tms_bits,
492  1,
493  2,
494  last_bit,
498  } else {
500  &tms_bits,
501  2,
502  1,
503  last_bit,
506  }
507  } else
509  field->out_value,
510  0,
511  field->in_value,
512  0,
513  field->num_bits,
515  }
516 
517  if (tap_get_state() != tap_get_end_state())
519 
520  LOG_DEBUG_IO("%s scan, %i bits, end in %s",
521  (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
523 }
524 
525 static int ftdi_reset(int trst, int srst)
526 {
527  struct signal *sig_ntrst = find_signal_by_name("nTRST");
528  struct signal *sig_nsrst = find_signal_by_name("nSRST");
529 
530  LOG_DEBUG_IO("reset trst: %i srst %i", trst, srst);
531 
532  if (!swd_mode) {
533  if (trst == 1) {
534  if (sig_ntrst)
535  ftdi_set_signal(sig_ntrst, '0');
536  else
537  LOG_ERROR("Can't assert TRST: nTRST signal is not defined");
538  } else if (sig_ntrst && jtag_get_reset_config() & RESET_HAS_TRST &&
539  trst == 0) {
541  ftdi_set_signal(sig_ntrst, 'z');
542  else
543  ftdi_set_signal(sig_ntrst, '1');
544  }
545  }
546 
547  if (srst == 1) {
548  if (sig_nsrst)
549  ftdi_set_signal(sig_nsrst, '0');
550  else
551  LOG_ERROR("Can't assert SRST: nSRST signal is not defined");
552  } else if (sig_nsrst && jtag_get_reset_config() & RESET_HAS_SRST &&
553  srst == 0) {
555  ftdi_set_signal(sig_nsrst, '1');
556  else
557  ftdi_set_signal(sig_nsrst, 'z');
558  }
559 
560  return mpsse_flush(mpsse_ctx);
561 }
562 
563 static void ftdi_execute_sleep(struct jtag_command *cmd)
564 {
565  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
566 
568  jtag_sleep(cmd->cmd.sleep->us);
569  LOG_DEBUG_IO("sleep %" PRIu32 " usec while in %s",
570  cmd->cmd.sleep->us,
572 }
573 
575 {
576  /* this is only allowed while in a stable state. A check for a stable
577  * state was done in jtag_add_clocks()
578  */
579  int num_cycles = cmd->cmd.stableclocks->num_cycles;
580 
581  /* 7 bits of either ones or zeros. */
582  uint8_t tms = tap_get_state() == TAP_RESET ? 0x7f : 0x00;
583 
584  /* TODO: Use mpsse_clock_data with in=out=0 for this, if TMS can be set to
585  * the correct level and remain there during the scan */
586  while (num_cycles > 0) {
587  /* there are no state transitions in this code, so omit state tracking */
588  unsigned this_len = num_cycles > 7 ? 7 : num_cycles;
589  mpsse_clock_tms_cs_out(mpsse_ctx, &tms, 0, this_len, false, ftdi_jtag_mode);
590  num_cycles -= this_len;
591  }
592 
593  LOG_DEBUG_IO("clocks %i while in %s",
594  cmd->cmd.stableclocks->num_cycles,
596 }
597 
599 {
600  switch (cmd->type) {
601  case JTAG_RUNTEST:
603  break;
604  case JTAG_TLR_RESET:
606  break;
607  case JTAG_PATHMOVE:
609  break;
610  case JTAG_SCAN:
612  break;
613  case JTAG_SLEEP:
615  break;
616  case JTAG_STABLECLOCKS:
618  break;
619  case JTAG_TMS:
621  break;
622  default:
623  LOG_ERROR("BUG: unknown JTAG command type encountered: %d", cmd->type);
624  break;
625  }
626 }
627 
628 static int ftdi_execute_queue(struct jtag_command *cmd_queue)
629 {
630  /* blink, if the current layout has that feature */
631  struct signal *led = find_signal_by_name("LED");
632  if (led)
633  ftdi_set_signal(led, '1');
634 
635  for (struct jtag_command *cmd = cmd_queue; cmd; cmd = cmd->next) {
636  /* fill the write buffer with the desired command */
638  }
639 
640  if (led)
641  ftdi_set_signal(led, '0');
642 
643  int retval = mpsse_flush(mpsse_ctx);
644  if (retval != ERROR_OK)
645  LOG_ERROR("error while flushing MPSSE queue: %d", retval);
646 
647  return retval;
648 }
649 
650 static int ftdi_initialize(void)
651 {
653  LOG_DEBUG("ftdi interface using 7 step jtag state transitions");
654  else
655  LOG_DEBUG("ftdi interface using shortest path jtag state transitions");
656 
657  if (!ftdi_vid[0] && !ftdi_pid[0]) {
658  LOG_ERROR("Please specify ftdi vid_pid");
659  return ERROR_JTAG_INIT_FAILED;
660  }
661 
664  if (!mpsse_ctx)
665  return ERROR_JTAG_INIT_FAILED;
666 
669 
670  if (swd_mode) {
671  struct signal *sig = find_signal_by_name("SWD_EN");
672  if (!sig) {
673  LOG_ERROR("SWD mode is active but SWD_EN signal is not defined");
674  return ERROR_JTAG_INIT_FAILED;
675  }
676  /* A dummy SWD_EN would have zero mask */
677  if (sig->data_mask)
678  ftdi_set_signal(sig, '1');
679  }
680 
683 
685 
687 
688  return mpsse_flush(mpsse_ctx);
689 }
690 
691 static int ftdi_quit(void)
692 {
694 
695  struct signal *sig = signals;
696  while (sig) {
697  struct signal *next = sig->next;
698  free((void *)sig->name);
699  free(sig);
700  sig = next;
701  }
702 
703  free(ftdi_device_desc);
704 
705  free(swd_cmd_queue);
706 
707  return ERROR_OK;
708 }
709 
710 COMMAND_HANDLER(ftdi_handle_device_desc_command)
711 {
712  if (CMD_ARGC == 1) {
713  free(ftdi_device_desc);
714  ftdi_device_desc = strdup(CMD_ARGV[0]);
715  } else {
716  LOG_ERROR("expected exactly one argument to ftdi device_desc <description>");
717  }
718 
719  return ERROR_OK;
720 }
721 
722 COMMAND_HANDLER(ftdi_handle_channel_command)
723 {
724  if (CMD_ARGC == 1)
726  else
728 
729  return ERROR_OK;
730 }
731 
732 COMMAND_HANDLER(ftdi_handle_layout_init_command)
733 {
734  if (CMD_ARGC != 2)
736 
739 
740  return ERROR_OK;
741 }
742 
743 COMMAND_HANDLER(ftdi_handle_layout_signal_command)
744 {
745  if (CMD_ARGC < 1)
747 
748  bool invert_data = false;
749  uint16_t data_mask = 0;
750  bool invert_input = false;
751  uint16_t input_mask = 0;
752  bool invert_oe = false;
753  uint16_t oe_mask = 0;
754  for (unsigned i = 1; i < CMD_ARGC; i += 2) {
755  if (strcmp("-data", CMD_ARGV[i]) == 0) {
756  invert_data = false;
758  } else if (strcmp("-ndata", CMD_ARGV[i]) == 0) {
759  invert_data = true;
761  } else if (strcmp("-input", CMD_ARGV[i]) == 0) {
762  invert_input = false;
764  } else if (strcmp("-ninput", CMD_ARGV[i]) == 0) {
765  invert_input = true;
767  } else if (strcmp("-oe", CMD_ARGV[i]) == 0) {
768  invert_oe = false;
769  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], oe_mask);
770  } else if (strcmp("-noe", CMD_ARGV[i]) == 0) {
771  invert_oe = true;
772  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], oe_mask);
773  } else if (!strcmp("-alias", CMD_ARGV[i]) ||
774  !strcmp("-nalias", CMD_ARGV[i])) {
775  if (!strcmp("-nalias", CMD_ARGV[i])) {
776  invert_data = true;
777  invert_input = true;
778  }
779  struct signal *sig = find_signal_by_name(CMD_ARGV[i + 1]);
780  if (!sig) {
781  LOG_ERROR("signal %s is not defined", CMD_ARGV[i + 1]);
782  return ERROR_FAIL;
783  }
784  data_mask = sig->data_mask;
785  input_mask = sig->input_mask;
786  oe_mask = sig->oe_mask;
787  invert_input ^= sig->invert_input;
788  invert_oe = sig->invert_oe;
789  invert_data ^= sig->invert_data;
790  } else {
791  LOG_ERROR("unknown option '%s'", CMD_ARGV[i]);
793  }
794  }
795 
796  struct signal *sig;
797  sig = find_signal_by_name(CMD_ARGV[0]);
798  if (!sig)
799  sig = create_signal(CMD_ARGV[0]);
800  if (!sig) {
801  LOG_ERROR("failed to create signal %s", CMD_ARGV[0]);
802  return ERROR_FAIL;
803  }
804 
805  sig->invert_data = invert_data;
806  sig->data_mask = data_mask;
807  sig->invert_input = invert_input;
808  sig->input_mask = input_mask;
809  sig->invert_oe = invert_oe;
810  sig->oe_mask = oe_mask;
811 
812  return ERROR_OK;
813 }
814 
815 COMMAND_HANDLER(ftdi_handle_set_signal_command)
816 {
817  if (CMD_ARGC < 2)
819 
820  struct signal *sig;
821  sig = find_signal_by_name(CMD_ARGV[0]);
822  if (!sig) {
823  LOG_ERROR("interface configuration doesn't define signal '%s'", CMD_ARGV[0]);
824  return ERROR_FAIL;
825  }
826 
827  switch (*CMD_ARGV[1]) {
828  case '0':
829  case '1':
830  case 'z':
831  case 'Z':
832  /* single character level specifier only */
833  if (CMD_ARGV[1][1] == '\0') {
834  ftdi_set_signal(sig, *CMD_ARGV[1]);
835  break;
836  }
837  /* fallthrough */
838  default:
839  LOG_ERROR("unknown signal level '%s', use 0, 1 or z", CMD_ARGV[1]);
841  }
842 
843  return mpsse_flush(mpsse_ctx);
844 }
845 
846 COMMAND_HANDLER(ftdi_handle_get_signal_command)
847 {
848  if (CMD_ARGC < 1)
850 
851  struct signal *sig;
852  uint16_t sig_data = 0;
853  sig = find_signal_by_name(CMD_ARGV[0]);
854  if (!sig) {
855  LOG_ERROR("interface configuration doesn't define signal '%s'", CMD_ARGV[0]);
856  return ERROR_FAIL;
857  }
858 
859  int ret = ftdi_get_signal(sig, &sig_data);
860  if (ret != ERROR_OK)
861  return ret;
862 
863  LOG_USER("Signal %s = %#06x", sig->name, sig_data);
864 
865  return ERROR_OK;
866 }
867 
868 COMMAND_HANDLER(ftdi_handle_vid_pid_command)
869 {
870  if (CMD_ARGC > MAX_USB_IDS * 2) {
871  LOG_WARNING("ignoring extra IDs in ftdi vid_pid "
872  "(maximum is %d pairs)", MAX_USB_IDS);
873  CMD_ARGC = MAX_USB_IDS * 2;
874  }
875  if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
876  LOG_WARNING("incomplete ftdi vid_pid configuration directive");
877  if (CMD_ARGC < 2)
879  /* remove the incomplete trailing id */
880  CMD_ARGC -= 1;
881  }
882 
883  unsigned i;
884  for (i = 0; i < CMD_ARGC; i += 2) {
885  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], ftdi_vid[i >> 1]);
886  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], ftdi_pid[i >> 1]);
887  }
888 
889  /*
890  * Explicitly terminate, in case there are multiples instances of
891  * ftdi vid_pid.
892  */
893  ftdi_vid[i >> 1] = ftdi_pid[i >> 1] = 0;
894 
895  return ERROR_OK;
896 }
897 
898 COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
899 {
900  const struct nvp *n;
901  static const struct nvp nvp_ftdi_jtag_modes[] = {
902  { .name = "rising", .value = JTAG_MODE },
903  { .name = "falling", .value = JTAG_MODE_ALT },
904  { .name = NULL, .value = -1 },
905  };
906 
907  if (CMD_ARGC > 0) {
908  n = nvp_name2value(nvp_ftdi_jtag_modes, CMD_ARGV[0]);
909  if (!n->name)
911  ftdi_jtag_mode = n->value;
912 
913  }
914 
915  n = nvp_value2name(nvp_ftdi_jtag_modes, ftdi_jtag_mode);
916  command_print(CMD, "ftdi samples TDO on %s edge of TCK", n->name);
917 
918  return ERROR_OK;
919 }
920 
921 static const struct command_registration ftdi_subcommand_handlers[] = {
922  {
923  .name = "device_desc",
924  .handler = &ftdi_handle_device_desc_command,
925  .mode = COMMAND_CONFIG,
926  .help = "set the USB device description of the FTDI device",
927  .usage = "description_string",
928  },
929  {
930  .name = "channel",
931  .handler = &ftdi_handle_channel_command,
932  .mode = COMMAND_CONFIG,
933  .help = "set the channel of the FTDI device that is used as JTAG",
934  .usage = "(0-3)",
935  },
936  {
937  .name = "layout_init",
938  .handler = &ftdi_handle_layout_init_command,
939  .mode = COMMAND_CONFIG,
940  .help = "initialize the FTDI GPIO signals used "
941  "to control output-enables and reset signals",
942  .usage = "data direction",
943  },
944  {
945  .name = "layout_signal",
946  .handler = &ftdi_handle_layout_signal_command,
947  .mode = COMMAND_ANY,
948  .help = "define a signal controlled by one or more FTDI GPIO as data "
949  "and/or output enable",
950  .usage = "name [-data mask|-ndata mask] [-oe mask|-noe mask] [-alias|-nalias name]",
951  },
952  {
953  .name = "set_signal",
954  .handler = &ftdi_handle_set_signal_command,
955  .mode = COMMAND_EXEC,
956  .help = "control a layout-specific signal",
957  .usage = "name (1|0|z)",
958  },
959  {
960  .name = "get_signal",
961  .handler = &ftdi_handle_get_signal_command,
962  .mode = COMMAND_EXEC,
963  .help = "read the value of a layout-specific signal",
964  .usage = "name",
965  },
966  {
967  .name = "vid_pid",
968  .handler = &ftdi_handle_vid_pid_command,
969  .mode = COMMAND_CONFIG,
970  .help = "the vendor ID and product ID of the FTDI device",
971  .usage = "(vid pid)*",
972  },
973  {
974  .name = "tdo_sample_edge",
975  .handler = &ftdi_handle_tdo_sample_edge_command,
976  .mode = COMMAND_ANY,
977  .help = "set which TCK clock edge is used for sampling TDO "
978  "- default is rising-edge (Setting to falling-edge may "
979  "allow signalling speed increase)",
980  .usage = "(rising|falling)",
981  },
983 };
984 
985 static const struct command_registration ftdi_command_handlers[] = {
986  {
987  .name = "ftdi",
988  .mode = COMMAND_ANY,
989  .help = "perform ftdi management",
990  .chain = ftdi_subcommand_handlers,
991  .usage = "",
992  },
994 };
995 
996 static int create_default_signal(const char *name, uint16_t data_mask)
997 {
998  struct signal *sig = create_signal(name);
999  if (!sig) {
1000  LOG_ERROR("failed to create signal %s", name);
1001  return ERROR_FAIL;
1002  }
1003  sig->invert_data = false;
1004  sig->data_mask = data_mask;
1005  sig->invert_oe = false;
1006  sig->oe_mask = 0;
1007 
1008  return ERROR_OK;
1009 }
1010 
1011 static int create_signals(void)
1012 {
1013  if (create_default_signal("TCK", 0x01) != ERROR_OK)
1014  return ERROR_FAIL;
1015  if (create_default_signal("TDI", 0x02) != ERROR_OK)
1016  return ERROR_FAIL;
1017  if (create_default_signal("TDO", 0x04) != ERROR_OK)
1018  return ERROR_FAIL;
1019  if (create_default_signal("TMS", 0x08) != ERROR_OK)
1020  return ERROR_FAIL;
1021  return ERROR_OK;
1022 }
1023 
1024 static int ftdi_swd_init(void)
1025 {
1026  LOG_INFO("FTDI SWD mode enabled");
1027  swd_mode = true;
1028 
1029  if (create_signals() != ERROR_OK)
1030  return ERROR_FAIL;
1031 
1032  swd_cmd_queue_alloced = 10;
1033  swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue));
1034 
1035  return swd_cmd_queue ? ERROR_OK : ERROR_FAIL;
1036 }
1037 
1038 static void ftdi_swd_swdio_en(bool enable)
1039 {
1040  struct signal *oe = find_signal_by_name("SWDIO_OE");
1041  if (oe) {
1042  if (oe->data_mask)
1043  ftdi_set_signal(oe, enable ? '1' : '0');
1044  else {
1045  /* Sets TDI/DO pin to input during rx when both pins are connected
1046  to SWDIO */
1047  if (enable)
1048  direction |= jtag_direction_init & 0x0002U;
1049  else
1050  direction &= ~0x0002U;
1052  }
1053  }
1054 }
1055 
1060 static int ftdi_swd_run_queue(void)
1061 {
1062  LOG_DEBUG_IO("Executing %zu queued transactions", swd_cmd_queue_length);
1063  int retval;
1064  struct signal *led = find_signal_by_name("LED");
1065 
1066  if (queued_retval != ERROR_OK) {
1067  LOG_DEBUG_IO("Skipping due to previous errors: %d", queued_retval);
1068  goto skip;
1069  }
1070 
1071  /* A transaction must be followed by another transaction or at least 8 idle cycles to
1072  * ensure that data is clocked through the AP. */
1074 
1075  /* Terminate the "blink", if the current layout has that feature */
1076  if (led)
1077  ftdi_set_signal(led, '0');
1078 
1080  if (queued_retval != ERROR_OK) {
1081  LOG_ERROR("MPSSE failed");
1082  goto skip;
1083  }
1084 
1085  for (size_t i = 0; i < swd_cmd_queue_length; i++) {
1086  int ack = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1, 3);
1087 
1088  /* Devices do not reply to DP_TARGETSEL write cmd, ignore received ack */
1089  bool check_ack = swd_cmd_returns_ack(swd_cmd_queue[i].cmd);
1090 
1091  LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK) ? LOG_LVL_DEBUG : LOG_LVL_DEBUG_IO,
1092  "%s%s %s %s reg %X = %08" PRIx32,
1093  check_ack ? "" : "ack ignored ",
1094  ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
1095  swd_cmd_queue[i].cmd & SWD_CMD_APNDP ? "AP" : "DP",
1096  swd_cmd_queue[i].cmd & SWD_CMD_RNW ? "read" : "write",
1097  (swd_cmd_queue[i].cmd & SWD_CMD_A32) >> 1,
1098  buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn,
1099  1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RNW ? 0 : 1), 32));
1100 
1101  if (ack != SWD_ACK_OK && check_ack) {
1103  goto skip;
1104 
1105  } else if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) {
1106  uint32_t data = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3, 32);
1107  int parity = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 32, 1);
1108 
1109  if (parity != parity_u32(data)) {
1110  LOG_ERROR("SWD Read data parity mismatch");
1112  goto skip;
1113  }
1114 
1115  if (swd_cmd_queue[i].dst)
1116  *swd_cmd_queue[i].dst = data;
1117  }
1118  }
1119 
1120 skip:
1122  retval = queued_retval;
1124 
1125  /* Queue a new "blink" */
1126  if (led && retval == ERROR_OK)
1127  ftdi_set_signal(led, '1');
1128 
1129  return retval;
1130 }
1131 
1132 static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
1133 {
1135  /* Not enough room in the queue. Run the queue and increase its size for next time.
1136  * Note that it's not possible to avoid running the queue here, because mpsse contains
1137  * pointers into the queue which may be invalid after the realloc. */
1139  struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue));
1140  if (q) {
1141  swd_cmd_queue = q;
1142  swd_cmd_queue_alloced *= 2;
1143  LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);
1144  }
1145  }
1146 
1147  if (queued_retval != ERROR_OK)
1148  return;
1149 
1150  size_t i = swd_cmd_queue_length++;
1152 
1154 
1155  if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) {
1156  /* Queue a read transaction */
1157  swd_cmd_queue[i].dst = dst;
1158 
1159  ftdi_swd_swdio_en(false);
1161  0, 1 + 3 + 32 + 1 + 1, SWD_MODE);
1162  ftdi_swd_swdio_en(true);
1163  } else {
1164  /* Queue a write transaction */
1165  ftdi_swd_swdio_en(false);
1166 
1168  0, 1 + 3 + 1, SWD_MODE);
1169 
1170  ftdi_swd_swdio_en(true);
1171 
1172  buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1, 32, data);
1173  buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1 + 32, 1, parity_u32(data));
1174 
1176  1 + 3 + 1, 32 + 1, SWD_MODE);
1177  }
1178 
1179  /* Insert idle cycles after AP accesses to avoid WAIT */
1180  if (cmd & SWD_CMD_APNDP)
1181  mpsse_clock_data_out(mpsse_ctx, NULL, 0, ap_delay_clk, SWD_MODE);
1182 
1183 }
1184 
1185 static void ftdi_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
1186 {
1187  assert(cmd & SWD_CMD_RNW);
1188  ftdi_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
1189 }
1190 
1191 static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
1192 {
1193  assert(!(cmd & SWD_CMD_RNW));
1194  ftdi_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
1195 }
1196 
1198 {
1199  switch (seq) {
1200  case LINE_RESET:
1201  LOG_DEBUG("SWD line reset");
1202  ftdi_swd_swdio_en(true);
1204  break;
1205  case JTAG_TO_SWD:
1206  LOG_DEBUG("JTAG-to-SWD");
1207  ftdi_swd_swdio_en(true);
1209  break;
1210  case JTAG_TO_DORMANT:
1211  LOG_DEBUG("JTAG-to-DORMANT");
1212  ftdi_swd_swdio_en(true);
1214  break;
1215  case SWD_TO_JTAG:
1216  LOG_DEBUG("SWD-to-JTAG");
1217  ftdi_swd_swdio_en(true);
1219  break;
1220  case SWD_TO_DORMANT:
1221  LOG_DEBUG("SWD-to-DORMANT");
1222  ftdi_swd_swdio_en(true);
1224  break;
1225  case DORMANT_TO_SWD:
1226  LOG_DEBUG("DORMANT-to-SWD");
1227  ftdi_swd_swdio_en(true);
1229  break;
1230  case DORMANT_TO_JTAG:
1231  LOG_DEBUG("DORMANT-to-JTAG");
1232  ftdi_swd_swdio_en(true);
1234  break;
1235  default:
1236  LOG_ERROR("Sequence %d not supported", seq);
1237  return ERROR_FAIL;
1238  }
1239 
1240  return ERROR_OK;
1241 }
1242 
1243 static const struct swd_driver ftdi_swd = {
1244  .init = ftdi_swd_init,
1245  .switch_seq = ftdi_swd_switch_seq,
1246  .read_reg = ftdi_swd_read_reg,
1247  .write_reg = ftdi_swd_write_reg,
1248  .run = ftdi_swd_run_queue,
1249 };
1250 
1251 static const char * const ftdi_transports[] = { "jtag", "swd", NULL };
1252 
1253 static struct jtag_interface ftdi_interface = {
1255  .execute_queue = ftdi_execute_queue,
1256 };
1257 
1259  .name = "ftdi",
1260  .transports = ftdi_transports,
1261  .commands = ftdi_command_handlers,
1262 
1263  .init = ftdi_initialize,
1264  .quit = ftdi_quit,
1265  .reset = ftdi_reset,
1266  .speed = ftdi_speed,
1267  .khz = ftdi_khz,
1268  .speed_div = ftdi_speed_div,
1269 
1270  .jtag_ops = &ftdi_interface,
1271  .swd_ops = &ftdi_swd,
1272 };
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
Definition: adapter.c:298
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
Definition: adapter.c:207
const char * adapter_usb_get_location(void)
Definition: adapter.c:324
#define SWD_ACK_FAULT
Definition: arm_adi_v5.h:33
swd_special_seq
Definition: arm_adi_v5.h:236
@ DORMANT_TO_JTAG
Definition: arm_adi_v5.h:243
@ JTAG_TO_SWD
Definition: arm_adi_v5.h:238
@ DORMANT_TO_SWD
Definition: arm_adi_v5.h:242
@ LINE_RESET
Definition: arm_adi_v5.h:237
@ JTAG_TO_DORMANT
Definition: arm_adi_v5.h:239
@ SWD_TO_DORMANT
Definition: arm_adi_v5.h:241
@ SWD_TO_JTAG
Definition: arm_adi_v5.h:240
#define SWD_ACK_WAIT
Definition: arm_adi_v5.h:32
#define SWD_ACK_OK
Definition: arm_adi_v5.h:31
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:202
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:99
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:31
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#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:442
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:404
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:167
@ 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
static uint16_t output
Definition: ftdi.c:119
COMMAND_HANDLER(ftdi_handle_device_desc_command)
Definition: ftdi.c:710
static uint8_t ftdi_channel
Definition: ftdi.c:83
static const struct command_registration ftdi_command_handlers[]
Definition: ftdi.c:985
static void ftdi_swd_swdio_en(bool enable)
Definition: ftdi.c:1038
static int queued_retval
Definition: ftdi.c:116
static void ftdi_execute_sleep(struct jtag_command *cmd)
Definition: ftdi.c:563
static struct signal * create_signal(const char *name)
Definition: ftdi.c:135
static void ftdi_execute_stableclocks(struct jtag_command *cmd)
Definition: ftdi.c:574
static void ftdi_execute_pathmove(struct jtag_command *cmd)
Definition: ftdi.c:372
static int ftdi_swd_init(void)
Definition: ftdi.c:1024
static uint16_t direction
Definition: ftdi.c:120
static char * ftdi_device_desc
Definition: ftdi.c:82
static void ftdi_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: ftdi.c:1185
static struct jtag_interface ftdi_interface
Definition: ftdi.c:1253
#define JTAG_MODE
Definition: ftdi.c:78
static uint16_t jtag_output_init
Definition: ftdi.c:121
static int ftdi_speed(int speed)
Definition: ftdi.c:269
static int ftdi_get_signal(const struct signal *s, uint16_t *value_out)
Definition: ftdi.c:206
static bool swd_mode
Definition: ftdi.c:86
static size_t swd_cmd_queue_length
Definition: ftdi.c:114
struct adapter_driver ftdi_adapter_driver
Definition: ftdi.c:1258
static const struct swd_driver ftdi_swd
Definition: ftdi.c:1243
static struct mpsse_ctx * mpsse_ctx
Definition: ftdi.c:93
static void ftdi_execute_tms(struct jtag_command *cmd)
Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine.
Definition: ftdi.c:359
#define MAX_USB_IDS
Definition: ftdi.c:88
static size_t swd_cmd_queue_alloced
Definition: ftdi.c:115
static const char *const ftdi_transports[]
Definition: ftdi.c:1251
static int ftdi_reset(int trst, int srst)
Definition: ftdi.c:525
static int ftdi_khz(int khz, int *jtag_speed)
Definition: ftdi.c:291
static int ftdi_speed_div(int speed, int *khz)
Definition: ftdi.c:285
static uint16_t ftdi_pid[MAX_USB_IDS+1]
Definition: ftdi.c:91
static int ftdi_execute_queue(struct jtag_command *cmd_queue)
Definition: ftdi.c:628
static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
Definition: ftdi.c:1132
static int ftdi_swd_run_queue(void)
Flush the MPSSE queue and process the SWD transaction queue.
Definition: ftdi.c:1060
#define JTAG_MODE_ALT
Definition: ftdi.c:79
static uint16_t jtag_direction_init
Definition: ftdi.c:122
static struct signal * find_signal_by_name(const char *name)
Definition: ftdi.c:126
static int ftdi_initialize(void)
Definition: ftdi.c:650
static int ftdi_quit(void)
Definition: ftdi.c:691
#define SWD_MODE
Definition: ftdi.c:80
static void ftdi_end_state(tap_state_t state)
Definition: ftdi.c:302
static void move_to_state(tap_state_t goal_state)
Function move_to_state moves the TAP controller from the current state to a goal_state through a path...
Definition: ftdi.c:241
static void ftdi_execute_statemove(struct jtag_command *cmd)
Definition: ftdi.c:343
static int create_default_signal(const char *name, uint16_t data_mask)
Definition: ftdi.c:996
static void ftdi_execute_scan(struct jtag_command *cmd)
Definition: ftdi.c:423
static uint8_t ftdi_jtag_mode
Definition: ftdi.c:84
static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: ftdi.c:1191
static uint16_t ftdi_vid[MAX_USB_IDS+1]
Definition: ftdi.c:90
static int ftdi_swd_switch_seq(enum swd_special_seq seq)
Definition: ftdi.c:1197
static void ftdi_execute_runtest(struct jtag_command *cmd)
Definition: ftdi.c:312
static int freq
Definition: ftdi.c:117
static int create_signals(void)
Definition: ftdi.c:1011
static const struct command_registration ftdi_subcommand_handlers[]
Definition: ftdi.c:921
static int ftdi_set_signal(const struct signal *s, char value)
Definition: ftdi.c:153
static struct signal * signals
Definition: ftdi.c:106
static struct swd_cmd_queue_entry * swd_cmd_queue
static void ftdi_execute_command(struct jtag_command *cmd)
Definition: ftdi.c:598
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:187
#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
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1062
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1734
@ TAP_RESET
Definition: jtag.h:56
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
@ TAP_IRPAUSE
Definition: jtag.h:52
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:553
@ RESET_HAS_SRST
Definition: jtag.h:219
@ RESET_HAS_TRST
Definition: jtag.h:218
@ RESET_TRST_OPEN_DRAIN
Definition: jtag.h:223
@ RESET_SRST_PUSH_PULL
Definition: jtag.h:224
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_USER(expr ...)
Definition: log.h:135
#define LOG_CUSTOM_LEVEL(level, expr ...)
Definition: log.h:117
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define LOG_WARNING(expr ...)
Definition: log.h:129
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
@ LOG_LVL_DEBUG
Definition: log.h:47
@ LOG_LVL_DEBUG_IO
Definition: log.h:48
#define zero
Definition: mips32.c:165
int mpsse_flush(struct mpsse_ctx *ctx)
Definition: mpsse.c:845
void mpsse_clock_data_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, unsigned length, uint8_t mode)
Definition: mpsse.c:483
void mpsse_read_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t *data)
Definition: mpsse.c:673
void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
Definition: mpsse.c:640
int mpsse_set_frequency(struct mpsse_ctx *ctx, int frequency)
Definition: mpsse.c:748
void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data)
Definition: mpsse.c:657
void mpsse_clock_data_in(struct mpsse_ctx *ctx, uint8_t *in, unsigned in_offset, unsigned length, uint8_t mode)
Definition: mpsse.c:489
struct mpsse_ctx * mpsse_open(const uint16_t vids[], const uint16_t pids[], const char *description, const char *serial, const char *location, int channel)
Definition: mpsse.c:327
bool mpsse_is_high_speed(struct mpsse_ctx *ctx)
Definition: mpsse.c:416
void mpsse_close(struct mpsse_ctx *ctx)
Definition: mpsse.c:402
void mpsse_loopback_config(struct mpsse_ctx *ctx, bool enable)
Definition: mpsse.c:703
void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in, unsigned in_offset, unsigned length, bool tdi, uint8_t mode)
Definition: mpsse.c:572
void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
Definition: mpsse.c:623
void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, unsigned length, bool tdi, uint8_t mode)
Definition: mpsse.c:566
void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in, unsigned in_offset, unsigned length, uint8_t mode)
Definition: mpsse.c:495
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
Definition: nvp.c:29
const struct nvp * nvp_value2name(const struct nvp *p, int value)
Definition: nvp.c:39
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
const char * name
Definition: command.h:235
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241
Represents a driver for a debugging interface.
Definition: interface.h:182
unsigned supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:186
Name Value Pairs, aka: NVP.
Definition: nvp.h:61
int value
Definition: nvp.h:63
const char * name
Definition: nvp.h:62
This structure defines a single scan field in the scan.
Definition: jtag.h:87
int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:93
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:91
Definition: ftdi.c:95
struct signal * next
Definition: ftdi.c:103
bool invert_oe
Definition: ftdi.c:102
const char * name
Definition: ftdi.c:96
bool invert_data
Definition: ftdi.c:100
uint16_t input_mask
Definition: ftdi.c:98
uint16_t data_mask
Definition: ftdi.c:97
bool invert_input
Definition: ftdi.c:101
uint16_t oe_mask
Definition: ftdi.c:99
Definition: ftdi.c:109
uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4+3+32+1+4, 8)]
Definition: ftdi.c:112
uint8_t cmd
Definition: ftdi.c:110
uint32_t * dst
Definition: ftdi.c:111
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Definition: swd.h:255
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
static bool swd_cmd_returns_ack(uint8_t cmd)
Test if we can rely on ACK returned by SWD command.
Definition: swd.h:58
#define SWD_CMD_PARK
Definition: swd.h:22
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
Definition: swd.h:72
#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
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
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
Definition: types.h:265
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t state[4]
Definition: vdebug.c:21
static unsigned int parity(unsigned int v)
Definition: xscale.c:623