78 #define USEABLE_GPIOS 0x78
81 #define GPIO_SET_L (BIT(4) | BIT(5) | BIT(6) | BIT(7))
82 #define GPIO_SET_H (BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7))
84 #define VENDOR_VERSION 0x5F
87 #define HW_TDO_BUF_SIZE 4096
89 #define LARGER_PACK_MAX_SIZE 51200
91 #define UCMDPKT_DATA_MAX_BYTES_USBHS 507
92 #define USBC_PACKET_USBHS 512
93 #define CH347_CMD_HEADER 3
94 #define CH347_CMD_INIT_READ_LEN 1
96 #define CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE 9
98 #define MAX_BITS_PER_BIT_OP 248
102 #define CH347_CMD_INFO_RD 0xCA
103 #define CH347_CMD_GPIO 0xCC
104 #define CH347_CMD_JTAG_INIT 0xD0
105 #define CH347_CMD_JTAG_BIT_OP 0xD1
106 #define CH347_CMD_JTAG_BIT_OP_RD 0xD2
107 #define CH347_CMD_JTAG_DATA_SHIFT 0xD3
108 #define CH347_CMD_JTAG_DATA_SHIFT_RD 0xD4
110 #define CH347_SINGLE_CMD_MAX_READ MAX(GPIO_CNT, CH347_CMD_INIT_READ_LEN)
113 #define CH347_CMD_SWD_INIT 0xE5
114 #define CH347_CMD_SWD 0xE8
115 #define CH347_CMD_SWD_REG_W 0xA0
116 #define CH347_CMD_SWD_SEQ_W 0xA1
117 #define CH347_CMD_SWD_REG_R 0xA2
118 #define CH347_MAX_PROCESSING_US 7000
120 #define CH347_MAX_SEND_BUF USBC_PACKET_USBHS
121 #define CH347_MAX_RECV_BUF USBC_PACKET_USBHS
122 #define CH347_MAX_CMD_BUF 128
123 #define CH347_SWD_CLOCK_MAX 5000
124 #define CH347_SWD_CLOCK_BASE 1000
126 #define CH347_SWD_CLOCK_MAX_DIVISOR (CH347_MAX_PROCESSING_US / swd_seq_dormant_to_swd_len)
128 #define CH347_EPOUT 0x06u
129 #define CH347_EPIN 0x86u
130 #define CH347T_MPHSI_INTERFACE 2
131 #define CH347F_MPHSI_INTERFACE 4
132 #define USB_WRITE_TIMEOUT 500
133 #define USB_READ_TIMEOUT 500
135 #define BYTEWISE_MODE_VERSION 0x241
138 #define DEFAULT_VENDOR_ID 0x1a86
139 #define DEFAULT_CH347T_PRODUCT_ID 0x55dd
140 #define DEFAULT_CH347F_PRODUCT_ID 0x55de
141 #define DEFAULT_OTHER_PRODUCT_ID 0x55e7
274 unsigned int i = 0, j = 0;
275 unsigned int n =
size * 3 + 1;
276 char *str = malloc(n);
280 while (i <
size && j < n) {
281 uint8_t
cmd = data[i++];
286 unsigned int cmd_payload_size =
le_to_h_u16(data + i);
287 if (i + 2 <=
size && j + 4 < n) {
288 hexify(str + j, data + i, 2, n - j);
297 if (i + cmd_payload_size >
size) {
299 cmd_payload_size =
size - i;
304 unsigned int swd_base_i = i;
306 while (i < swd_base_i + cmd_payload_size) {
312 unsigned int swd_bits = 0;
313 unsigned int swd_payload_size = 0;
317 hexify(str + j, data + i, 2, n - j);
327 swd_payload_size = 1;
337 swd_payload_size = 1 + 4 + 1;
339 swd_payload_size = 1;
343 hexify(str + j, data + i,
MIN(swd_payload_size,
size - i), n - j);
344 i += swd_payload_size;
345 j += 2 * swd_payload_size;
354 hexify(str + j, data + i,
MIN(cmd_payload_size,
size - i), n - j);
355 i += cmd_payload_size;
356 j += 2 * cmd_payload_size;
450 cmd->tdo_bit_count = 0;
455 cmd->read_len =
cmd->write_data_len;
464 for (
int i = 0; i <
cmd->write_data_len; i++) {
467 cmd->tdo_bit_count++;
473 cmd->read_len =
cmd->write_data_len;
475 cmd->tdo_bit_count =
cmd->read_len * 8;
497 if (!
cmd || !
cmd->write_data) {
525 static int ch347_read_scan(uint8_t *decoded_buf,
int decoded_buf_len,
int raw_read_len)
528 uint8_t *read_buf = malloc(
read_len);
541 int decoded_buf_idx = 0;
544 unsigned int type = read_buf[rd_idx++];
545 uint16_t data_len =
le_to_h_u16(&read_buf[rd_idx]);
547 if (decoded_buf_idx > decoded_buf_len) {
548 LOG_ERROR(
"CH347 decoded_buf too small");
565 memcpy(&decoded_buf[decoded_buf_idx], &read_buf[rd_idx], data_len);
566 decoded_buf_idx += data_len;
571 for (
int i = 0; i < data_len; i++) {
572 if (read_buf[rd_idx + i] &
BIT(0))
573 decoded_buf[decoded_buf_idx + i / 8] |=
BIT(i % 8);
575 decoded_buf[decoded_buf_idx + i / 8] &= ~(
BIT(i % 8));
605 for (
int i = 0; i <
scan->fields_len; i++) {
606 int num_bits =
scan->fields[i].num_bits;
609 if (
scan->fields[i].in_value) {
610 uint8_t *capture_buf = malloc(
DIV_ROUND_UP(num_bits, 8));
623 buf_cpy(captured,
scan->fields[i].in_value, num_bits);
641 if (byte_offset < decoded_buf_len) {
673 int decoded_buf_len = 0;
675 if (
cmd->read_len > 0)
680 uint8_t *decoded_buf =
NULL;
681 int decoded_buf_idx = 0;
682 if (decoded_buf_len > 0) {
683 decoded_buf = malloc(decoded_buf_len);
693 int total_tdo_count = 0;
694 int bytes_to_write = 0;
698 total_tdo_count +=
cmd->tdo_bit_count;
704 bytes_to_write = total_len;
708 if (!last_cmd || bytes_to_write == 0) {
715 uint8_t *write_buf = malloc(bytes_to_write);
723 int bytes_to_read = 0;
724 int current_decoded_buf_len = 0;
729 write_buf[idx++] =
cmd->type;
732 memcpy(&write_buf[idx],
cmd->write_data,
cmd->write_data_len);
733 idx +=
cmd->write_data_len;
735 if (
cmd->read_len > 0) {
743 free(
cmd->write_data);
762 if (!current_decoded_buf_len) {
766 retval =
ch347_read_scan(&decoded_buf[decoded_buf_idx], current_decoded_buf_len, bytes_to_read);
767 decoded_buf_idx += current_decoded_buf_len;
844 scan->fields = scan_fields;
845 scan->fields_len = scan_fields_len;
937 int remaining =
count;
939 while (remaining > 0) {
949 bytes_idx += bytes_to_store;
950 remaining -= bytes_to_store;
993 for (
int i = 0; i <
count; i++) {
1023 LOG_DEBUG_IO(
"TMS Value: %02x..., step = %d, skip = %d", tms_value[0],
step, skip);
1029 for (
int i = skip; i <
step; i++) {
1052 for (
unsigned int i = 0; i <
cmd->num_states; i++) {
1107 int byte_count = bits_len / 8;
1108 int bit_count = bits_len % 8;
1111 if (byte_count > 0 && bit_count == 0) {
1120 bit_count = bits_len;
1126 if (byte_count > 0) {
1149 for (
int i = 0; i < bit_count; i++) {
1154 if (i + 1 == bit_count)
1224 static const char *
const type2str[] = {
"",
"SCAN_IN",
"SCAN_OUT",
"SCAN_IO"};
1227 uint8_t *buf =
NULL;
1244 LOG_DEBUG_IO(
"scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d",
1245 cmd->ir_scan ?
"IRSCAN" :
"DRSCAN",
1247 scan_bits, log_buf,
cmd->end_state);
1289 if ((
byte &
BIT(6)) >> 6 != data) {
1324 LOG_ERROR(
"Asserting SRST not supported!");
1330 LOG_WARNING(
"Asserting TRST not supported in SWD mode!");
1378 switch (
cmd->type) {
1401 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X",
cmd->type);
1431 char error_message[256];
1432 snprintf(error_message,
sizeof(error_message),
"CH347 not found. Tried VID/PID pairs: ");
1433 for (
int i = 0; ch347_vids[i] != 0; i++)
1434 snprintf(error_message + strlen(error_message),
sizeof(error_message) - strlen(error_message),
1435 "%04x:%04x ", ch347_vids[i], ch347_pids[i]);
1441 struct libusb_device_descriptor ch347_device_descriptor;
1444 LOG_ERROR(
"CH347 error calling libusb_get_device");
1449 retval = libusb_get_device_descriptor(
device, &ch347_device_descriptor);
1451 LOG_ERROR(
"CH347 error getting device descriptor: %s", libusb_error_name(retval));
1462 LOG_ERROR(
"CH347 unable to claim interface: %s", libusb_error_name(retval));
1471 char firmware_version;
1473 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
1474 VENDOR_VERSION, 0, 0, &firmware_version,
sizeof(firmware_version),
1477 LOG_ERROR(
"CH347 unable to get firmware version");
1482 char manufacturer[256 + 1];
1483 if (libusb_get_string_descriptor_ascii(
ch347_handle, ch347_device_descriptor.iManufacturer,
1484 (
unsigned char *)manufacturer,
sizeof(manufacturer) - 1) < 0) {
1485 strcpy(manufacturer,
"(unknown)");
1487 char product[256 + 1];
1488 if (libusb_get_string_descriptor_ascii(
ch347_handle, ch347_device_descriptor.iProduct,
1489 (
unsigned char *)product,
sizeof(product) - 1) < 0) {
1490 strcpy(product,
"(unknown)");
1492 char serial_number[256 + 1];
1493 if (libusb_get_string_descriptor_ascii(
ch347_handle, ch347_device_descriptor.iSerialNumber,
1494 (
unsigned char *)serial_number,
sizeof(serial_number) - 1) < 0) {
1495 strcpy(serial_number,
"(unknown)");
1498 LOG_INFO(
"CH347 %s from vendor %s with serial number %s found. (Chip version=%X.%2X, Firmware=0x%02X)",
1502 (ch347_device_descriptor.bcdDevice >> 8) & 0xFF,
1503 ch347_device_descriptor.bcdDevice & 0xFF,
1507 LOG_INFO(
"CH347T old version of the chip, JTAG only working in bitwise mode. For bytewise mode at least version %X.%X is needed.",
1519 if (ch347_device_descriptor.bcdDevice < 0x441)
1520 LOG_WARNING(
"CH347T version older than 4.41 probably does not support SWD transport");
1522 if (ch347_device_descriptor.bcdDevice == 0x441)
1523 LOG_WARNING(
"If CH347T version 4.41 cannot connect or SWD fails often, insert a resistor to SWDIO circuit");
1525 }
else if (ch347_device_descriptor.bcdDevice == 0x241) {
1526 LOG_WARNING(
"CH347T version 2.41 has very weird clock timing, may not work with a slower JTAG device");
1529 if (ch347_device_descriptor.bcdDevice < 0x544)
1530 LOG_INFO(
"Please upgrade CH347T firmware to a production version >= 5.44");
1535 if (ch347_device_descriptor.bcdDevice < 0x101)
1536 LOG_INFO(
"Please upgrade CH347F firmware to a production version >= 1.1");
1582 for (
int i = 0; i < 4; i++) {
1593 *supports_larger_pack_mode =
mode != 0;
1635 uint8_t cmd_data[] = {0x40, 0x42, 0x0f, 0x00, clock_divisor, 0x00, 0x00, 0x00 };
1643 uint8_t init_result = 0;
1645 LOG_DEBUG(
"SWD init clk div %" PRIu8
", result %02" PRIx8,
1646 clock_divisor, init_result);
1684 bool supports_larger_pack_mode;
1717 *khz = speeds[speed_idx];
1731 LOG_ERROR(
"Adaptive clocking not supported");
1757 int lower_bound = 0;
1759 for (
int i = 0; i <
length; i++) {
1760 if (khz >= lower_bound && khz <= speeds[i]) {
1764 lower_bound = speeds[i];
1768 LOG_INFO(
"Speed %d kHz is higher than highest speed of %d kHz. Using %d khz!",
1771 }
else if (speeds[idx] != khz) {
1772 LOG_INFO(
"Requested speed of %d kHz is not possible. Using the next higher speed of %d kHz!",
1841 .handler = &ch347_handle_vid_pid_command,
1843 .help =
"the vendor ID and product ID of the CH347 device",
1844 .usage =
"(vid pid)*",
1847 .name =
"device_desc",
1848 .handler = &ch347_handle_device_desc_command,
1850 .help =
"set the USB device description of the CH347 device",
1851 .usage =
"description_string",
1854 .name =
"activity_led",
1855 .handler = &ch347_handle_activity_led_command,
1857 .help =
"if set this CH347 GPIO pin is the JTAG activity LED; start with n for active low output",
1858 .usage =
"[n]gpio_number",
1867 .help =
"perform ch347 management",
1919 LOG_INFO(
"CH347 SWD mode enabled");
2050 len = 1 + 1 + 1 + 1;
2054 len = 1 + 1 + 4 + 1;
2061 len = 1 + 1 + 1 + 1 + 4 + 1;
2098 && ap_delay_clk > max_processing_clk;
2109 : expected_total_clk / 5;
2121 unsigned int this_delay_clk =
MIN(ap_delay_clk, 255);
2122 if ((
unsigned int)send_room * 8 < this_delay_clk)
2123 this_delay_clk = send_room * 8;
2129 ap_delay_clk -= this_delay_clk;
2147 LOG_ERROR(
"ch347 SWD queue not empty after ch347_swd_run_queue");
2154 unsigned int this_delay_clk =
MIN(ap_delay_clk, 255);
2155 if (send_room * 8 < this_delay_clk)
2156 this_delay_clk = send_room * 8;
2157 if (max_processing_clk < this_delay_clk)
2158 this_delay_clk = max_processing_clk;
2162 ap_delay_clk -= this_delay_clk;
2165 }
while (ap_delay_clk);
2182 LOG_ERROR(
"CH347 usb write/read failed - queued_retval");
2189 LOG_ERROR(
"CH347 usb write/read failed - not CH347_CMD_SWD");
2197 LOG_ERROR(
"CH347 usb write/read failed - too long");
2210 LOG_ERROR(
"CH347 usb write/read failed - not CH347_CMD_SWD_SEQ_W");
2224 uint32_t data =
buf_get_u32(&recv_buf[recv_len], 0, 32);
2228 "%s%s %s read reg %X = %08" PRIx32,
2229 check_ack ?
"" :
"ack ignored ",
2244 LOG_ERROR(
"SWD Read data parity mismatch");
2250 *pswd_io->
dst = data;
2253 LOG_ERROR(
"CH347 usb write/read failed - not SWD_CMD_RNW");
2266 "%s%s %s write reg %X = %08" PRIx32,
2267 check_ack ?
"" :
"ack ignored ",
2281 LOG_ERROR(
"CH347 usb write/read failed recv_len = %d", recv_len);
2334 : expected_total_clk / 5;
2336 LOG_DEBUG_IO(
"Expected queue run %u cycles, with this cmd %u",
2355 LOG_ERROR(
"ch347 SWD queue not empty after ch347_swd_run_queue");
2369 pswd_io->
value = data;
2408 LOG_ERROR(
"Sequence %d not supported", seq);
struct adapter_gpio_config gpios[ADAPTER_GPIO_IDX_NUM]
static const struct device_t * device
char * buf_to_hex_str(const void *_buf, unsigned int buf_len)
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
void * buf_cpy(const void *from, void *_to, unsigned int size)
Copies size bits out of from and into to.
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
Support functions to access arbitrary bits in a byte array.
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.
static int ch347_scratchpad_add_idle_clock(void)
Function to ensure that the clock is in a low state.
static int ch347_scratchpad_add_move_state(enum tap_state state, int skip)
Toggle the tap state to the target state.
static int ch347_cmd_from_scratchpad(void)
copy the scratchpad content into a new command in the command queue
struct adapter_driver ch347_adapter_driver
static int ch347_scratchpad_add_bytes(uint8_t *bytes, int count)
adds bytes from a buffer to the scratchpad if scratchpad is full after this byte the command will be ...
#define CH347_MAX_CMD_BUF
static int ch347_init_pack_size(void)
inits ch347.pack_size and ch347.max_len
static int ch347_swd_switch_out(enum swd_special_seq seq, const uint8_t *out, unsigned int out_len)
static int ch347_read_data(uint8_t *data, int *length)
reads data from the CH347 via libusb driver
static int ch347_scan_data_to_fields(uint8_t *decoded_buf, int decoded_buf_len)
Used to put the data from the decoded buffer into the scan command fields.
static const int ch347_larger_pack_clock_speeds[]
static void ch347_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static int ch347_quit(void)
CH347 Device Release Function.
#define CH347F_MPHSI_INTERFACE
#define DEFAULT_CH347F_PRODUCT_ID
static struct ch347_swd_io * ch347_get_one_swd_io(void)
#define CH347_MAX_PROCESSING_US
static int ch347_scratchpad_add_move_path(struct pathmove_command *cmd)
Obtain the current Tap status and switch to the status TMS value passed down by cmd.
#define CH347_SWD_CLOCK_MAX
#define DEFAULT_OTHER_PRODUCT_ID
#define CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE
static void ch347_cmd_calc_reads(struct ch347_cmd *cmd)
calculates the amount of bits and bytes that should be read for this command
static uint16_t custom_ch347_vids[]
static const struct command_registration ch347_command_handlers[]
#define DEFAULT_VENDOR_ID
static void ch347_write_swd_reg(uint8_t cmd, const uint32_t out)
#define CH347_CMD_JTAG_INIT
static int ch347_cmd_start_next(uint8_t type)
starts the next command in the scratchpad.
#define CH347_SWD_CLOCK_BASE
#define CH347_MAX_SEND_BUF
static bool ch347_is_single_cmd_type(uint8_t type)
#define CH347_CMD_INIT_READ_LEN
static int ch347_swd_run_queue(void)
static const struct swd_driver ch347_swd
#define CH347_SINGLE_CMD_MAX_READ
static int ch347_speed_get_index(int khz, int *speed_idx)
multiplies the input speed by 1000
static int ch347_adapter_set_speed(uint8_t clock_index)
Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index...
static int ch347_open_device(void)
opens the CH347 device via libusb driver
static int ch347_scratchpad_add_stableclocks(int count)
Function adds a certain amount of TCK pulses without changing the TMS pin.
static int ch347_scratchpad_add_byte(uint8_t byte)
adds one byte to the scratchpad if scratchpad is full after this byte the command will be created fro...
static int ch347_execute_queue(struct jtag_command *cmd_queue)
Executes the command queue.
static int ch347_swd_send_idle(uint32_t ap_delay_clk)
static int ch347_cmd_transmit_queue(void)
Sends the write buffer via libusb and if LARGER_PACK mode is active read also data back.
static void log_buf_dump(const uint8_t *data, unsigned int size, bool recv)
static int ch347_activity_led_set(int led_state)
Turn the activity LED on or off.
#define CH347_CMD_SWD_INIT
static int ch347_gpio_set(int gpio, bool data)
Sets a GPIO bit.
static int ch347_swd_queue_flush(void)
static int ch347_scratchpad_add_pin_byte(void)
adds the output pin byte to the scratchpad if scratchpad is full after this byte the command will be ...
static void ch347_write_spec_seq(const uint8_t *out, uint8_t out_len)
static struct libusb_device_handle * ch347_handle
#define UCMDPKT_DATA_MAX_BYTES_USBHS
static uint16_t default_ch347_pids[]
static uint16_t custom_ch347_pids[]
static int ch347_scan_queue_fields(struct scan_field *scan_fields, int scan_fields_len)
queue the scan fields into the scan queue
static int ch347_scratchpad_add_run_test(int cycles, enum tap_state state)
Toggle the Tap state to run test/idle.
#define CH347_MAX_RECV_BUF
static int ch347_speed_get(int speed_idx, int *khz)
returns the speed in kHz by the give speed index
static int ch347_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
static int ch347_swd_switch_seq(enum swd_special_seq seq)
static struct jtag_interface ch347_interface
static bool ch347_chk_buf_size(uint8_t cmd, uint32_t ap_delay_clk)
static int ch347_scratchpad_add_write_read(struct scan_command *cmd, uint8_t *bits, int bits_len, enum scan_type scan)
CH347 Batch read/write function.
#define USB_WRITE_TIMEOUT
static int ch347_write_data(uint8_t *data, int *length)
writes data to the CH347 via libusb driver
static struct ch347_info ch347
#define CH347_SWD_CLOCK_MAX_DIVISOR
#define DEFAULT_CH347T_PRODUCT_ID
#define CH347_CMD_JTAG_DATA_SHIFT
static int ch347_read_scan(uint8_t *decoded_buf, int decoded_buf_len, int raw_read_len)
Reads data back from CH347 and decode it byte- and bitwise into the buffer.
#define CH347_CMD_SWD_REG_R
static uint8_t ch347_activity_led_gpio_pin
static int ch347_scratchpad_add_tms_change(const uint8_t *tms_value, int step, int skip)
Function that performs state switching by changing the value of TMS.
static int ch347_swd_init(void)
Initialization for the swd mode.
static int ch347_single_read_get_byte(int read_buf_idx, uint8_t *byte)
Function executes the single command and deliver one byte from the buffer that's read back from USB.
#define CH347T_MPHSI_INTERFACE
static int ch347_sleep(int us)
Flushes the command buffer and sleeps for a specific timespan.
static void ch347_read_swd_reg(uint8_t cmd)
#define CH347_CMD_JTAG_BIT_OP
static int ch347_adapter_supports_larger_pack_mode(bool *supports_larger_pack_mode)
Sends the CH347_CMD_JTAG_INIT (D0) command to ask the JTAG interface with special clock index 9 for t...
static int ch347_init(void)
CH347 Initialization function.
static int ch347_adapter_init(uint8_t clock_index, bool *supports_larger_pack_mode)
Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index...
#define LARGER_PACK_MAX_SIZE
static const int ch347_standard_pack_clock_speeds[]
static uint16_t default_ch347_vids[]
static int ch347_scratchpad_add_clock_tms(bool tms)
Function used to change the TMS value at the rising edge of TCK to switch its TAP state.
static int ch347_swd_run_queue_inner(void)
#define CH347_CMD_SWD_SEQ_W
#define CH347_CMD_SWD_REG_W
static const struct command_registration ch347_subcommand_handlers[]
static void ch347_scratchpad_check_full(void)
checks if the scratchpad is full.
static void ch347_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static int ch347_swd_init_cmd(uint8_t clock_divisor)
swd init function
#define CH347_CMD_JTAG_BIT_OP_RD
static int ch347_speed_set(int speed_index)
Initializes the JTAG interface and set CH347 TCK frequency.
#define BYTEWISE_MODE_VERSION
#define USBC_PACKET_USBHS
static int ch347_reset(int trst, int srst)
Control (assert/deassert) the signals SRST and TRST on the interface.
static int ch347_scratchpad_add_scan(struct scan_command *cmd)
Switch to SHIFT-DR or SHIFT-IR status for scanning.
#define MAX_BITS_PER_BIT_OP
COMMAND_HANDLER(ch347_handle_vid_pid_command)
The command handler for setting the device usb vid/pid.
static bool ch347_activity_led_active_high
static char * ch347_device_desc
#define CH347_CMD_JTAG_DATA_SHIFT_RD
#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.
#define ERROR_COMMAND_ARGUMENT_INVALID
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
@ SCAN_IN
From device to host,.
@ SCAN_IO
Full-duplex scan.
uint32_t size
Size of dw_spi_transaction::buffer.
enum tap_state tap_state_transition(enum tap_state cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
int tap_get_tms_path_len(enum tap_state from, enum tap_state to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
enum tap_state tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
int tap_get_tms_path(enum tap_state from, enum tap_state to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
#define DEBUG_CAP_TMS_SEQ
#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...
void jtag_sleep(uint32_t us)
tap_state
Defines JTAG Test Access Port states.
#define ERROR_JTAG_TRANSITION_INVALID
static struct scan_blk scan
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)
int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_control_transfer(struct libusb_device_handle *dev, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, char *bytes, uint16_t size, unsigned int timeout, int *transferred)
void jtag_libusb_close(struct libusb_device_handle *dev)
int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
#define list_first_entry(ptr, type, member)
static void list_add_tail(struct list_head *new, struct list_head *head)
static int list_empty(const struct list_head *head)
#define list_for_each_entry_safe(p, n, h, field)
#define list_for_each_entry(p, h, field)
static void list_del(struct list_head *entry)
#define list_entry(ptr, type, field)
#define list_for_each_safe(p, n, head)
static void list_del_init(struct list_head *entry)
static void INIT_LIST_HEAD(struct list_head *list)
#define LOG_CUSTOM_LEVEL(level, expr ...)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_LEVEL_IS(FOO)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
const unsigned char bit_offset
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
static int step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
struct list_head scan_queue
struct list_head cmd_queue
bool swclk_5mhz_supported
uint8_t single_read[CH347_SINGLE_CMD_MAX_READ]
enum ch347_variant chip_variant
uint8_t scratchpad[UCMDPKT_DATA_MAX_BYTES_USBHS]
uint8_t scratchpad_cmd_type
struct scan_field * fields
struct list_head free_cmd_head
struct ch347_swd_io ch347_cmd_buf[CH347_MAX_CMD_BUF]
uint8_t send_buf[CH347_MAX_SEND_BUF]
uint8_t recv_buf[CH347_MAX_RECV_BUF]
struct list_head send_cmd_head
unsigned int total_swd_clk
struct list_head list_entry
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
This structure defines a single scan field in the scan.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned int swd_seq_dormant_to_swd_len
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
static bool swd_cmd_returns_ack(uint8_t cmd)
Test if we can rely on ACK returned by SWD command.
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
static uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver....
static const unsigned int swd_seq_jtag_to_swd_len
static const unsigned int swd_seq_line_reset_len
static const unsigned int swd_seq_dormant_to_jtag_len
static const unsigned int swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
static const unsigned int swd_seq_swd_to_jtag_len
static const unsigned int swd_seq_jtag_to_dormant_len
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
static uint16_t le_to_h_u16(const uint8_t *buf)
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#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 void h_u16_to_le(uint8_t *buf, uint16_t val)
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static unsigned int parity(unsigned int v)