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  uint8_t zero = 0;
315 
316  LOG_DEBUG_IO("runtest %u cycles, end in %s",
317  cmd->cmd.runtest->num_cycles,
318  tap_state_name(cmd->cmd.runtest->end_state));
319 
320  if (tap_get_state() != TAP_IDLE)
322 
323  /* TODO: Reuse ftdi_execute_stableclocks */
324  unsigned int i = cmd->cmd.runtest->num_cycles;
325  while (i > 0) {
326  /* there are no state transitions in this code, so omit state tracking */
327  unsigned int this_len = i > 7 ? 7 : i;
328  mpsse_clock_tms_cs_out(mpsse_ctx, &zero, 0, this_len, false, ftdi_jtag_mode);
329  i -= this_len;
330  }
331 
332  ftdi_end_state(cmd->cmd.runtest->end_state);
333 
334  if (tap_get_state() != tap_get_end_state())
336 
337  LOG_DEBUG_IO("runtest: %u, end in %s",
338  cmd->cmd.runtest->num_cycles,
340 }
341 
343 {
344  LOG_DEBUG_IO("statemove end in %s",
345  tap_state_name(cmd->cmd.statemove->end_state));
346 
347  ftdi_end_state(cmd->cmd.statemove->end_state);
348 
349  /* shortest-path move to desired end state */
352 }
353 
358 static void ftdi_execute_tms(struct jtag_command *cmd)
359 {
360  LOG_DEBUG_IO("TMS: %u bits", cmd->cmd.tms->num_bits);
361 
362  /* TODO: Missing tap state tracking, also missing from ft2232.c! */
364  cmd->cmd.tms->bits,
365  0,
366  cmd->cmd.tms->num_bits,
367  false,
369 }
370 
372 {
373  tap_state_t *path = cmd->cmd.pathmove->path;
374  unsigned int num_states = cmd->cmd.pathmove->num_states;
375 
376  LOG_DEBUG_IO("pathmove: %u states, current: %s end: %s", num_states,
378  tap_state_name(path[num_states-1]));
379 
380  int state_count = 0;
381  unsigned int bit_count = 0;
382  uint8_t tms_byte = 0;
383 
384  LOG_DEBUG_IO("-");
385 
386  /* this loop verifies that the path is legal and logs each state in the path */
387  while (num_states--) {
388 
389  /* either TMS=0 or TMS=1 must work ... */
390  if (tap_state_transition(tap_get_state(), false)
391  == path[state_count])
392  buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
393  else if (tap_state_transition(tap_get_state(), true)
394  == path[state_count]) {
395  buf_set_u32(&tms_byte, bit_count++, 1, 0x1);
396 
397  /* ... or else the caller goofed BADLY */
398  } else {
399  LOG_ERROR("BUG: %s -> %s isn't a valid "
400  "TAP state transition",
402  tap_state_name(path[state_count]));
403  exit(-1);
404  }
405 
406  tap_set_state(path[state_count]);
407  state_count++;
408 
409  if (bit_count == 7 || num_states == 0) {
411  &tms_byte,
412  0,
413  bit_count,
414  false,
416  bit_count = 0;
417  }
418  }
420 }
421 
422 static void ftdi_execute_scan(struct jtag_command *cmd)
423 {
424  LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
425  jtag_scan_type(cmd->cmd.scan));
426 
427  /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */
428  while (cmd->cmd.scan->num_fields > 0
429  && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) {
430  cmd->cmd.scan->num_fields--;
431  LOG_DEBUG_IO("discarding trailing empty field");
432  }
433 
434  if (!cmd->cmd.scan->num_fields) {
435  LOG_DEBUG_IO("empty scan, doing nothing");
436  return;
437  }
438 
439  if (cmd->cmd.scan->ir_scan) {
440  if (tap_get_state() != TAP_IRSHIFT)
442  } else {
443  if (tap_get_state() != TAP_DRSHIFT)
445  }
446 
447  ftdi_end_state(cmd->cmd.scan->end_state);
448 
449  struct scan_field *field = cmd->cmd.scan->fields;
450  unsigned int scan_size = 0;
451 
452  for (unsigned int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) {
453  scan_size += field->num_bits;
454  LOG_DEBUG_IO("%s%s field %u/%u %u bits",
455  field->in_value ? "in" : "",
456  field->out_value ? "out" : "",
457  i,
458  cmd->cmd.scan->num_fields,
459  field->num_bits);
460 
461  if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) {
462  /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap
463  * movement. This last field can't have length zero, it was checked above. */
465  field->out_value,
466  0,
467  field->in_value,
468  0,
469  field->num_bits - 1,
471  uint8_t last_bit = 0;
472  if (field->out_value)
473  bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
474 
475  /* If endstate is TAP_IDLE, clock out 1-1-0 (->EXIT1 ->UPDATE ->IDLE)
476  * Otherwise, clock out 1-0 (->EXIT1 ->PAUSE)
477  */
478  uint8_t tms_bits = 0x03;
480  &tms_bits,
481  0,
482  field->in_value,
483  field->num_bits - 1,
484  1,
485  last_bit,
488  if (tap_get_end_state() == TAP_IDLE) {
490  &tms_bits,
491  1,
492  2,
493  last_bit,
497  } else {
499  &tms_bits,
500  2,
501  1,
502  last_bit,
505  }
506  } else
508  field->out_value,
509  0,
510  field->in_value,
511  0,
512  field->num_bits,
514  }
515 
516  if (tap_get_state() != tap_get_end_state())
518 
519  LOG_DEBUG_IO("%s scan, %i bits, end in %s",
520  (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
522 }
523 
524 static int ftdi_reset(int trst, int srst)
525 {
526  struct signal *sig_ntrst = find_signal_by_name("nTRST");
527  struct signal *sig_nsrst = find_signal_by_name("nSRST");
528 
529  LOG_DEBUG_IO("reset trst: %i srst %i", trst, srst);
530 
531  if (!swd_mode) {
532  if (trst == 1) {
533  if (sig_ntrst)
534  ftdi_set_signal(sig_ntrst, '0');
535  else
536  LOG_ERROR("Can't assert TRST: nTRST signal is not defined");
537  } else if (sig_ntrst && jtag_get_reset_config() & RESET_HAS_TRST &&
538  trst == 0) {
540  ftdi_set_signal(sig_ntrst, 'z');
541  else
542  ftdi_set_signal(sig_ntrst, '1');
543  }
544  }
545 
546  if (srst == 1) {
547  if (sig_nsrst)
548  ftdi_set_signal(sig_nsrst, '0');
549  else
550  LOG_ERROR("Can't assert SRST: nSRST signal is not defined");
551  } else if (sig_nsrst && jtag_get_reset_config() & RESET_HAS_SRST &&
552  srst == 0) {
554  ftdi_set_signal(sig_nsrst, '1');
555  else
556  ftdi_set_signal(sig_nsrst, 'z');
557  }
558 
559  return mpsse_flush(mpsse_ctx);
560 }
561 
562 static void ftdi_execute_sleep(struct jtag_command *cmd)
563 {
564  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
565 
567  jtag_sleep(cmd->cmd.sleep->us);
568  LOG_DEBUG_IO("sleep %" PRIu32 " usec while in %s",
569  cmd->cmd.sleep->us,
571 }
572 
574 {
575  /* this is only allowed while in a stable state. A check for a stable
576  * state was done in jtag_add_clocks()
577  */
578  unsigned int num_cycles = cmd->cmd.stableclocks->num_cycles;
579 
580  /* 7 bits of either ones or zeros. */
581  uint8_t tms = tap_get_state() == TAP_RESET ? 0x7f : 0x00;
582 
583  /* TODO: Use mpsse_clock_data with in=out=0 for this, if TMS can be set to
584  * the correct level and remain there during the scan */
585  while (num_cycles > 0) {
586  /* there are no state transitions in this code, so omit state tracking */
587  unsigned int this_len = num_cycles > 7 ? 7 : num_cycles;
588  mpsse_clock_tms_cs_out(mpsse_ctx, &tms, 0, this_len, false, ftdi_jtag_mode);
589  num_cycles -= this_len;
590  }
591 
592  LOG_DEBUG_IO("clocks %u while in %s",
593  cmd->cmd.stableclocks->num_cycles,
595 }
596 
598 {
599  switch (cmd->type) {
600  case JTAG_RUNTEST:
602  break;
603  case JTAG_TLR_RESET:
605  break;
606  case JTAG_PATHMOVE:
608  break;
609  case JTAG_SCAN:
611  break;
612  case JTAG_SLEEP:
614  break;
615  case JTAG_STABLECLOCKS:
617  break;
618  case JTAG_TMS:
620  break;
621  default:
622  LOG_ERROR("BUG: unknown JTAG command type encountered: %d", cmd->type);
623  break;
624  }
625 }
626 
627 static int ftdi_execute_queue(struct jtag_command *cmd_queue)
628 {
629  /* blink, if the current layout has that feature */
630  struct signal *led = find_signal_by_name("LED");
631  if (led)
632  ftdi_set_signal(led, '1');
633 
634  for (struct jtag_command *cmd = cmd_queue; cmd; cmd = cmd->next) {
635  /* fill the write buffer with the desired command */
637  }
638 
639  if (led)
640  ftdi_set_signal(led, '0');
641 
642  int retval = mpsse_flush(mpsse_ctx);
643  if (retval != ERROR_OK)
644  LOG_ERROR("error while flushing MPSSE queue: %d", retval);
645 
646  return retval;
647 }
648 
649 static int ftdi_initialize(void)
650 {
652  LOG_DEBUG("ftdi interface using 7 step jtag state transitions");
653  else
654  LOG_DEBUG("ftdi interface using shortest path jtag state transitions");
655 
656  if (!ftdi_vid[0] && !ftdi_pid[0]) {
657  LOG_ERROR("Please specify ftdi vid_pid");
658  return ERROR_JTAG_INIT_FAILED;
659  }
660 
663  if (!mpsse_ctx)
664  return ERROR_JTAG_INIT_FAILED;
665 
668 
669  if (swd_mode) {
670  struct signal *sig = find_signal_by_name("SWD_EN");
671  if (!sig) {
672  LOG_ERROR("SWD mode is active but SWD_EN signal is not defined");
673  return ERROR_JTAG_INIT_FAILED;
674  }
675  /* A dummy SWD_EN would have zero mask */
676  if (sig->data_mask)
677  ftdi_set_signal(sig, '1');
678  }
679 
682 
684 
686 
687  return mpsse_flush(mpsse_ctx);
688 }
689 
690 static int ftdi_quit(void)
691 {
693 
694  struct signal *sig = signals;
695  while (sig) {
696  struct signal *next = sig->next;
697  free((void *)sig->name);
698  free(sig);
699  sig = next;
700  }
701 
702  free(ftdi_device_desc);
703 
704  free(swd_cmd_queue);
705 
706  return ERROR_OK;
707 }
708 
709 COMMAND_HANDLER(ftdi_handle_device_desc_command)
710 {
711  if (CMD_ARGC == 1) {
712  free(ftdi_device_desc);
713  ftdi_device_desc = strdup(CMD_ARGV[0]);
714  } else {
715  LOG_ERROR("expected exactly one argument to ftdi device_desc <description>");
716  }
717 
718  return ERROR_OK;
719 }
720 
721 COMMAND_HANDLER(ftdi_handle_channel_command)
722 {
723  if (CMD_ARGC == 1)
725  else
727 
728  return ERROR_OK;
729 }
730 
731 COMMAND_HANDLER(ftdi_handle_layout_init_command)
732 {
733  if (CMD_ARGC != 2)
735 
738 
739  return ERROR_OK;
740 }
741 
742 COMMAND_HANDLER(ftdi_handle_layout_signal_command)
743 {
744  if (CMD_ARGC < 1)
746 
747  bool invert_data = false;
748  uint16_t data_mask = 0;
749  bool invert_input = false;
750  uint16_t input_mask = 0;
751  bool invert_oe = false;
752  uint16_t oe_mask = 0;
753  for (unsigned int i = 1; i < CMD_ARGC; i += 2) {
754  if (strcmp("-data", CMD_ARGV[i]) == 0) {
755  invert_data = false;
757  } else if (strcmp("-ndata", CMD_ARGV[i]) == 0) {
758  invert_data = true;
760  } else if (strcmp("-input", CMD_ARGV[i]) == 0) {
761  invert_input = false;
763  } else if (strcmp("-ninput", CMD_ARGV[i]) == 0) {
764  invert_input = true;
766  } else if (strcmp("-oe", CMD_ARGV[i]) == 0) {
767  invert_oe = false;
768  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], oe_mask);
769  } else if (strcmp("-noe", CMD_ARGV[i]) == 0) {
770  invert_oe = true;
771  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], oe_mask);
772  } else if (!strcmp("-alias", CMD_ARGV[i]) ||
773  !strcmp("-nalias", CMD_ARGV[i])) {
774  if (!strcmp("-nalias", CMD_ARGV[i])) {
775  invert_data = true;
776  invert_input = true;
777  }
778  struct signal *sig = find_signal_by_name(CMD_ARGV[i + 1]);
779  if (!sig) {
780  LOG_ERROR("signal %s is not defined", CMD_ARGV[i + 1]);
781  return ERROR_FAIL;
782  }
783  data_mask = sig->data_mask;
784  input_mask = sig->input_mask;
785  oe_mask = sig->oe_mask;
786  invert_input ^= sig->invert_input;
787  invert_oe = sig->invert_oe;
788  invert_data ^= sig->invert_data;
789  } else {
790  LOG_ERROR("unknown option '%s'", CMD_ARGV[i]);
792  }
793  }
794 
795  struct signal *sig;
796  sig = find_signal_by_name(CMD_ARGV[0]);
797  if (!sig)
798  sig = create_signal(CMD_ARGV[0]);
799  if (!sig) {
800  LOG_ERROR("failed to create signal %s", CMD_ARGV[0]);
801  return ERROR_FAIL;
802  }
803 
804  sig->invert_data = invert_data;
805  sig->data_mask = data_mask;
806  sig->invert_input = invert_input;
807  sig->input_mask = input_mask;
808  sig->invert_oe = invert_oe;
809  sig->oe_mask = oe_mask;
810 
811  return ERROR_OK;
812 }
813 
814 COMMAND_HANDLER(ftdi_handle_set_signal_command)
815 {
816  if (CMD_ARGC < 2)
818 
819  struct signal *sig;
820  sig = find_signal_by_name(CMD_ARGV[0]);
821  if (!sig) {
822  LOG_ERROR("interface configuration doesn't define signal '%s'", CMD_ARGV[0]);
823  return ERROR_FAIL;
824  }
825 
826  switch (*CMD_ARGV[1]) {
827  case '0':
828  case '1':
829  case 'z':
830  case 'Z':
831  /* single character level specifier only */
832  if (CMD_ARGV[1][1] == '\0') {
833  ftdi_set_signal(sig, *CMD_ARGV[1]);
834  break;
835  }
836  /* fallthrough */
837  default:
838  LOG_ERROR("unknown signal level '%s', use 0, 1 or z", CMD_ARGV[1]);
840  }
841 
842  return mpsse_flush(mpsse_ctx);
843 }
844 
845 COMMAND_HANDLER(ftdi_handle_get_signal_command)
846 {
847  if (CMD_ARGC < 1)
849 
850  struct signal *sig;
851  uint16_t sig_data = 0;
852  sig = find_signal_by_name(CMD_ARGV[0]);
853  if (!sig) {
854  command_print(CMD, "interface configuration doesn't define signal '%s'", CMD_ARGV[0]);
855  return ERROR_FAIL;
856  }
857 
858  int ret = ftdi_get_signal(sig, &sig_data);
859  if (ret != ERROR_OK)
860  return ret;
861 
862  command_print(CMD, "%#06x", sig_data);
863 
864  return ERROR_OK;
865 }
866 
867 COMMAND_HANDLER(ftdi_handle_vid_pid_command)
868 {
869  if (CMD_ARGC > MAX_USB_IDS * 2) {
870  LOG_WARNING("ignoring extra IDs in ftdi vid_pid "
871  "(maximum is %d pairs)", MAX_USB_IDS);
872  CMD_ARGC = MAX_USB_IDS * 2;
873  }
874  if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
875  LOG_WARNING("incomplete ftdi vid_pid configuration directive");
876  if (CMD_ARGC < 2)
878  /* remove the incomplete trailing id */
879  CMD_ARGC -= 1;
880  }
881 
882  unsigned int i;
883  for (i = 0; i < CMD_ARGC; i += 2) {
884  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], ftdi_vid[i >> 1]);
885  COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], ftdi_pid[i >> 1]);
886  }
887 
888  /*
889  * Explicitly terminate, in case there are multiples instances of
890  * ftdi vid_pid.
891  */
892  ftdi_vid[i >> 1] = ftdi_pid[i >> 1] = 0;
893 
894  return ERROR_OK;
895 }
896 
897 COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
898 {
899  const struct nvp *n;
900  static const struct nvp nvp_ftdi_jtag_modes[] = {
901  { .name = "rising", .value = JTAG_MODE },
902  { .name = "falling", .value = JTAG_MODE_ALT },
903  { .name = NULL, .value = -1 },
904  };
905 
906  if (CMD_ARGC > 0) {
907  n = nvp_name2value(nvp_ftdi_jtag_modes, CMD_ARGV[0]);
908  if (!n->name)
910  ftdi_jtag_mode = n->value;
911 
912  }
913 
914  n = nvp_value2name(nvp_ftdi_jtag_modes, ftdi_jtag_mode);
915  command_print(CMD, "ftdi samples TDO on %s edge of TCK", n->name);
916 
917  return ERROR_OK;
918 }
919 
920 static const struct command_registration ftdi_subcommand_handlers[] = {
921  {
922  .name = "device_desc",
923  .handler = &ftdi_handle_device_desc_command,
924  .mode = COMMAND_CONFIG,
925  .help = "set the USB device description of the FTDI device",
926  .usage = "description_string",
927  },
928  {
929  .name = "channel",
930  .handler = &ftdi_handle_channel_command,
931  .mode = COMMAND_CONFIG,
932  .help = "set the channel of the FTDI device that is used as JTAG",
933  .usage = "(0-3)",
934  },
935  {
936  .name = "layout_init",
937  .handler = &ftdi_handle_layout_init_command,
938  .mode = COMMAND_CONFIG,
939  .help = "initialize the FTDI GPIO signals used "
940  "to control output-enables and reset signals",
941  .usage = "data direction",
942  },
943  {
944  .name = "layout_signal",
945  .handler = &ftdi_handle_layout_signal_command,
946  .mode = COMMAND_ANY,
947  .help = "define a signal controlled by one or more FTDI GPIO as data "
948  "and/or output enable",
949  .usage = "name [-data mask|-ndata mask] [-oe mask|-noe mask] [-alias|-nalias name]",
950  },
951  {
952  .name = "set_signal",
953  .handler = &ftdi_handle_set_signal_command,
954  .mode = COMMAND_EXEC,
955  .help = "control a layout-specific signal",
956  .usage = "name (1|0|z)",
957  },
958  {
959  .name = "get_signal",
960  .handler = &ftdi_handle_get_signal_command,
961  .mode = COMMAND_EXEC,
962  .help = "read the value of a layout-specific signal",
963  .usage = "name",
964  },
965  {
966  .name = "vid_pid",
967  .handler = &ftdi_handle_vid_pid_command,
968  .mode = COMMAND_CONFIG,
969  .help = "the vendor ID and product ID of the FTDI device",
970  .usage = "(vid pid)*",
971  },
972  {
973  .name = "tdo_sample_edge",
974  .handler = &ftdi_handle_tdo_sample_edge_command,
975  .mode = COMMAND_ANY,
976  .help = "set which TCK clock edge is used for sampling TDO "
977  "- default is rising-edge (Setting to falling-edge may "
978  "allow signalling speed increase)",
979  .usage = "(rising|falling)",
980  },
982 };
983 
984 static const struct command_registration ftdi_command_handlers[] = {
985  {
986  .name = "ftdi",
987  .mode = COMMAND_ANY,
988  .help = "perform ftdi management",
989  .chain = ftdi_subcommand_handlers,
990  .usage = "",
991  },
993 };
994 
995 static int create_default_signal(const char *name, uint16_t data_mask)
996 {
997  struct signal *sig = create_signal(name);
998  if (!sig) {
999  LOG_ERROR("failed to create signal %s", name);
1000  return ERROR_FAIL;
1001  }
1002  sig->invert_data = false;
1003  sig->data_mask = data_mask;
1004  sig->invert_oe = false;
1005  sig->oe_mask = 0;
1006 
1007  return ERROR_OK;
1008 }
1009 
1010 static int create_signals(void)
1011 {
1012  if (create_default_signal("TCK", 0x01) != ERROR_OK)
1013  return ERROR_FAIL;
1014  if (create_default_signal("TDI", 0x02) != ERROR_OK)
1015  return ERROR_FAIL;
1016  if (create_default_signal("TDO", 0x04) != ERROR_OK)
1017  return ERROR_FAIL;
1018  if (create_default_signal("TMS", 0x08) != ERROR_OK)
1019  return ERROR_FAIL;
1020  return ERROR_OK;
1021 }
1022 
1023 static int ftdi_swd_init(void)
1024 {
1025  LOG_INFO("FTDI SWD mode enabled");
1026  swd_mode = true;
1027 
1028  if (create_signals() != ERROR_OK)
1029  return ERROR_FAIL;
1030 
1031  swd_cmd_queue_alloced = 10;
1032  swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue));
1033 
1034  return swd_cmd_queue ? ERROR_OK : ERROR_FAIL;
1035 }
1036 
1037 static void ftdi_swd_swdio_en(bool enable)
1038 {
1039  struct signal *oe = find_signal_by_name("SWDIO_OE");
1040  if (oe) {
1041  if (oe->data_mask)
1042  ftdi_set_signal(oe, enable ? '1' : '0');
1043  else {
1044  /* Sets TDI/DO pin to input during rx when both pins are connected
1045  to SWDIO */
1046  if (enable)
1047  direction |= jtag_direction_init & 0x0002U;
1048  else
1049  direction &= ~0x0002U;
1051  }
1052  }
1053 }
1054 
1059 static int ftdi_swd_run_queue(void)
1060 {
1061  LOG_DEBUG_IO("Executing %zu queued transactions", swd_cmd_queue_length);
1062  int retval;
1063  struct signal *led = find_signal_by_name("LED");
1064 
1065  if (queued_retval != ERROR_OK) {
1066  LOG_DEBUG_IO("Skipping due to previous errors: %d", queued_retval);
1067  goto skip;
1068  }
1069 
1070  /* A transaction must be followed by another transaction or at least 8 idle cycles to
1071  * ensure that data is clocked through the AP. */
1073 
1074  /* Terminate the "blink", if the current layout has that feature */
1075  if (led)
1076  ftdi_set_signal(led, '0');
1077 
1079  if (queued_retval != ERROR_OK) {
1080  LOG_ERROR("MPSSE failed");
1081  goto skip;
1082  }
1083 
1084  for (size_t i = 0; i < swd_cmd_queue_length; i++) {
1085  int ack = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1, 3);
1086 
1087  /* Devices do not reply to DP_TARGETSEL write cmd, ignore received ack */
1088  bool check_ack = swd_cmd_returns_ack(swd_cmd_queue[i].cmd);
1089 
1090  LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK) ? LOG_LVL_DEBUG : LOG_LVL_DEBUG_IO,
1091  "%s%s %s %s reg %X = %08" PRIx32,
1092  check_ack ? "" : "ack ignored ",
1093  ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
1094  swd_cmd_queue[i].cmd & SWD_CMD_APNDP ? "AP" : "DP",
1095  swd_cmd_queue[i].cmd & SWD_CMD_RNW ? "read" : "write",
1096  (swd_cmd_queue[i].cmd & SWD_CMD_A32) >> 1,
1097  buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn,
1098  1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RNW ? 0 : 1), 32));
1099 
1100  if (ack != SWD_ACK_OK && check_ack) {
1102  goto skip;
1103 
1104  } else if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) {
1105  uint32_t data = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3, 32);
1106  int parity = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 32, 1);
1107 
1108  if (parity != parity_u32(data)) {
1109  LOG_ERROR("SWD Read data parity mismatch");
1111  goto skip;
1112  }
1113 
1114  if (swd_cmd_queue[i].dst)
1115  *swd_cmd_queue[i].dst = data;
1116  }
1117  }
1118 
1119 skip:
1121  retval = queued_retval;
1123 
1124  /* Queue a new "blink" */
1125  if (led && retval == ERROR_OK)
1126  ftdi_set_signal(led, '1');
1127 
1128  return retval;
1129 }
1130 
1131 static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
1132 {
1134  /* Not enough room in the queue. Run the queue and increase its size for next time.
1135  * Note that it's not possible to avoid running the queue here, because mpsse contains
1136  * pointers into the queue which may be invalid after the realloc. */
1138  struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue));
1139  if (q) {
1140  swd_cmd_queue = q;
1141  swd_cmd_queue_alloced *= 2;
1142  LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);
1143  }
1144  }
1145 
1146  if (queued_retval != ERROR_OK)
1147  return;
1148 
1149  size_t i = swd_cmd_queue_length++;
1151 
1153 
1154  if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) {
1155  /* Queue a read transaction */
1156  swd_cmd_queue[i].dst = dst;
1157 
1158  ftdi_swd_swdio_en(false);
1160  0, 1 + 3 + 32 + 1 + 1, SWD_MODE);
1161  ftdi_swd_swdio_en(true);
1162  } else {
1163  /* Queue a write transaction */
1164  ftdi_swd_swdio_en(false);
1165 
1167  0, 1 + 3 + 1, SWD_MODE);
1168 
1169  ftdi_swd_swdio_en(true);
1170 
1171  buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1, 32, data);
1172  buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1 + 32, 1, parity_u32(data));
1173 
1175  1 + 3 + 1, 32 + 1, SWD_MODE);
1176  }
1177 
1178  /* Insert idle cycles after AP accesses to avoid WAIT */
1179  if (cmd & SWD_CMD_APNDP)
1180  mpsse_clock_data_out(mpsse_ctx, NULL, 0, ap_delay_clk, SWD_MODE);
1181 
1182 }
1183 
1184 static void ftdi_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
1185 {
1186  assert(cmd & SWD_CMD_RNW);
1187  ftdi_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
1188 }
1189 
1190 static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
1191 {
1192  assert(!(cmd & SWD_CMD_RNW));
1193  ftdi_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
1194 }
1195 
1197 {
1198  switch (seq) {
1199  case LINE_RESET:
1200  LOG_DEBUG("SWD line reset");
1201  ftdi_swd_swdio_en(true);
1203  break;
1204  case JTAG_TO_SWD:
1205  LOG_DEBUG("JTAG-to-SWD");
1206  ftdi_swd_swdio_en(true);
1208  break;
1209  case JTAG_TO_DORMANT:
1210  LOG_DEBUG("JTAG-to-DORMANT");
1211  ftdi_swd_swdio_en(true);
1213  break;
1214  case SWD_TO_JTAG:
1215  LOG_DEBUG("SWD-to-JTAG");
1216  ftdi_swd_swdio_en(true);
1218  break;
1219  case SWD_TO_DORMANT:
1220  LOG_DEBUG("SWD-to-DORMANT");
1221  ftdi_swd_swdio_en(true);
1223  break;
1224  case DORMANT_TO_SWD:
1225  LOG_DEBUG("DORMANT-to-SWD");
1226  ftdi_swd_swdio_en(true);
1228  break;
1229  case DORMANT_TO_JTAG:
1230  LOG_DEBUG("DORMANT-to-JTAG");
1231  ftdi_swd_swdio_en(true);
1233  break;
1234  default:
1235  LOG_ERROR("Sequence %d not supported", seq);
1236  return ERROR_FAIL;
1237  }
1238 
1239  return ERROR_OK;
1240 }
1241 
1242 static const struct swd_driver ftdi_swd = {
1243  .init = ftdi_swd_init,
1244  .switch_seq = ftdi_swd_switch_seq,
1245  .read_reg = ftdi_swd_read_reg,
1246  .write_reg = ftdi_swd_write_reg,
1247  .run = ftdi_swd_run_queue,
1248 };
1249 
1250 static const char * const ftdi_transports[] = { "jtag", "swd", NULL };
1251 
1252 static struct jtag_interface ftdi_interface = {
1254  .execute_queue = ftdi_execute_queue,
1255 };
1256 
1258  .name = "ftdi",
1259  .transports = ftdi_transports,
1260  .commands = ftdi_command_handlers,
1261 
1262  .init = ftdi_initialize,
1263  .quit = ftdi_quit,
1264  .reset = ftdi_reset,
1265  .speed = ftdi_speed,
1266  .khz = ftdi_khz,
1267  .speed_div = ftdi_speed_div,
1268 
1269  .jtag_ops = &ftdi_interface,
1270  .swd_ops = &ftdi_swd,
1271 };
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 int dst_offset, const uint8_t *src, unsigned int src_offset, unsigned int bit_count)
Definition: binarybuffer.h:218
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
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:709
static uint8_t ftdi_channel
Definition: ftdi.c:83
static const struct command_registration ftdi_command_handlers[]
Definition: ftdi.c:984
static void ftdi_swd_swdio_en(bool enable)
Definition: ftdi.c:1037
static int queued_retval
Definition: ftdi.c:116
static void ftdi_execute_sleep(struct jtag_command *cmd)
Definition: ftdi.c:562
static struct signal * create_signal(const char *name)
Definition: ftdi.c:135
static void ftdi_execute_stableclocks(struct jtag_command *cmd)
Definition: ftdi.c:573
static void ftdi_execute_pathmove(struct jtag_command *cmd)
Definition: ftdi.c:371
static int ftdi_swd_init(void)
Definition: ftdi.c:1023
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:1184
static struct jtag_interface ftdi_interface
Definition: ftdi.c:1252
#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:1257
static const struct swd_driver ftdi_swd
Definition: ftdi.c:1242
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:358
#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:1250
static int ftdi_reset(int trst, int srst)
Definition: ftdi.c:524
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:627
static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
Definition: ftdi.c:1131
static int ftdi_swd_run_queue(void)
Flush the MPSSE queue and process the SWD transaction queue.
Definition: ftdi.c:1059
#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:649
static int ftdi_quit(void)
Definition: ftdi.c:690
#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:342
static int create_default_signal(const char *name, uint16_t data_mask)
Definition: ftdi.c:995
static void ftdi_execute_scan(struct jtag_command *cmd)
Definition: ftdi.c:422
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:1190
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:1196
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:1010
static const struct command_registration ftdi_subcommand_handlers[]
Definition: ftdi.c:920
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:597
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_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:181
int mpsse_flush(struct mpsse_ctx *ctx)
Definition: mpsse.c:848
void mpsse_read_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t *data)
Definition: mpsse.c:676
void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
Definition: mpsse.c:643
int mpsse_set_frequency(struct mpsse_ctx *ctx, int frequency)
Definition: mpsse.c:751
void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data)
Definition: mpsse.c:660
void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, unsigned int length, bool tdi, uint8_t mode)
Definition: mpsse.c:569
void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, uint8_t *in, unsigned int in_offset, unsigned int length, uint8_t mode)
Definition: mpsse.c:498
void mpsse_clock_data_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, unsigned int length, uint8_t mode)
Definition: mpsse.c:486
void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, uint8_t *in, unsigned int in_offset, unsigned int length, bool tdi, uint8_t mode)
Definition: mpsse.c:575
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:330
bool mpsse_is_high_speed(struct mpsse_ctx *ctx)
Definition: mpsse.c:419
void mpsse_close(struct mpsse_ctx *ctx)
Definition: mpsse.c:405
void mpsse_clock_data_in(struct mpsse_ctx *ctx, uint8_t *in, unsigned int in_offset, unsigned int length, uint8_t mode)
Definition: mpsse.c:492
void mpsse_loopback_config(struct mpsse_ctx *ctx, bool enable)
Definition: mpsse.c:706
void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
Definition: mpsse.c:626
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 int 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
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
unsigned int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
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 int swd_seq_dormant_to_swd_len
Definition: swd.h:190
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 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
static const unsigned int swd_seq_jtag_to_swd_len
Definition: swd.h:125
static const unsigned int swd_seq_line_reset_len
Definition: swd.h:104
static const unsigned int swd_seq_dormant_to_jtag_len
Definition: swd.h:244
#define SWD_CMD_APNDP
Definition: swd.h:17
static const unsigned int swd_seq_swd_to_dormant_len
Definition: swd.h:159
#define SWD_CMD_START
Definition: swd.h:16
#define SWD_CMD_RNW
Definition: swd.h:18
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
Definition: swd.h:98
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 unsigned int swd_seq_swd_to_jtag_len
Definition: swd.h:144
static const unsigned int swd_seq_jtag_to_dormant_len
Definition: swd.h:211
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