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;
607 uint32_t attempts, uint32_t
timeout)
612 uint32_t bytes_read = 0;
617 while (!done && attempts > 0) {
630 if (bytes_read != in_length) {
633 LOG_DEBUG(
"XDS110: command 0x%02x return %" PRIu32
" bytes, expected %" PRIu32,
640 LOG_DEBUG(
"XDS110: command 0x%02x returned error %d",
679 static bool xds_version(uint32_t *firmware_id, uint16_t *hardware_id)
768 uint32_t end_state, uint8_t *data_out, uint8_t *data_in)
791 *path_pntr = (uint8_t)(shift_state & 0xff);
793 *end_pntr = (uint8_t)(end_state & 0xff);
802 memcpy((
void *)data_out_pntr, (
void *)data_out, total_bytes);
808 memcpy((
void *)data_in, (
void *)data_in_pntr, total_bytes);
885 uint32_t address, uint32_t *value)
896 *type_pntr = (uint8_t)(
type & 0xff);
897 *ap_num_pntr = (uint8_t)(ap_num & 0xff);
898 *address_pntr = (uint8_t)(address & 0xff);
912 uint32_t address, uint32_t *value)
926 *type_pntr = (uint8_t)(
type & 0xff);
927 *ap_num_pntr = (uint8_t)(ap_num & 0xff);
928 *address_pntr = (uint8_t)(address & 0xff);
999 *source_pntr = (uint8_t)(voltage != 0 ? 1 : 0);
1008 uint32_t *dap_results, uint32_t result_count)
1015 if (!dap_requests || !dap_results)
1020 memcpy((
void *)request_pntr, (
void *)dap_requests, request_size);
1026 if (success && (result_count > 0))
1027 memcpy((
void *)dap_results, (
void *)result_pntr, result_count * 4);
1033 uint8_t *scan_results, uint32_t result_size)
1040 if (!scan_requests || !scan_results)
1045 memcpy((
void *)request_pntr, (
void *)scan_requests, request_size);
1051 if (success && (result_size > 0))
1052 memcpy((
void *)scan_results, (
void *)result_pntr, result_size);
1071 memcpy((
void *)path_pntr, (
void *)path, num_states);
1098 LOG_ERROR(
"Sequence SWD line reset (%d) not supported", seq);
1130 LOG_ERROR(
"Sequence %d not supported", seq);
1153 uint32_t reg_value = 0;
1154 uint32_t temp_value = 0;
1158 if (!is_read_request)
1178 reg_value = temp_value;
1186 LOG_ERROR(
"XDS110: failed to read DAP register");
1217 if (is_read_request)
1236 LOG_ERROR(
"XDS110: failed to write DAP register");
1256 bool success =
true;
1287 dap_results[result++] = value;
1312 uint32_t request_size = (is_read_request) ? 1 : 5;
1324 if (is_read_request) {
1333 LOG_DEBUG(
"XDS110: refusing to enable sticky overrun detection");
1346 uint32_t ap_delay_clk)
1352 uint32_t ap_delay_clk)
1369 LOG_INFO(
"XDS110: firmware version = %" PRIu32
".%" PRIu32
".%" PRIu32
".%" PRIu32,
1370 (((firmware >> 28) & 0xf) * 10) + ((firmware >> 24) & 0xf),
1371 (((firmware >> 20) & 0xf) * 10) + ((firmware >> 16) & 0xf),
1372 (((firmware >> 12) & 0xf) * 10) + ((firmware >> 8) & 0xf),
1373 (((firmware >> 4) & 0xf) * 10) + ((firmware >> 0) & 0xf));
1378 LOG_INFO(
"XDS110: connected to target via SWD");
1381 LOG_INFO(
"XDS110: connected to target via JTAG");
1387 LOG_WARNING(
"XDS110: the firmware is not optimized for OpenOCD");
1458 "XDS110: ignoring supply voltage, not supported on this probe");
1506 uint32_t end_state, uint8_t *data_out, uint8_t *data_in)
1508 (void)
xds_jtag_scan(shift_state, total_bits, end_state, data_out, data_in);
1527 uint32_t shift_state;
1586 LOG_ERROR(
"BUG: unknown JTAG command type 0x%x encountered",
1596 data_pntr = data_in;
1672 uint32_t num_states;
1675 num_states = (uint32_t)
cmd->cmd.pathmove->num_states;
1677 if (num_states == 0)
1680 path = malloc(num_states *
sizeof(uint8_t));
1682 LOG_ERROR(
"XDS110: unable to allocate memory");
1687 for (
unsigned int i = 0; i < num_states; i++)
1695 LOG_ERROR(
"XDS110: the firmware does not support pathmove command");
1707 uint32_t total_fields;
1708 uint32_t total_bits;
1709 uint32_t total_bytes;
1716 for (
unsigned int i = 0; i <
cmd->cmd.scan->num_fields; i++) {
1718 total_bits += (uint32_t)
cmd->cmd.scan->fields[i].num_bits;
1721 if (total_bits == 0)
1733 if ((1 + total_bytes +
sizeof(end_state) + 1) >
MAX_DATA_BLOCK) {
1734 LOG_ERROR(
"BUG: JTAG scan request is too large to handle (%" PRIu32
" bits)",
1740 if (
cmd->cmd.scan->ir_scan)
1756 memset((
void *)
buffer, 0x00, total_bytes);
1757 for (
unsigned int i = 0; i <
cmd->cmd.scan->num_fields; i++) {
1758 if (
cmd->cmd.scan->fields[i].out_value) {
1761 cmd->cmd.scan->fields[i].num_bits);
1763 offset +=
cmd->cmd.scan->fields[i].num_bits;
1766 cmd->cmd.scan->fields[i].num_bits;
1768 cmd->cmd.scan->fields[i].in_value;
1776 uint32_t clocks =
cmd->cmd.stableclocks->num_cycles;
1795 uint32_t clocks =
cmd->cmd.stableclocks->num_cycles;
1811 switch (
cmd->type) {
1835 LOG_ERROR(
"BUG: unknown JTAG command type 0x%x encountered",
1858 uint32_t delay_count;
1862 LOG_INFO(
"XDS110: RTCK not supported");
1867 LOG_INFO(
"XDS110: increase speed request: %d kHz to %d kHz minimum",
1882 "XDS110: reduce speed request: %d kHz to %d kHz maximum",
1890 const double xds110_tck_pulse_increment = 66.0;
1891 freq_to_use = speed * 1000;
1895 double one_giga = 1000000000;
1897 double max_freq_pulse_duration = one_giga /
1901 double freq_to_pulse_width_in_ns = one_giga / freq_to_use;
1908 double current_value = max_freq_pulse_duration;
1910 while (current_value < freq_to_pulse_width_in_ns) {
1911 current_value += xds110_tck_pulse_increment;
1920 double diff_freq_1 = freq_to_use -
1921 (one_giga / (max_freq_pulse_duration +
1922 (xds110_tck_pulse_increment * delay_count)));
1923 double diff_freq_2 = (one_giga / (max_freq_pulse_duration +
1924 (xds110_tck_pulse_increment * (delay_count - 1)))) -
1928 if (diff_freq_1 > diff_freq_2)
1940 "XDS110: reduce speed request: %d kHz to %d kHz maximum",
1951 }
else if (speed >= 8500) {
1953 }
else if (speed >= 5500) {
1959 const double m = 17100000.0;
1960 const double b = -1.02;
1962 freq_to_use = speed * 1000;
1963 double period = 1.0/freq_to_use;
1964 double delay = m * period + b;
1969 delay_count = (uint32_t)delay;
2004 uint32_t voltage = 0;
2013 LOG_ERROR(
"XDS110: voltage must be 0 or between %d and %d "
2027 .handler = &xds110_handle_info_command,
2029 .help =
"show XDS110 info",
2034 .handler = &xds110_handle_supply_voltage_command,
2036 .help =
"set the XDS110 probe supply voltage",
2037 .usage =
"voltage_in_millivolts",
2046 .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 int dst_offset, const uint8_t *src, unsigned int src_offset, unsigned int 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.
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 ...)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
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)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
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
#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)
static int xds110_execute_queue(struct jtag_command *cmd_queue)
#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