OpenOCD
ti_icdi_usb.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * *
5  * Copyright (C) 2012 by Spencer Oliver *
6  * spen@spen-soft.co.uk *
7  ***************************************************************************/
8 
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12 
13 /* project specific includes */
14 #include <helper/binarybuffer.h>
15 #include <jtag/adapter.h>
16 #include <jtag/interface.h>
17 #include <jtag/hla/hla_layout.h>
18 #include <jtag/hla/hla_transport.h>
19 #include <jtag/hla/hla_interface.h>
20 #include <target/target.h>
21 
22 #include <target/cortex_m.h>
23 
24 #include "libusb_helper.h"
25 
26 #define ICDI_WRITE_ENDPOINT 0x02
27 #define ICDI_READ_ENDPOINT 0x83
28 
29 #define ICDI_WRITE_TIMEOUT (LIBUSB_TIMEOUT_MS)
30 #define ICDI_READ_TIMEOUT (LIBUSB_TIMEOUT_MS)
31 #define ICDI_PACKET_SIZE 2048
32 
33 #define PACKET_START "$"
34 #define PACKET_END "#"
35 
37  struct libusb_device_handle *usb_dev;
38 
39  char *read_buffer;
40  char *write_buffer;
43  uint32_t max_rw_packet; /* max X packet (read/write memory) transfers */
44 };
45 
46 static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size,
47  uint32_t count, uint8_t *buffer);
48 static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t size,
49  uint32_t count, const uint8_t *buffer);
50 
51 static int remote_escape_output(const char *buffer, int len, char *out_buf, int *out_len, int out_maxlen)
52 {
53  int input_index, output_index;
54 
55  output_index = 0;
56 
57  for (input_index = 0; input_index < len; input_index++) {
58 
59  char b = buffer[input_index];
60 
61  if (b == '$' || b == '#' || b == '}' || b == '*') {
62  /* These must be escaped. */
63  if (output_index + 2 > out_maxlen)
64  break;
65  out_buf[output_index++] = '}';
66  out_buf[output_index++] = b ^ 0x20;
67  } else {
68  if (output_index + 1 > out_maxlen)
69  break;
70  out_buf[output_index++] = b;
71  }
72  }
73 
74  *out_len = input_index;
75  return output_index;
76 }
77 
78 static int remote_unescape_input(const char *buffer, int len, char *out_buf, int out_maxlen)
79 {
80  int input_index, output_index;
81  int escaped;
82 
83  output_index = 0;
84  escaped = 0;
85 
86  for (input_index = 0; input_index < len; input_index++) {
87 
88  char b = buffer[input_index];
89 
90  if (output_index + 1 > out_maxlen)
91  LOG_ERROR("Received too much data from the target.");
92 
93  if (escaped) {
94  out_buf[output_index++] = b ^ 0x20;
95  escaped = 0;
96  } else if (b == '}')
97  escaped = 1;
98  else
99  out_buf[output_index++] = b;
100  }
101 
102  if (escaped)
103  LOG_ERROR("Unmatched escape character in target response.");
104 
105  return output_index;
106 }
107 
108 static int icdi_send_packet(void *handle, int len)
109 {
110  unsigned char cksum = 0;
111  struct icdi_usb_handle *h = handle;
112  int result, retry = 0;
113  int transferred = 0;
114 
115  assert(handle);
116 
117  /* check we have a large enough buffer for checksum "#00" */
118  if (len + 3 > h->max_packet) {
119  LOG_ERROR("packet buffer too small");
120  return ERROR_FAIL;
121  }
122 
123  /* calculate checksum - offset start of packet */
124  for (int i = 1; i < len; i++)
125  cksum += h->write_buffer[i];
126 
127  len += sprintf(&h->write_buffer[len], PACKET_END "%02x", cksum);
128 
130  char buffer[50];
131  char ch = h->write_buffer[1];
132  if (ch == 'x' || ch == 'X') {
133  LOG_DEBUG_USB("writing packet: <binary>");
134  } else {
135  memcpy(buffer, h->write_buffer, len >= 50 ? 50 - 1 : len);
136  buffer[len] = 0;
137  LOG_DEBUG_USB("writing packet: %s", buffer);
138  }
139  }
140 
141  while (1) {
142 
143  result = libusb_bulk_transfer(h->usb_dev, ICDI_WRITE_ENDPOINT, (unsigned char *)h->write_buffer, len,
144  &transferred, ICDI_WRITE_TIMEOUT);
145  if (result != 0 || transferred != len) {
146  LOG_DEBUG("Error TX Data %d", result);
147  return ERROR_FAIL;
148  }
149 
150  /* check that the client got the message ok, or shall we resend */
151  result = libusb_bulk_transfer(h->usb_dev, ICDI_READ_ENDPOINT, (unsigned char *)h->read_buffer, h->max_packet,
152  &transferred, ICDI_READ_TIMEOUT);
153  if (result != 0 || transferred < 1) {
154  LOG_DEBUG("Error RX Data %d", result);
155  return ERROR_FAIL;
156  }
157 
158  LOG_DEBUG_USB("received reply: '%c' : count %d", h->read_buffer[0], transferred);
159 
160  if (h->read_buffer[0] == '-') {
161  LOG_DEBUG("Resending packet %d", ++retry);
162  } else {
163  if (h->read_buffer[0] != '+')
164  LOG_DEBUG("Unexpected Reply from ICDI: %c", h->read_buffer[0]);
165  break;
166  }
167 
168  if (retry == 3) {
169  LOG_DEBUG("maximum nack retries attempted");
170  return ERROR_FAIL;
171  }
172  }
173 
174  retry = 0;
175  h->read_count = transferred;
176 
177  while (1) {
178 
179  /* read reply from icdi */
180  result = libusb_bulk_transfer(h->usb_dev, ICDI_READ_ENDPOINT, (unsigned char *)h->read_buffer + h->read_count,
181  h->max_packet - h->read_count, &transferred, ICDI_READ_TIMEOUT);
182 
183  LOG_DEBUG_USB("received data: count %d", transferred);
184 
185  /* check for errors but retry for timeout */
186  if (result != 0) {
187 
188  if (result == LIBUSB_ERROR_TIMEOUT) {
189  LOG_DEBUG("Error RX timeout %d", result);
190  } else {
191  LOG_DEBUG("Error RX Data %d", result);
192  return ERROR_FAIL;
193  }
194  }
195 
196  h->read_count += transferred;
197 
198  /* we need to make sure we have a full packet, including checksum */
199  if (h->read_count > 5) {
200 
201  /* check that we have received an packet delimiter
202  * we do not validate the checksum
203  * reply should contain $...#AA - so we check for # */
204  if (h->read_buffer[h->read_count - 3] == '#')
205  return ERROR_OK;
206  }
207 
208  if (retry++ == 3) {
209  LOG_DEBUG("maximum data retries attempted");
210  break;
211  }
212  }
213 
214  return ERROR_FAIL;
215 }
216 
217 static int icdi_send_cmd(void *handle, const char *cmd)
218 {
219  struct icdi_usb_handle *h = handle;
220 
221  int cmd_len = snprintf(h->write_buffer, h->max_packet, PACKET_START "%s", cmd);
222  return icdi_send_packet(handle, cmd_len);
223 }
224 
225 static int icdi_send_remote_cmd(void *handle, const char *data)
226 {
227  struct icdi_usb_handle *h = handle;
228 
229  size_t cmd_len = sprintf(h->write_buffer, PACKET_START "qRcmd,");
230  cmd_len += hexify(h->write_buffer + cmd_len, (const uint8_t *)data,
231  strlen(data), h->max_packet - cmd_len);
232 
233  return icdi_send_packet(handle, cmd_len);
234 }
235 
236 static int icdi_get_cmd_result(void *handle)
237 {
238  struct icdi_usb_handle *h = handle;
239  int offset = 0;
240  char ch;
241 
242  assert(handle);
243 
244  do {
245  ch = h->read_buffer[offset++];
246  if (offset > h->read_count)
247  return ERROR_FAIL;
248  } while (ch != '$');
249 
250  if (memcmp("OK", h->read_buffer + offset, 2) == 0)
251  return ERROR_OK;
252 
253  if (h->read_buffer[offset] == 'E') {
254  /* get error code */
255  uint8_t result;
256  if (unhexify(&result, h->read_buffer + offset + 1, 1) != 1)
257  return ERROR_FAIL;
258  return result;
259  }
260 
261  /* for now we assume everything else is ok */
262  return ERROR_OK;
263 }
264 
265 static int icdi_usb_idcode(void *handle, uint32_t *idcode)
266 {
267  *idcode = 0;
268  return ERROR_OK;
269 }
270 
271 static int icdi_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val)
272 {
273  uint8_t buf[4];
274  /* REVISIT: There's no target pointer here so there's no way to use target_buffer_set_u32().
275  * I guess all supported chips are little-endian anyway. */
276  h_u32_to_le(buf, val);
277  return icdi_usb_write_mem(handle, addr, 4, 1, buf);
278 }
279 
280 static enum target_state icdi_usb_state(void *handle)
281 {
282  int result;
283  struct icdi_usb_handle *h = handle;
284  uint32_t dhcsr;
285  uint8_t buf[4];
286 
287  result = icdi_usb_read_mem(h, DCB_DHCSR, 4, 1, buf);
288  if (result != ERROR_OK)
289  return TARGET_UNKNOWN;
290 
291  /* REVISIT: There's no target pointer here so there's no way to use target_buffer_get_u32().
292  * I guess all supported chips are little-endian anyway. */
293  dhcsr = le_to_h_u32(buf);
294  if (dhcsr & S_HALT)
295  return TARGET_HALTED;
296 
297  return TARGET_RUNNING;
298 }
299 
300 static int icdi_usb_version(void *handle)
301 {
302  struct icdi_usb_handle *h = handle;
303 
304  char version[20];
305 
306  /* get info about icdi */
307  int result = icdi_send_remote_cmd(handle, "version");
308  if (result != ERROR_OK)
309  return result;
310 
311  if (h->read_count < 8) {
312  LOG_ERROR("Invalid Reply Received");
313  return ERROR_FAIL;
314  }
315 
316  /* convert reply */
317  if (unhexify((uint8_t *)version, h->read_buffer + 2, 4) != 4) {
318  LOG_WARNING("unable to get ICDI version");
319  return ERROR_OK;
320  }
321 
322  /* null terminate and print info */
323  version[4] = 0;
324 
325  LOG_INFO("ICDI Firmware version: %s", version);
326 
327  return ERROR_OK;
328 }
329 
330 static int icdi_usb_query(void *handle)
331 {
332  int result;
333 
334  struct icdi_usb_handle *h = handle;
335 
336  result = icdi_send_cmd(handle, "qSupported");
337  if (result != ERROR_OK)
338  return result;
339 
340  /* check result */
341  result = icdi_get_cmd_result(handle);
342  if (result != ERROR_OK) {
343  LOG_ERROR("query supported failed: 0x%x", result);
344  return ERROR_FAIL;
345  }
346 
347  /* from this we can get the max packet supported */
348 
349  /* query packet buffer size */
350  char *offset = strstr(h->read_buffer, "PacketSize");
351  if (offset) {
352  char *separator;
353  int max_packet;
354 
355  max_packet = strtol(offset + 11, &separator, 16);
356  if (!max_packet)
357  LOG_ERROR("invalid max packet, using defaults");
358  else
359  h->max_packet = max_packet;
360  LOG_DEBUG("max packet supported : %i bytes", h->max_packet);
361  }
362 
363 
364  /* if required re allocate packet buffer */
365  if (h->max_packet != ICDI_PACKET_SIZE) {
366  h->read_buffer = realloc(h->read_buffer, h->max_packet);
367  h->write_buffer = realloc(h->write_buffer, h->max_packet);
368  if (!h->read_buffer || !h->write_buffer) {
369  LOG_ERROR("unable to reallocate memory");
370  return ERROR_FAIL;
371  }
372  }
373 
374  /* set extended mode */
375  result = icdi_send_cmd(handle, "!");
376  if (result != ERROR_OK)
377  return result;
378 
379  /* check result */
380  result = icdi_get_cmd_result(handle);
381  if (result != ERROR_OK) {
382  LOG_ERROR("unable to enable extended mode: 0x%x", result);
383  return ERROR_FAIL;
384  }
385 
386  return ERROR_OK;
387 }
388 
389 static int icdi_usb_reset(void *handle)
390 {
391  /* we do this in hla_target.c */
392  return ERROR_OK;
393 }
394 
395 static int icdi_usb_assert_srst(void *handle, int srst)
396 {
397  /* TODO not supported yet */
398  return ERROR_COMMAND_NOTFOUND;
399 }
400 
401 static int icdi_usb_run(void *handle)
402 {
403  int result;
404 
405  /* resume target at current address */
406  result = icdi_send_cmd(handle, "c");
407  if (result != ERROR_OK)
408  return result;
409 
410  /* check result */
411  result = icdi_get_cmd_result(handle);
412  if (result != ERROR_OK) {
413  LOG_ERROR("continue failed: 0x%x", result);
414  return ERROR_FAIL;
415  }
416 
417  return result;
418 }
419 
420 static int icdi_usb_halt(void *handle)
421 {
422  int result;
423 
424  /* this query halts the target ?? */
425  result = icdi_send_cmd(handle, "?");
426  if (result != ERROR_OK)
427  return result;
428 
429  /* check result */
430  result = icdi_get_cmd_result(handle);
431  if (result != ERROR_OK) {
432  LOG_ERROR("halt failed: 0x%x", result);
433  return ERROR_FAIL;
434  }
435 
436  return result;
437 }
438 
439 static int icdi_usb_step(void *handle)
440 {
441  int result;
442 
443  /* step target at current address */
444  result = icdi_send_cmd(handle, "s");
445  if (result != ERROR_OK)
446  return result;
447 
448  /* check result */
449  result = icdi_get_cmd_result(handle);
450  if (result != ERROR_OK) {
451  LOG_ERROR("step failed: 0x%x", result);
452  return ERROR_FAIL;
453  }
454 
455  return result;
456 }
457 
458 static int icdi_usb_read_regs(void *handle)
459 {
460  /* currently unsupported */
461  return ERROR_OK;
462 }
463 
464 static int icdi_usb_read_reg(void *handle, unsigned int regsel, uint32_t *val)
465 {
466  int result;
467  struct icdi_usb_handle *h = handle;
468  char cmd[10];
469 
470  snprintf(cmd, sizeof(cmd), "p%x", regsel);
471  result = icdi_send_cmd(handle, cmd);
472  if (result != ERROR_OK)
473  return result;
474 
475  /* check result */
476  result = icdi_get_cmd_result(handle);
477  if (result != ERROR_OK) {
478  LOG_ERROR("register read failed: 0x%x", result);
479  return ERROR_FAIL;
480  }
481 
482  /* convert result */
483  uint8_t buf[4];
484  if (unhexify(buf, h->read_buffer + 2, 4) != 4) {
485  LOG_ERROR("failed to convert result");
486  return ERROR_FAIL;
487  }
488  *val = le_to_h_u32(buf);
489 
490  return result;
491 }
492 
493 static int icdi_usb_write_reg(void *handle, unsigned int regsel, uint32_t val)
494 {
495  int result;
496  char cmd[20];
497  uint8_t buf[4];
498  h_u32_to_le(buf, val);
499 
500  int cmd_len = snprintf(cmd, sizeof(cmd), "P%x=", regsel);
501  hexify(cmd + cmd_len, buf, 4, sizeof(cmd));
502 
503  result = icdi_send_cmd(handle, cmd);
504  if (result != ERROR_OK)
505  return result;
506 
507  /* check result */
508  result = icdi_get_cmd_result(handle);
509  if (result != ERROR_OK) {
510  LOG_ERROR("register write failed: 0x%x", result);
511  return ERROR_FAIL;
512  }
513 
514  return result;
515 }
516 
517 static int icdi_usb_read_mem_int(void *handle, uint32_t addr, uint32_t len, uint8_t *buffer)
518 {
519  int result;
520  struct icdi_usb_handle *h = handle;
521  char cmd[20];
522 
523  snprintf(cmd, sizeof(cmd), "x%" PRIx32 ",%" PRIx32, addr, len);
524  result = icdi_send_cmd(handle, cmd);
525  if (result != ERROR_OK)
526  return result;
527 
528  /* check result */
529  result = icdi_get_cmd_result(handle);
530  if (result != ERROR_OK) {
531  LOG_ERROR("memory read failed: 0x%x", result);
532  return ERROR_FAIL;
533  }
534 
535  /* unescape input */
536  int read_len = remote_unescape_input(h->read_buffer + 5, h->read_count - 8, (char *)buffer, len);
537  if (read_len != (int)len) {
538  LOG_ERROR("read more bytes than expected: actual 0x%x expected 0x%" PRIx32, read_len, len);
539  return ERROR_FAIL;
540  }
541 
542  return ERROR_OK;
543 }
544 
545 static int icdi_usb_write_mem_int(void *handle, uint32_t addr, uint32_t len, const uint8_t *buffer)
546 {
547  int result;
548  struct icdi_usb_handle *h = handle;
549 
550  size_t cmd_len = snprintf(h->write_buffer, h->max_packet, PACKET_START "X%" PRIx32 ",%" PRIx32 ":", addr, len);
551 
552  int out_len;
553  cmd_len += remote_escape_output((const char *)buffer, len, h->write_buffer + cmd_len,
554  &out_len, h->max_packet - cmd_len);
555 
556  if (out_len < (int)len) {
557  /* for now issue a error as we have no way of allocating a larger buffer */
558  LOG_ERROR("memory buffer too small: requires 0x%x actual 0x%" PRIx32, out_len, len);
559  return ERROR_FAIL;
560  }
561 
562  result = icdi_send_packet(handle, cmd_len);
563  if (result != ERROR_OK)
564  return result;
565 
566  /* check result */
567  result = icdi_get_cmd_result(handle);
568  if (result != ERROR_OK) {
569  LOG_ERROR("memory write failed: 0x%x", result);
570  return ERROR_FAIL;
571  }
572 
573  return ERROR_OK;
574 }
575 
576 static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size,
577  uint32_t count, uint8_t *buffer)
578 {
579  int retval = ERROR_OK;
580  struct icdi_usb_handle *h = handle;
581  uint32_t bytes_remaining;
582 
583  /* calculate byte count */
584  count *= size;
585 
586  while (count) {
587 
588  bytes_remaining = h->max_rw_packet;
589  if (count < bytes_remaining)
590  bytes_remaining = count;
591 
592  retval = icdi_usb_read_mem_int(handle, addr, bytes_remaining, buffer);
593  if (retval != ERROR_OK)
594  return retval;
595 
596  buffer += bytes_remaining;
597  addr += bytes_remaining;
598  count -= bytes_remaining;
599  }
600 
601  return retval;
602 }
603 
604 static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t size,
605  uint32_t count, const uint8_t *buffer)
606 {
607  int retval = ERROR_OK;
608  struct icdi_usb_handle *h = handle;
609  uint32_t bytes_remaining;
610 
611  /* calculate byte count */
612  count *= size;
613 
614  while (count) {
615 
616  bytes_remaining = h->max_rw_packet;
617  if (count < bytes_remaining)
618  bytes_remaining = count;
619 
620  retval = icdi_usb_write_mem_int(handle, addr, bytes_remaining, buffer);
621  if (retval != ERROR_OK)
622  return retval;
623 
624  buffer += bytes_remaining;
625  addr += bytes_remaining;
626  count -= bytes_remaining;
627  }
628 
629  return retval;
630 }
631 
632 static int icdi_usb_override_target(const char *targetname)
633 {
634  return !strcmp(targetname, "cortex_m");
635 }
636 
637 static int icdi_usb_close(void *handle)
638 {
639  struct icdi_usb_handle *h = handle;
640 
641  if (!h)
642  return ERROR_OK;
643 
644  if (h->usb_dev)
646 
647  free(h->read_buffer);
648  free(h->write_buffer);
649  free(handle);
650  return ERROR_OK;
651 }
652 
653 static int icdi_usb_open(struct hl_interface_param *param, void **fd)
654 {
655  /* TODO: Convert remaining libusb_ calls to jtag_libusb_ */
656  int retval;
657  struct icdi_usb_handle *h;
658 
659  LOG_DEBUG("icdi_usb_open");
660 
661  h = calloc(1, sizeof(struct icdi_usb_handle));
662 
663  if (!h) {
664  LOG_ERROR("unable to allocate memory");
665  return ERROR_FAIL;
666  }
667 
668  for (uint8_t i = 0; param->vid[i] && param->pid[i]; ++i)
669  LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s", param->transport,
670  param->vid[i], param->pid[i], adapter_get_required_serial() ? adapter_get_required_serial() : "");
671 
672  /* TI (Stellaris) ICDI provides its serial number in the USB descriptor;
673  no need to provide a callback here. */
674  jtag_libusb_open(param->vid, param->pid, NULL, &h->usb_dev, NULL);
675 
676  if (!h->usb_dev) {
677  LOG_ERROR("open failed");
678  goto error_open;
679  }
680 
681  if (libusb_claim_interface(h->usb_dev, 2)) {
682  LOG_DEBUG("claim interface failed");
683  goto error_open;
684  }
685 
686  /* check if mode is supported */
687  retval = ERROR_OK;
688 
689  switch (param->transport) {
690 #if 0
691  /* TODO place holder as swd is not currently supported */
692  case HL_TRANSPORT_SWD:
693 #endif
694  case HL_TRANSPORT_JTAG:
695  break;
696  default:
697  retval = ERROR_FAIL;
698  break;
699  }
700 
701  if (retval != ERROR_OK) {
702  LOG_ERROR("mode (transport) not supported by device");
703  goto error_open;
704  }
705 
706  /* allocate buffer */
707  h->read_buffer = malloc(ICDI_PACKET_SIZE);
708  h->write_buffer = malloc(ICDI_PACKET_SIZE);
710 
711  if (!h->read_buffer || !h->write_buffer) {
712  LOG_DEBUG("malloc failed");
713  goto error_open;
714  }
715 
716  /* query icdi version etc */
717  retval = icdi_usb_version(h);
718  if (retval != ERROR_OK)
719  goto error_open;
720 
721  /* query icdi support */
722  retval = icdi_usb_query(h);
723  if (retval != ERROR_OK)
724  goto error_open;
725 
726  *fd = h;
727 
728  /* set the max target read/write buffer in bytes
729  * as we are using gdb binary packets to transfer memory we have to
730  * reserve half the buffer for any possible escape chars plus
731  * at least 64 bytes for the gdb packet header */
732  h->max_rw_packet = (((h->max_packet - 64) / 4) * 4) / 2;
733 
734  return ERROR_OK;
735 
736 error_open:
737  icdi_usb_close(h);
738 
739  return ERROR_FAIL;
740 }
741 
743  .open = icdi_usb_open,
744  .close = icdi_usb_close,
745  .idcode = icdi_usb_idcode,
746  .state = icdi_usb_state,
747  .reset = icdi_usb_reset,
748  .assert_srst = icdi_usb_assert_srst,
749  .run = icdi_usb_run,
750  .halt = icdi_usb_halt,
751  .step = icdi_usb_step,
752  .read_regs = icdi_usb_read_regs,
753  .read_reg = icdi_usb_read_reg,
754  .write_reg = icdi_usb_write_reg,
755  .read_mem = icdi_usb_read_mem,
756  .write_mem = icdi_usb_write_mem,
757  .write_debug_reg = icdi_usb_write_debug_reg,
758  .override_target = icdi_usb_override_target,
759  .custom_command = icdi_send_remote_cmd,
760 };
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
Definition: adapter.c:302
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
Definition: binarybuffer.c:380
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
Definition: binarybuffer.c:342
Support functions to access arbitrary bits in a byte array.
#define ERROR_COMMAND_NOTFOUND
Definition: command.h:406
#define S_HALT
Definition: cortex_m.h:180
#define DCB_DHCSR
Definition: cortex_m.h:85
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
@ HL_TRANSPORT_SWD
Definition: hla_transport.h:16
@ HL_TRANSPORT_JTAG
Definition: hla_transport.h:17
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], const char *product, struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
void jtag_libusb_close(struct libusb_device_handle *dev)
#define LOG_DEBUG_USB(expr,...)
Definition: log.h:107
#define LOG_WARNING(expr ...)
Definition: log.h:137
#define ERROR_FAIL
Definition: log.h:181
#define LOG_ERROR(expr ...)
Definition: log.h:140
#define LOG_LEVEL_IS(FOO)
Definition: log.h:105
#define LOG_INFO(expr ...)
Definition: log.h:134
#define LOG_DEBUG(expr ...)
Definition: log.h:117
#define ERROR_OK
Definition: log.h:175
@ LOG_LVL_DEBUG_USB
Definition: log.h:53
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
enum hl_transports transport
Definition: hla_interface.h:29
uint16_t pid[HLA_MAX_USB_IDS+1]
List of recognised PIDs.
Definition: hla_interface.h:27
uint16_t vid[HLA_MAX_USB_IDS+1]
List of recognised VIDs.
Definition: hla_interface.h:25
int(* open)(struct hl_interface_param *param, void **handle)
Definition: hla_layout.h:29
uint32_t max_rw_packet
Definition: ti_icdi_usb.c:43
char * write_buffer
Definition: ti_icdi_usb.c:40
struct libusb_device_handle * usb_dev
Definition: ti_icdi_usb.c:37
char * read_buffer
Definition: ti_icdi_usb.c:39
target_state
Definition: target.h:55
@ TARGET_UNKNOWN
Definition: target.h:56
@ TARGET_HALTED
Definition: target.h:58
@ TARGET_RUNNING
Definition: target.h:57
#define ICDI_WRITE_TIMEOUT
Definition: ti_icdi_usb.c:29
static int remote_unescape_input(const char *buffer, int len, char *out_buf, int out_maxlen)
Definition: ti_icdi_usb.c:78
static int icdi_send_remote_cmd(void *handle, const char *data)
Definition: ti_icdi_usb.c:225
#define ICDI_PACKET_SIZE
Definition: ti_icdi_usb.c:31
static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: ti_icdi_usb.c:576
static int icdi_usb_override_target(const char *targetname)
Definition: ti_icdi_usb.c:632
static enum target_state icdi_usb_state(void *handle)
Definition: ti_icdi_usb.c:280
struct hl_layout_api icdi_usb_layout_api
Definition: ti_icdi_usb.c:742
static int icdi_usb_assert_srst(void *handle, int srst)
Definition: ti_icdi_usb.c:395
#define ICDI_WRITE_ENDPOINT
Definition: ti_icdi_usb.c:26
static int icdi_usb_query(void *handle)
Definition: ti_icdi_usb.c:330
static int icdi_get_cmd_result(void *handle)
Definition: ti_icdi_usb.c:236
static int icdi_usb_step(void *handle)
Definition: ti_icdi_usb.c:439
#define ICDI_READ_TIMEOUT
Definition: ti_icdi_usb.c:30
#define ICDI_READ_ENDPOINT
Definition: ti_icdi_usb.c:27
static int icdi_usb_read_mem_int(void *handle, uint32_t addr, uint32_t len, uint8_t *buffer)
Definition: ti_icdi_usb.c:517
static int icdi_usb_idcode(void *handle, uint32_t *idcode)
Definition: ti_icdi_usb.c:265
static int icdi_send_cmd(void *handle, const char *cmd)
Definition: ti_icdi_usb.c:217
static int remote_escape_output(const char *buffer, int len, char *out_buf, int *out_len, int out_maxlen)
Definition: ti_icdi_usb.c:51
static int icdi_usb_halt(void *handle)
Definition: ti_icdi_usb.c:420
static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: ti_icdi_usb.c:604
#define PACKET_END
Definition: ti_icdi_usb.c:34
static int icdi_usb_close(void *handle)
Definition: ti_icdi_usb.c:637
static int icdi_usb_write_reg(void *handle, unsigned int regsel, uint32_t val)
Definition: ti_icdi_usb.c:493
#define PACKET_START
Definition: ti_icdi_usb.c:33
static int icdi_usb_version(void *handle)
Definition: ti_icdi_usb.c:300
static int icdi_send_packet(void *handle, int len)
Definition: ti_icdi_usb.c:108
static int icdi_usb_write_mem_int(void *handle, uint32_t addr, uint32_t len, const uint8_t *buffer)
Definition: ti_icdi_usb.c:545
static int icdi_usb_read_regs(void *handle)
Definition: ti_icdi_usb.c:458
static int icdi_usb_run(void *handle)
Definition: ti_icdi_usb.c:401
static int icdi_usb_open(struct hl_interface_param *param, void **fd)
Definition: ti_icdi_usb.c:653
static int icdi_usb_reset(void *handle)
Definition: ti_icdi_usb.c:389
static int icdi_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val)
Definition: ti_icdi_usb.c:271
static int icdi_usb_read_reg(void *handle, unsigned int regsel, uint32_t *val)
Definition: ti_icdi_usb.c:464
static void h_u32_to_le(uint8_t *buf, uint32_t val)
Definition: types.h:178
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22