20 #define XDS110_MIN_VOLTAGE 1800
21 #define XDS110_MAX_VOLTAGE 3600
24 #define XDS110_STAND_ALONE_ID 0x21
27 #define OCD_FIRMWARE_VERSION 0x02030011
28 #define OCD_FIRMWARE_UPGRADE \
29 "XDS110: upgrade to version 2.3.0.11+ for improved support"
32 #define FAST_TCK_FIRMWARE_VERSION 0x03000000
35 #define FAST_TCK_PLUS_FIRMWARE_VERSION 0x03000003
42 #define MAX_PACKET 1024
48 #define MAX_DATA_BLOCK 4096
50 #ifndef USB_PAYLOAD_SIZE
52 #define USB_PAYLOAD_SIZE (MAX_DATA_BLOCK + 60)
54 #define MAX_RESULT_QUEUE (MAX_DATA_BLOCK / 4)
64 #define DEFAULT_ATTEMPTS (1)
65 #define DEFAULT_TIMEOUT (4000)
69 #define SC_ERR_XDS110_FAIL -261
70 #define SC_ERR_SWD_WAIT -613
71 #define SC_ERR_SWD_FAULT -614
72 #define SC_ERR_SWD_PROTOCOL -615
73 #define SC_ERR_SWD_PARITY -616
74 #define SC_ERR_SWD_DEVICE_ID -617
77 #define XDS110_MIN_TCK_SPEED 100
78 #define XDS110_MAX_SLOW_TCK_SPEED 2500
79 #define XDS110_MAX_FAST_TCK_SPEED 14000
80 #define XDS110_DEFAULT_TCK_SPEED 2500
83 #define FAST_TCK_DELAY_14000_KHZ 0
84 #define FAST_TCK_DELAY_10000_KHZ 0xfffffffd
85 #define FAST_TCK_DELAY_12000_KHZ 0xfffffffe
86 #define FAST_TCK_DELAY_8500_KHZ 1
87 #define FAST_TCK_DELAY_5500_KHZ 2
94 #define XDS_JTAG_STATE_RESET 1
95 #define XDS_JTAG_STATE_IDLE 2
96 #define XDS_JTAG_STATE_SHIFT_DR 3
97 #define XDS_JTAG_STATE_SHIFT_IR 4
98 #define XDS_JTAG_STATE_PAUSE_DR 5
99 #define XDS_JTAG_STATE_PAUSE_IR 6
100 #define XDS_JTAG_STATE_EXIT1_DR 8
101 #define XDS_JTAG_STATE_EXIT1_IR 9
102 #define XDS_JTAG_STATE_EXIT2_DR 10
103 #define XDS_JTAG_STATE_EXIT2_IR 11
104 #define XDS_JTAG_STATE_SELECT_DR 12
105 #define XDS_JTAG_STATE_SELECT_IR 13
106 #define XDS_JTAG_STATE_UPDATE_DR 14
107 #define XDS_JTAG_STATE_UPDATE_IR 15
108 #define XDS_JTAG_STATE_CAPTURE_DR 16
109 #define XDS_JTAG_STATE_CAPTURE_IR 17
112 #define XDS_JTAG_TRANSIT_QUICKEST 1
113 #define XDS_JTAG_TRANSIT_VIA_CAPTURE 2
114 #define XDS_JTAG_TRANSIT_VIA_IDLE 3
121 #define DAP_DP_IDCODE 0x0
122 #define DAP_DP_ABORT 0x0
123 #define DAP_DP_STAT 0x4
124 #define DAP_DP_CTRL 0x4
125 #define DAP_DP_ADDR 0x8
126 #define DAP_DP_RESEND 0x8
127 #define DAP_DP_SELECT 0x8
128 #define DAP_DP_RDBUFF 0xc
130 #define DAP_AP_CSW 0x00
131 #define DAP_AP_TAR 0x04
132 #define DAP_AP_DRW 0x0C
133 #define DAP_AP_BD0 0x10
134 #define DAP_AP_BD1 0x14
135 #define DAP_AP_BD2 0x18
136 #define DAP_AP_BD3 0x1C
137 #define DAP_AP_RTBL 0xF8
138 #define DAP_AP_IDR 0xFC
142 #define XDS_OUT_LEN 1
146 #define XDS_CONNECT 0x01
147 #define XDS_DISCONNECT 0x02
148 #define XDS_VERSION 0x03
149 #define XDS_SET_TCK 0x04
150 #define XDS_SET_TRST 0x05
151 #define XDS_CYCLE_TCK 0x07
152 #define XDS_GOTO_STATE 0x09
153 #define XDS_JTAG_SCAN 0x0c
154 #define XDS_SET_SRST 0x0e
155 #define CMAPI_CONNECT 0x0f
156 #define CMAPI_DISCONNECT 0x10
157 #define CMAPI_ACQUIRE 0x11
158 #define CMAPI_RELEASE 0x12
159 #define CMAPI_REG_READ 0x15
160 #define CMAPI_REG_WRITE 0x16
161 #define SWD_CONNECT 0x17
162 #define SWD_DISCONNECT 0x18
163 #define CJTAG_CONNECT 0x2b
164 #define CJTAG_DISCONNECT 0x2c
165 #define XDS_SET_SUPPLY 0x32
166 #define OCD_DAP_REQUEST 0x3a
167 #define OCD_SCAN_REQUEST 0x3b
168 #define OCD_PATHMOVE 0x3c
170 #define CMD_IR_SCAN 1
171 #define CMD_DR_SCAN 2
172 #define CMD_RUNTEST 3
173 #define CMD_STABLECLOCKS 4
203 struct libusb_context *
ctx;
204 struct libusb_device_handle *
dev;
250 .is_connected =
false,
251 .is_cmapi_connected =
false,
252 .is_cmapi_acquired =
false,
253 .is_swd_mode =
false,
254 .is_ap_dirty =
false,
260 .txn_request_size = 0,
261 .txn_result_size = 0,
262 .txn_result_count = 0
267 buffer[3] = (value >> 24) & 0xff;
268 buffer[2] = (value >> 16) & 0xff;
269 buffer[1] = (value >> 8) & 0xff;
270 buffer[0] = (value >> 0) & 0xff;
275 buffer[1] = (value >> 8) & 0xff;
276 buffer[0] = (value >> 0) & 0xff;
281 uint32_t value = (((uint32_t)
buffer[3]) << 24) |
282 (((uint32_t)
buffer[2]) << 16) |
283 (((uint32_t)
buffer[1]) << 8) |
284 (((uint32_t)
buffer[0]) << 0);
290 uint16_t value = (((uint32_t)
buffer[1]) << 8) |
291 (((uint32_t)
buffer[0]) << 0);
304 struct libusb_context *ctx =
NULL;
305 struct libusb_device **list =
NULL;
306 struct libusb_device_handle *dev =
NULL;
308 struct libusb_device_descriptor desc;
311 uint16_t vids[] = { 0x0451, 0x0451, 0x1cbe };
312 uint16_t pids[] = { 0xbef3, 0xbef4, 0x02a5 };
314 uint8_t interfaces[] = { 2, 2, 0 };
315 uint8_t endpoints_in[] = { 3, 3, 1 };
316 uint8_t endpoints_out[] = { 2, 2, 1 };
326 result = libusb_init(&ctx);
330 count = libusb_get_device_list(ctx, &list);
339 for (i = 0; i <
count; i++) {
341 libusb_get_device_descriptor(list[i], &desc);
344 if (desc.idVendor == vids[
device] &&
345 desc.idProduct == pids[
device]) {
351 result = libusb_open(list[i], &dev);
353 const int max_data = 256;
354 unsigned char data[max_data + 1];
364 result = libusb_get_string_descriptor_ascii(dev,
365 desc.iSerialNumber, data, max_data);
389 libusb_free_device_list(list, 1);
407 (void)libusb_set_auto_detach_kernel_driver(dev, 1);
435 return (result == 0) ?
true :
false;
469 return (result == 0) ?
true :
false;
474 int bytes_written = 0;
475 int result = LIBUSB_SUCCESS;
482 size, &bytes_written, 0);
484 while (result == LIBUSB_ERROR_PIPE && retries < 3) {
488 size, &bytes_written, 0);
493 *written = bytes_written;
495 return (result == 0 &&
size == bytes_written) ?
true :
false;
516 if (bytes_read >= 7 &&
'*' ==
buffer[0]) {
522 if ((bytes_read - 3) <=
size) {
537 if (total_bytes_read)
538 *total_bytes_read = 0;
574 if (total_bytes_read)
575 *total_bytes_read =
count;
602 if (written != (
int)
size)
616 uint32_t attempts, uint32_t
timeout)
621 uint32_t bytes_read = 0;
626 while (!done && attempts > 0) {
639 if (bytes_read != in_length) {
642 LOG_DEBUG(
"XDS110: command 0x%02x return %" PRIu32
" bytes, expected %" PRIu32,
649 LOG_DEBUG(
"XDS110: command 0x%02x returned error %d",
688 static bool xds_version(uint32_t *firmware_id, uint16_t *hardware_id)
777 uint32_t end_state, uint8_t *data_out, uint8_t *data_in)
800 *path_pntr = (uint8_t)(shift_state & 0xff);
802 *end_pntr = (uint8_t)(end_state & 0xff);
811 memcpy((
void *)data_out_pntr, (
void *)data_out, total_bytes);
817 memcpy((
void *)data_in, (
void *)data_in_pntr, total_bytes);
894 uint32_t address, uint32_t *value)
905 *type_pntr = (uint8_t)(
type & 0xff);
906 *ap_num_pntr = (uint8_t)(ap_num & 0xff);
907 *address_pntr = (uint8_t)(address & 0xff);
921 uint32_t address, uint32_t *value)
935 *type_pntr = (uint8_t)(
type & 0xff);
936 *ap_num_pntr = (uint8_t)(ap_num & 0xff);
937 *address_pntr = (uint8_t)(address & 0xff);
1008 *source_pntr = (uint8_t)(voltage != 0 ? 1 : 0);
1017 uint32_t *dap_results, uint32_t result_count)
1024 if (!dap_requests || !dap_results)
1029 memcpy((
void *)request_pntr, (
void *)dap_requests, request_size);
1035 if (success && (result_count > 0))
1036 memcpy((
void *)dap_results, (
void *)result_pntr, result_count * 4);
1042 uint8_t *scan_results, uint32_t result_size)
1049 if (!scan_requests || !scan_results)
1054 memcpy((
void *)request_pntr, (
void *)scan_requests, request_size);
1060 if (success && (result_size > 0))
1061 memcpy((
void *)scan_results, (
void *)result_pntr, result_size);
1080 memcpy((
void *)path_pntr, (
void *)path, num_states);
1107 LOG_ERROR(
"Sequence SWD line reset (%d) not supported", seq);
1139 LOG_ERROR(
"Sequence %d not supported", seq);
1162 uint32_t reg_value = 0;
1163 uint32_t temp_value = 0;
1167 if (!is_read_request)
1187 reg_value = temp_value;
1195 LOG_ERROR(
"XDS110: failed to read DAP register");
1226 if (is_read_request)
1245 LOG_ERROR(
"XDS110: failed to write DAP register");
1265 bool success =
true;
1296 dap_results[result++] = value;
1321 uint32_t request_size = (is_read_request) ? 1 : 5;
1333 if (is_read_request) {
1342 LOG_DEBUG(
"XDS110: refusing to enable sticky overrun detection");
1355 uint32_t ap_delay_clk)
1361 uint32_t ap_delay_clk)
1378 LOG_INFO(
"XDS110: firmware version = %" PRIu32
".%" PRIu32
".%" PRIu32
".%" PRIu32,
1379 (((firmware >> 28) & 0xf) * 10) + ((firmware >> 24) & 0xf),
1380 (((firmware >> 20) & 0xf) * 10) + ((firmware >> 16) & 0xf),
1381 (((firmware >> 12) & 0xf) * 10) + ((firmware >> 8) & 0xf),
1382 (((firmware >> 4) & 0xf) * 10) + ((firmware >> 0) & 0xf));
1387 LOG_INFO(
"XDS110: connected to target via SWD");
1390 LOG_INFO(
"XDS110: connected to target via JTAG");
1396 LOG_WARNING(
"XDS110: the firmware is not optimized for OpenOCD");
1467 "XDS110: ignoring supply voltage, not supported on this probe");
1515 uint32_t end_state, uint8_t *data_out, uint8_t *data_in)
1517 (void)
xds_jtag_scan(shift_state, total_bits, end_state, data_out, data_in);
1536 uint32_t shift_state;
1595 LOG_ERROR(
"BUG: unknown JTAG command type 0x%x encountered",
1605 data_pntr = data_in;
1682 uint32_t num_states;
1685 num_states = (uint32_t)
cmd->cmd.pathmove->num_states;
1687 if (num_states == 0)
1690 path = (uint8_t *)malloc(num_states *
sizeof(uint8_t));
1692 LOG_ERROR(
"XDS110: unable to allocate memory");
1697 for (i = 0; i < num_states; i++)
1705 LOG_ERROR(
"XDS110: the firmware does not support pathmove command");
1718 uint32_t total_fields;
1719 uint32_t total_bits;
1720 uint32_t total_bytes;
1727 for (i = 0; i <
cmd->cmd.scan->num_fields; i++) {
1729 total_bits += (uint32_t)
cmd->cmd.scan->fields[i].num_bits;
1732 if (total_bits == 0)
1744 if ((1 + total_bytes +
sizeof(end_state) + 1) >
MAX_DATA_BLOCK) {
1745 LOG_ERROR(
"BUG: JTAG scan request is too large to handle (%" PRIu32
" bits)",
1751 if (
cmd->cmd.scan->ir_scan)
1767 memset((
void *)
buffer, 0x00, total_bytes);
1768 for (i = 0; i <
cmd->cmd.scan->num_fields; i++) {
1769 if (
cmd->cmd.scan->fields[i].out_value != 0) {
1772 cmd->cmd.scan->fields[i].num_bits);
1774 offset +=
cmd->cmd.scan->fields[i].num_bits;
1777 cmd->cmd.scan->fields[i].num_bits;
1779 cmd->cmd.scan->fields[i].in_value;
1787 uint32_t clocks = (uint32_t)
cmd->cmd.stableclocks->num_cycles;
1806 uint32_t clocks = (uint32_t)
cmd->cmd.stableclocks->num_cycles;
1822 switch (
cmd->type) {
1846 LOG_ERROR(
"BUG: unknown JTAG command type 0x%x encountered",
1869 uint32_t delay_count;
1873 LOG_INFO(
"XDS110: RTCK not supported");
1878 LOG_INFO(
"XDS110: increase speed request: %d kHz to %d kHz minimum",
1893 "XDS110: reduce speed request: %d kHz to %d kHz maximum",
1901 const double XDS110_TCK_PULSE_INCREMENT = 66.0;
1902 freq_to_use = speed * 1000;
1906 double one_giga = 1000000000;
1908 double max_freq_pulse_duration = one_giga /
1912 double freq_to_pulse_width_in_ns = one_giga / freq_to_use;
1919 double current_value = max_freq_pulse_duration;
1921 while (current_value < freq_to_pulse_width_in_ns) {
1922 current_value += XDS110_TCK_PULSE_INCREMENT;
1931 double diff_freq_1 = freq_to_use -
1932 (one_giga / (max_freq_pulse_duration +
1933 (XDS110_TCK_PULSE_INCREMENT * delay_count)));
1934 double diff_freq_2 = (one_giga / (max_freq_pulse_duration +
1935 (XDS110_TCK_PULSE_INCREMENT * (delay_count - 1)))) -
1939 if (diff_freq_1 > diff_freq_2)
1951 "XDS110: reduce speed request: %d kHz to %d kHz maximum",
1962 }
else if (speed >= 8500) {
1964 }
else if (speed >= 5500) {
1970 const double m = 17100000.0;
1971 const double b = -1.02;
1973 freq_to_use = speed * 1000;
1974 double period = 1.0/freq_to_use;
1975 double delay = m * period + b;
1980 delay_count = (uint32_t)delay;
2015 uint32_t voltage = 0;
2024 LOG_ERROR(
"XDS110: voltage must be 0 or between %d and %d "
2038 .handler = &xds110_handle_info_command,
2040 .help =
"show XDS110 info",
2045 .handler = &xds110_handle_supply_voltage_command,
2047 .help =
"set the XDS110 probe supply voltage",
2048 .usage =
"voltage_in_millivolts",
2057 .help =
"perform XDS110 management",
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
static const struct device_t * device
static void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#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...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_NOT_IMPLEMENTED
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
size_t size
Size of the control block search area.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Represents a driver for a debugging interface.
int(* execute_queue)(void)
Execute queued commands.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
unsigned char txn_requests[MAX_DATA_BLOCK]
uint32_t txn_result_count
unsigned char read_payload[USB_PAYLOAD_SIZE]
uint32_t txn_request_size
unsigned char write_payload[USB_PAYLOAD_SIZE]
struct libusb_device_handle * dev
struct libusb_context * ctx
struct scan_result txn_scan_results[MAX_DATA_BLOCK/4]
unsigned char write_packet[3]
uint32_t * txn_dap_results[MAX_DATA_BLOCK/4]
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static bool xds_set_srst(uint8_t srst)
#define XDS_JTAG_STATE_UPDATE_IR
static int xds110_execute_queue(void)
#define OCD_FIRMWARE_UPGRADE
#define XDS_JTAG_STATE_IDLE
static void xds110_flush(void)
#define XDS_JTAG_TRANSIT_QUICKEST
static const struct command_registration xds110_subcommand_handlers[]
COMMAND_HANDLER(xds110_handle_info_command)
#define XDS110_MAX_SLOW_TCK_SPEED
#define XDS110_MIN_VOLTAGE
static void xds110_set_u16(uint8_t *buffer, uint16_t value)
static int xds110_quit(void)
static bool cmapi_disconnect(void)
#define XDS_JTAG_STATE_EXIT1_IR
static bool cmapi_connect(uint32_t *idcode)
static bool usb_send_command(uint16_t size)
#define FAST_TCK_DELAY_10000_KHZ
static int xds110_reset(int trst, int srst)
static bool cmapi_acquire(void)
static void xds110_execute_sleep(struct jtag_command *cmd)
static bool xds_connect(void)
static void xds110_swd_queue_cmd(uint8_t cmd, uint32_t *value)
static void xds110_queue_runtest(struct jtag_command *cmd)
#define XDS110_MIN_TCK_SPEED
#define XDS_JTAG_STATE_SELECT_IR
static bool ocd_scan_request(uint8_t *scan_requests, uint32_t request_size, uint8_t *scan_results, uint32_t result_size)
static void xds110_execute_command(struct jtag_command *cmd)
static bool usb_connect(void)
#define FAST_TCK_DELAY_5500_KHZ
#define XDS110_STAND_ALONE_ID
static int xds110_swd_init(void)
static bool xds_version(uint32_t *firmware_id, uint16_t *hardware_id)
#define XDS_JTAG_STATE_EXIT1_DR
#define XDS110_DEFAULT_TCK_SPEED
static bool ocd_pathmove(uint32_t num_states, uint8_t *path)
static const struct command_registration xds110_command_handlers[]
#define FAST_TCK_DELAY_8500_KHZ
static void xds110_show_info(void)
#define OCD_FIRMWARE_VERSION
static const uint32_t xds_jtag_state[]
#define XDS_JTAG_STATE_CAPTURE_IR
static bool xds_execute(uint32_t out_length, uint32_t in_length, uint32_t attempts, uint32_t timeout)
static bool swd_disconnect(void)
#define XDS110_MAX_FAST_TCK_SPEED
static bool swd_connect(void)
static bool xds_jtag_scan(uint32_t shift_state, uint16_t shift_bits, uint32_t end_state, uint8_t *data_out, uint8_t *data_in)
static bool ocd_dap_request(uint8_t *dap_requests, uint32_t request_size, uint32_t *dap_results, uint32_t result_count)
#define XDS_JTAG_STATE_PAUSE_IR
static void xds110_execute_tlr_reset(struct jtag_command *cmd)
static int xds110_init(void)
#define XDS_JTAG_STATE_EXIT2_DR
static bool usb_get_response(uint32_t *total_bytes_read, uint32_t timeout)
static struct jtag_interface xds110_interface
#define XDS_JTAG_STATE_CAPTURE_DR
static void usb_disconnect(void)
#define XDS_JTAG_STATE_SELECT_DR
#define FAST_TCK_DELAY_12000_KHZ
static bool xds110_legacy_read_reg(uint8_t cmd, uint32_t *value)
struct adapter_driver xds110_adapter_driver
static void xds110_legacy_scan(uint32_t shift_state, uint32_t total_bits, uint32_t end_state, uint8_t *data_out, uint8_t *data_in)
static void xds110_legacy_stableclocks(uint32_t clocks)
static int xds110_speed(int speed)
#define XDS_JTAG_STATE_UPDATE_DR
static int xds110_speed_div(int speed, int *khz)
static struct xds110_info xds110
static bool xds_disconnect(void)
static void xds110_execute_pathmove(struct jtag_command *cmd)
static const char *const xds110_transport[]
static void xds110_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static void xds110_set_u32(uint8_t *buffer, uint32_t value)
static bool xds110_legacy_write_reg(uint8_t cmd, uint32_t value)
static bool xds_cycle_tck(uint32_t count)
static void xds110_queue_stableclocks(struct jtag_command *cmd)
#define XDS_JTAG_STATE_RESET
#define XDS_JTAG_STATE_PAUSE_DR
static int xds110_swd_run_queue(void)
static uint16_t xds110_get_u16(uint8_t *buffer)
static bool usb_write(unsigned char *buffer, int size, int *written)
static bool cjtag_connect(uint32_t format)
static uint32_t xds110_get_u32(uint8_t *buffer)
static bool usb_read(unsigned char *buffer, int size, int *bytes_read, int timeout)
static void xds110_legacy_runtest(uint32_t clocks, uint32_t end_state)
#define XDS_JTAG_STATE_SHIFT_IR
static bool xds_set_trst(uint8_t trst)
static void xds110_queue_scan(struct jtag_command *cmd)
static void xds110_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static bool cmapi_release(void)
static int xds110_swd_switch_seq(enum swd_special_seq seq)
static bool cmapi_read_dap_reg(uint32_t type, uint32_t ap_num, uint32_t address, uint32_t *value)
static const struct swd_driver xds110_swd_driver
static bool xds_set_supply(uint32_t voltage)
static bool xds_set_tck_delay(uint32_t delay)
#define XDS_JTAG_STATE_SHIFT_DR
#define SC_ERR_XDS110_FAIL
#define FAST_TCK_PLUS_FIRMWARE_VERSION
static int xds110_khz(int khz, int *jtag_speed)
#define XDS_JTAG_STATE_EXIT2_IR
static bool xds_goto_state(uint32_t state)
#define XDS110_MAX_VOLTAGE
static bool cmapi_write_dap_reg(uint32_t type, uint32_t ap_num, uint32_t address, uint32_t *value)
static bool cjtag_disconnect(void)
#define FAST_TCK_FIRMWARE_VERSION