OpenOCD
ch347.c File Reference
Include dependency graph for ch347.c:

Go to the source code of this file.

Data Structures

struct  ch347_cmd
 
struct  ch347_info
 
struct  ch347_scan
 
struct  ch347_swd_context
 
struct  ch347_swd_io
 

Macros

#define BYTEWISE_MODE_VERSION   0x241
 
#define CH347_CMD_GPIO   0xCC
 
#define CH347_CMD_HEADER   3
 
#define CH347_CMD_INFO_RD   0xCA
 
#define CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE   9
 
#define CH347_CMD_INIT_READ_LEN   1
 
#define CH347_CMD_JTAG_BIT_OP   0xD1
 
#define CH347_CMD_JTAG_BIT_OP_RD   0xD2
 
#define CH347_CMD_JTAG_DATA_SHIFT   0xD3
 
#define CH347_CMD_JTAG_DATA_SHIFT_RD   0xD4
 
#define CH347_CMD_JTAG_INIT   0xD0
 
#define CH347_CMD_SWD   0xE8
 
#define CH347_CMD_SWD_INIT   0xE5
 
#define CH347_CMD_SWD_REG_R   0xA2
 
#define CH347_CMD_SWD_REG_W   0xA0
 
#define CH347_CMD_SWD_SEQ_W   0xA1
 
#define CH347_EPIN   0x86u
 
#define CH347_EPOUT   0x06u
 
#define CH347_MAX_CMD_BUF   128
 
#define CH347_MAX_PROCESSING_US   7000
 
#define CH347_MAX_RECV_BUF   USBC_PACKET_USBHS
 
#define CH347_MAX_SEND_BUF   USBC_PACKET_USBHS
 
#define CH347_SINGLE_CMD_MAX_READ   MAX(GPIO_CNT, CH347_CMD_INIT_READ_LEN)
 
#define CH347_SWD_CLOCK_BASE   1000
 
#define CH347_SWD_CLOCK_MAX   5000
 
#define CH347_SWD_CLOCK_MAX_DIVISOR   (CH347_MAX_PROCESSING_US / swd_seq_dormant_to_swd_len)
 
#define CH347F_MPHSI_INTERFACE   4
 
#define CH347T_MPHSI_INTERFACE   2
 
#define DEFAULT_CH347F_PRODUCT_ID   0x55de
 
#define DEFAULT_CH347T_PRODUCT_ID   0x55dd
 
#define DEFAULT_OTHER_PRODUCT_ID   0x55e7
 
#define DEFAULT_VENDOR_ID   0x1a86
 
#define GPIO_CNT   8
 
#define GPIO_SET_H   (BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7))
 
#define GPIO_SET_L   (BIT(4) | BIT(5) | BIT(6) | BIT(7))
 
#define HW_TDO_BUF_SIZE   4096
 
#define LARGER_PACK_MAX_SIZE   51200
 
#define LED_OFF   0
 
#define LED_ON   1
 
#define MAX_BITS_PER_BIT_OP   248
 
#define TCK_H   BIT(0)
 
#define TCK_L   0
 
#define TDI_H   BIT(4)
 
#define TDI_L   0
 
#define TMS_H   BIT(1)
 
#define TMS_L   0
 
#define TRST_H   BIT(5)
 
#define TRST_L   0
 
#define UCMDPKT_DATA_MAX_BYTES_USBHS   507
 
#define USB_READ_TIMEOUT   500
 
#define USB_WRITE_TIMEOUT   500
 
#define USBC_PACKET_USBHS   512
 
#define USEABLE_GPIOS   0x78
 
#define VENDOR_VERSION   0x5F
 

Enumerations

enum  ch347_variant { CH347T = 0 , CH347F = 1 , OTHER_PRODUCT_ID = 2 }
 
enum  pack_size { UNSET = -1 , STANDARD_PACK = 0 , LARGER_PACK = 1 }
 

Functions

static int ch347_activity_led_set (int led_state)
 Turn the activity LED on or off. More...
 
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 or asking with special clock index 9 for the LARGER_PACK mode support. More...
 
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. More...
 
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 the LARGER_PACK mode support. More...
 
static bool ch347_chk_buf_size (uint8_t cmd, uint32_t ap_delay_clk)
 
static void ch347_cmd_calc_reads (struct ch347_cmd *cmd)
 calculates the amount of bits and bytes that should be read for this command More...
 
static int ch347_cmd_from_scratchpad (void)
 copy the scratchpad content into a new command in the command queue More...
 
static int ch347_cmd_start_next (uint8_t type)
 starts the next command in the scratchpad. More...
 
static int ch347_cmd_transmit_queue (void)
 Sends the write buffer via libusb and if LARGER_PACK mode is active read also data back. More...
 
static int ch347_execute_queue (struct jtag_command *cmd_queue)
 Executes the command queue. More...
 
static struct ch347_swd_ioch347_get_one_swd_io (void)
 
static int ch347_gpio_set (int gpio, bool data)
 Sets a GPIO bit. More...
 
static int ch347_init (void)
 CH347 Initialization function. More...
 
static int ch347_init_pack_size (void)
 inits ch347.pack_size and ch347.max_len More...
 
static bool ch347_is_single_cmd_type (uint8_t type)
 
static int ch347_open_device (void)
 opens the CH347 device via libusb driver More...
 
static int ch347_quit (void)
 CH347 Device Release Function. More...
 
static int ch347_read_data (uint8_t *data, int *length)
 reads data from the CH347 via libusb driver More...
 
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. More...
 
static void ch347_read_swd_reg (uint8_t cmd)
 
static int ch347_reset (int trst, int srst)
 Control (assert/deassert) the signals SRST and TRST on the interface. More...
 
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. More...
 
static int ch347_scan_queue_fields (struct scan_field *scan_fields, int scan_fields_len)
 queue the scan fields into the scan queue More...
 
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 from the scratchpad and the scratchpad is cleared for the next command More...
 
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 created from the scratchpad and the scratchpad is cleared for the next command More...
 
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. More...
 
static int ch347_scratchpad_add_idle_clock (void)
 Function to ensure that the clock is in a low state. More...
 
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. More...
 
static int ch347_scratchpad_add_move_state (enum tap_state state, int skip)
 Toggle the tap state to the target state. More...
 
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 created from the scratchpad and the scratchpad is cleared for the next command More...
 
static int ch347_scratchpad_add_run_test (int cycles, enum tap_state state)
 Toggle the Tap state to run test/idle. More...
 
static int ch347_scratchpad_add_scan (struct scan_command *cmd)
 Switch to SHIFT-DR or SHIFT-IR status for scanning. More...
 
static int ch347_scratchpad_add_stableclocks (int count)
 Function adds a certain amount of TCK pulses without changing the TMS pin. More...
 
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. More...
 
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. More...
 
static void ch347_scratchpad_check_full (void)
 checks if the scratchpad is full. More...
 
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. More...
 
static int ch347_sleep (int us)
 Flushes the command buffer and sleeps for a specific timespan. More...
 
static int ch347_speed_get (int speed_idx, int *khz)
 returns the speed in kHz by the give speed index More...
 
static int ch347_speed_get_index (int khz, int *speed_idx)
 multiplies the input speed by 1000 More...
 
static int ch347_speed_set (int speed_index)
 Initializes the JTAG interface and set CH347 TCK frequency. More...
 
static int ch347_swd_init (void)
 Initialization for the swd mode. More...
 
static int ch347_swd_init_cmd (uint8_t clock_divisor)
 swd init function More...
 
static int ch347_swd_queue_cmd (uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
 
static int ch347_swd_queue_flush (void)
 
static void ch347_swd_read_reg (uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 
static int ch347_swd_run_queue (void)
 
static int ch347_swd_run_queue_inner (void)
 
static int ch347_swd_send_idle (uint32_t ap_delay_clk)
 
static int ch347_swd_switch_out (enum swd_special_seq seq, const uint8_t *out, unsigned int out_len)
 
static int ch347_swd_switch_seq (enum swd_special_seq seq)
 
static void ch347_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 
static int ch347_write_data (uint8_t *data, int *length)
 writes data to the CH347 via libusb driver More...
 
static void ch347_write_spec_seq (const uint8_t *out, uint8_t out_len)
 
static void ch347_write_swd_reg (uint8_t cmd, const uint32_t out)
 
 COMMAND_HANDLER (ch347_handle_activity_led_command)
 The command handler for configuring which GPIO pin is used as activity LED. More...
 
 COMMAND_HANDLER (ch347_handle_device_desc_command)
 The command handler for setting the device description that should be found. More...
 
 COMMAND_HANDLER (ch347_handle_vid_pid_command)
 The command handler for setting the device usb vid/pid. More...
 
static void log_buf_dump (const uint8_t *data, unsigned int size, bool recv)
 

Variables

static struct ch347_info ch347
 
static bool ch347_activity_led_active_high
 
static uint8_t ch347_activity_led_gpio_pin = 0xFF
 
struct adapter_driver ch347_adapter_driver
 
static const struct command_registration ch347_command_handlers []
 
static char * ch347_device_desc
 
static struct libusb_device_handle * ch347_handle
 
static struct jtag_interface ch347_interface
 
static const int ch347_larger_pack_clock_speeds []
 
static const int ch347_standard_pack_clock_speeds []
 
static const struct command_registration ch347_subcommand_handlers []
 
static const struct swd_driver ch347_swd
 
static struct ch347_swd_context ch347_swd_context
 
static uint16_t custom_ch347_pids [] = {0, 0, 0, 0}
 
static uint16_t custom_ch347_vids [] = {0, 0, 0, 0}
 
static uint16_t default_ch347_pids []
 
static uint16_t default_ch347_vids [] = {DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, 0}
 
static bool swd_mode
 

Macro Definition Documentation

◆ BYTEWISE_MODE_VERSION

#define BYTEWISE_MODE_VERSION   0x241

Definition at line 135 of file ch347.c.

◆ CH347_CMD_GPIO

#define CH347_CMD_GPIO   0xCC

Definition at line 103 of file ch347.c.

◆ CH347_CMD_HEADER

#define CH347_CMD_HEADER   3

Definition at line 93 of file ch347.c.

◆ CH347_CMD_INFO_RD

#define CH347_CMD_INFO_RD   0xCA

Definition at line 102 of file ch347.c.

◆ CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE

#define CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE   9

Definition at line 96 of file ch347.c.

◆ CH347_CMD_INIT_READ_LEN

#define CH347_CMD_INIT_READ_LEN   1

Definition at line 94 of file ch347.c.

◆ CH347_CMD_JTAG_BIT_OP

#define CH347_CMD_JTAG_BIT_OP   0xD1

Definition at line 105 of file ch347.c.

◆ CH347_CMD_JTAG_BIT_OP_RD

#define CH347_CMD_JTAG_BIT_OP_RD   0xD2

Definition at line 106 of file ch347.c.

◆ CH347_CMD_JTAG_DATA_SHIFT

#define CH347_CMD_JTAG_DATA_SHIFT   0xD3

Definition at line 107 of file ch347.c.

◆ CH347_CMD_JTAG_DATA_SHIFT_RD

#define CH347_CMD_JTAG_DATA_SHIFT_RD   0xD4

Definition at line 108 of file ch347.c.

◆ CH347_CMD_JTAG_INIT

#define CH347_CMD_JTAG_INIT   0xD0

Definition at line 104 of file ch347.c.

◆ CH347_CMD_SWD

#define CH347_CMD_SWD   0xE8

Definition at line 114 of file ch347.c.

◆ CH347_CMD_SWD_INIT

#define CH347_CMD_SWD_INIT   0xE5

Definition at line 113 of file ch347.c.

◆ CH347_CMD_SWD_REG_R

#define CH347_CMD_SWD_REG_R   0xA2

Definition at line 117 of file ch347.c.

◆ CH347_CMD_SWD_REG_W

#define CH347_CMD_SWD_REG_W   0xA0

Definition at line 115 of file ch347.c.

◆ CH347_CMD_SWD_SEQ_W

#define CH347_CMD_SWD_SEQ_W   0xA1

Definition at line 116 of file ch347.c.

◆ CH347_EPIN

#define CH347_EPIN   0x86u

Definition at line 129 of file ch347.c.

◆ CH347_EPOUT

#define CH347_EPOUT   0x06u

Definition at line 128 of file ch347.c.

◆ CH347_MAX_CMD_BUF

#define CH347_MAX_CMD_BUF   128

Definition at line 122 of file ch347.c.

◆ CH347_MAX_PROCESSING_US

#define CH347_MAX_PROCESSING_US   7000

Definition at line 118 of file ch347.c.

◆ CH347_MAX_RECV_BUF

#define CH347_MAX_RECV_BUF   USBC_PACKET_USBHS

Definition at line 121 of file ch347.c.

◆ CH347_MAX_SEND_BUF

#define CH347_MAX_SEND_BUF   USBC_PACKET_USBHS

Definition at line 120 of file ch347.c.

◆ CH347_SINGLE_CMD_MAX_READ

#define CH347_SINGLE_CMD_MAX_READ   MAX(GPIO_CNT, CH347_CMD_INIT_READ_LEN)

Definition at line 110 of file ch347.c.

◆ CH347_SWD_CLOCK_BASE

#define CH347_SWD_CLOCK_BASE   1000

Definition at line 124 of file ch347.c.

◆ CH347_SWD_CLOCK_MAX

#define CH347_SWD_CLOCK_MAX   5000

Definition at line 123 of file ch347.c.

◆ CH347_SWD_CLOCK_MAX_DIVISOR

#define CH347_SWD_CLOCK_MAX_DIVISOR   (CH347_MAX_PROCESSING_US / swd_seq_dormant_to_swd_len)

Definition at line 126 of file ch347.c.

◆ CH347F_MPHSI_INTERFACE

#define CH347F_MPHSI_INTERFACE   4

Definition at line 131 of file ch347.c.

◆ CH347T_MPHSI_INTERFACE

#define CH347T_MPHSI_INTERFACE   2

Definition at line 130 of file ch347.c.

◆ DEFAULT_CH347F_PRODUCT_ID

#define DEFAULT_CH347F_PRODUCT_ID   0x55de

Definition at line 140 of file ch347.c.

◆ DEFAULT_CH347T_PRODUCT_ID

#define DEFAULT_CH347T_PRODUCT_ID   0x55dd

Definition at line 139 of file ch347.c.

◆ DEFAULT_OTHER_PRODUCT_ID

#define DEFAULT_OTHER_PRODUCT_ID   0x55e7

Definition at line 141 of file ch347.c.

◆ DEFAULT_VENDOR_ID

#define DEFAULT_VENDOR_ID   0x1a86

Definition at line 138 of file ch347.c.

◆ GPIO_CNT

#define GPIO_CNT   8

Definition at line 74 of file ch347.c.

◆ GPIO_SET_H

#define GPIO_SET_H   (BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7))

Definition at line 82 of file ch347.c.

◆ GPIO_SET_L

#define GPIO_SET_L   (BIT(4) | BIT(5) | BIT(6) | BIT(7))

Definition at line 81 of file ch347.c.

◆ HW_TDO_BUF_SIZE

#define HW_TDO_BUF_SIZE   4096

Definition at line 87 of file ch347.c.

◆ LARGER_PACK_MAX_SIZE

#define LARGER_PACK_MAX_SIZE   51200

Definition at line 89 of file ch347.c.

◆ LED_OFF

#define LED_OFF   0

Definition at line 73 of file ch347.c.

◆ LED_ON

#define LED_ON   1

Definition at line 72 of file ch347.c.

◆ MAX_BITS_PER_BIT_OP

#define MAX_BITS_PER_BIT_OP   248

Definition at line 98 of file ch347.c.

◆ TCK_H

#define TCK_H   BIT(0)

Definition at line 68 of file ch347.c.

◆ TCK_L

#define TCK_L   0

Definition at line 69 of file ch347.c.

◆ TDI_H

#define TDI_H   BIT(4)

Definition at line 64 of file ch347.c.

◆ TDI_L

#define TDI_L   0

Definition at line 65 of file ch347.c.

◆ TMS_H

#define TMS_H   BIT(1)

Definition at line 66 of file ch347.c.

◆ TMS_L

#define TMS_L   0

Definition at line 67 of file ch347.c.

◆ TRST_H

#define TRST_H   BIT(5)

Definition at line 70 of file ch347.c.

◆ TRST_L

#define TRST_L   0

Definition at line 71 of file ch347.c.

◆ UCMDPKT_DATA_MAX_BYTES_USBHS

#define UCMDPKT_DATA_MAX_BYTES_USBHS   507

Definition at line 91 of file ch347.c.

◆ USB_READ_TIMEOUT

#define USB_READ_TIMEOUT   500

Definition at line 133 of file ch347.c.

◆ USB_WRITE_TIMEOUT

#define USB_WRITE_TIMEOUT   500

Definition at line 132 of file ch347.c.

◆ USBC_PACKET_USBHS

#define USBC_PACKET_USBHS   512

Definition at line 92 of file ch347.c.

◆ USEABLE_GPIOS

#define USEABLE_GPIOS   0x78

Definition at line 78 of file ch347.c.

◆ VENDOR_VERSION

#define VENDOR_VERSION   0x5F

Definition at line 84 of file ch347.c.

Enumeration Type Documentation

◆ ch347_variant

Enumerator
CH347T 
CH347F 
OTHER_PRODUCT_ID 

Definition at line 148 of file ch347.c.

◆ pack_size

enum pack_size
Enumerator
UNSET 
STANDARD_PACK 
LARGER_PACK 

Definition at line 158 of file ch347.c.

Function Documentation

◆ ch347_activity_led_set()

static int ch347_activity_led_set ( int  led_state)
static

Turn the activity LED on or off.

Parameters
led_stateLED_ON or LED_OFF
Returns
ERROR_OK at success or if pin is not configured

Definition at line 1303 of file ch347.c.

References ch347_activity_led_active_high, ch347_activity_led_gpio_pin, ch347_gpio_set(), and ERROR_OK.

Referenced by ch347_execute_queue(), and ch347_quit().

◆ ch347_adapter_init()

static int ch347_adapter_init ( uint8_t  clock_index,
bool *  supports_larger_pack_mode 
)
static

Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index or asking with special clock index 9 for the LARGER_PACK mode support.

Parameters
clock_indexClock index; special clock index 9 is used for checking if the device supports the LARGER_PACK mode
supports_larger_pack_modereturns true if the device supports the LARGER_PACK mode for newer CH347 devices; false if the device supports only the older STANDARD_PACK mode
Returns
ERROR_OK on success

Definition at line 1568 of file ch347.c.

References CH347_CMD_JTAG_INIT, ch347_cmd_start_next(), ch347_scratchpad_add_byte(), ch347_scratchpad_add_pin_byte(), ch347_single_read_get_byte(), ERROR_OK, and mode.

Referenced by ch347_adapter_set_speed(), and ch347_adapter_supports_larger_pack_mode().

◆ ch347_adapter_set_speed()

static int ch347_adapter_set_speed ( uint8_t  clock_index)
static

Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index.

Parameters
clock_indexClock index
Returns
ERROR_OK on success

Definition at line 1617 of file ch347.c.

References ch347_adapter_init().

Referenced by ch347_speed_set().

◆ ch347_adapter_supports_larger_pack_mode()

static int ch347_adapter_supports_larger_pack_mode ( bool *  supports_larger_pack_mode)
static

Sends the CH347_CMD_JTAG_INIT (D0) command to ask the JTAG interface with special clock index 9 for the LARGER_PACK mode support.

Parameters
supports_larger_pack_modereturns true if the device supports the LARGER_PACK mode for newer CH347 devices; false if the device supports only the older STANDARD_PACK mode
Returns
ERROR_OK on success

Definition at line 1605 of file ch347.c.

References ch347_adapter_init(), and CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE.

Referenced by ch347_init_pack_size().

◆ ch347_chk_buf_size()

static bool ch347_chk_buf_size ( uint8_t  cmd,
uint32_t  ap_delay_clk 
)
static

◆ ch347_cmd_calc_reads()

static void ch347_cmd_calc_reads ( struct ch347_cmd cmd)
static

calculates the amount of bits and bytes that should be read for this command

Parameters
cmdcommand for the calculation

Definition at line 447 of file ch347.c.

References CH347_CMD_GPIO, CH347_CMD_INIT_READ_LEN, CH347_CMD_JTAG_BIT_OP_RD, CH347_CMD_JTAG_DATA_SHIFT_RD, CH347_CMD_JTAG_INIT, CH347_CMD_SWD_INIT, cmd, and TCK_H.

Referenced by ch347_cmd_from_scratchpad().

◆ ch347_cmd_from_scratchpad()

static int ch347_cmd_from_scratchpad ( void  )
static

copy the scratchpad content into a new command in the command queue

Parameters
scan_fieldsarray of scan_field's for data from the device
scan_fields_lenarray length
Returns
ERROR_OK at success

Definition at line 487 of file ch347.c.

References ch347, ch347_cmd_calc_reads(), cmd, ch347_info::cmd_queue, ERROR_FAIL, ERROR_OK, list_add_tail(), LOG_ERROR, ch347_info::scratchpad, ch347_info::scratchpad_cmd_type, and ch347_info::scratchpad_idx.

Referenced by ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_scratchpad_add_write_read(), and ch347_scratchpad_check_full().

◆ ch347_cmd_start_next()

static int ch347_cmd_start_next ( uint8_t  type)
static

starts the next command in the scratchpad.

If it's the same command type it can concat the data bytes. no need to make a new command for this case

Parameters
typecommand type

Definition at line 792 of file ch347.c.

References ch347, ch347_cmd_from_scratchpad(), ch347_cmd_transmit_queue(), ch347_is_single_cmd_type(), ERROR_OK, ch347_info::scratchpad_cmd_type, ch347_info::scratchpad_idx, and type.

Referenced by ch347_adapter_init(), ch347_gpio_set(), ch347_reset(), ch347_scratchpad_add_move_path(), ch347_scratchpad_add_stableclocks(), ch347_scratchpad_add_tms_change(), ch347_scratchpad_add_write_read(), and ch347_swd_init_cmd().

◆ ch347_cmd_transmit_queue()

◆ ch347_execute_queue()

◆ ch347_get_one_swd_io()

◆ ch347_gpio_set()

static int ch347_gpio_set ( int  gpio,
bool  data 
)
static

Sets a GPIO bit.

Parameters
gpioGPIO bit number 0-7
datatrue for high; false for low
Returns
ERROR_OK at success

Definition at line 1267 of file ch347.c.

References BIT, CH347_CMD_GPIO, ch347_cmd_start_next(), ch347_scratchpad_add_bytes(), ch347_single_read_get_byte(), ERROR_FAIL, ERROR_OK, GPIO_CNT, GPIO_SET_H, GPIO_SET_L, gpios, and LOG_ERROR.

Referenced by ch347_activity_led_set().

◆ ch347_init()

◆ ch347_init_pack_size()

static int ch347_init_pack_size ( void  )
static

◆ ch347_is_single_cmd_type()

static bool ch347_is_single_cmd_type ( uint8_t  type)
inlinestatic

Definition at line 267 of file ch347.c.

References CH347_CMD_GPIO, CH347_CMD_JTAG_INIT, CH347_CMD_SWD_INIT, and type.

Referenced by ch347_cmd_start_next(), and ch347_cmd_transmit_queue().

◆ ch347_open_device()

◆ ch347_quit()

static int ch347_quit ( void  )
static

CH347 Device Release Function.

Returns
ERROR_OK on success

Definition at line 1547 of file ch347.c.

References ch347_activity_led_set(), ch347_cmd_transmit_queue(), ch347_handle, jtag_libusb_close(), LED_ON, and LOG_DEBUG_IO.

◆ ch347_read_data()

static int ch347_read_data ( uint8_t *  data,
int *  length 
)
static

reads data from the CH347 via libusb driver

Parameters
dataPoint to the data buffer
lengthData length in and out
Returns
ERROR_OK at success

Definition at line 411 of file ch347.c.

References CH347_EPIN, ch347_handle, ERROR_OK, jtag_libusb_bulk_read(), length, log_buf_dump(), LOG_DEBUG_IO, LOG_ERROR, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, and USB_READ_TIMEOUT.

Referenced by ch347_read_scan(), and ch347_swd_queue_flush().

◆ ch347_read_scan()

static int ch347_read_scan ( uint8_t *  decoded_buf,
int  decoded_buf_len,
int  raw_read_len 
)
static

Reads data back from CH347 and decode it byte- and bitwise into the buffer.

Parameters
decoded_bufPoint to a buffer to place the data to be decoded; need to be sized to the decoded size length; not the raw_read_len
decoded_buf_lenlength of the decoded_buf
raw_read_lenData length in bytes that should be read via libusb; the decoded length can be shorter
Returns
ERROR_OK at success

Definition at line 525 of file ch347.c.

References BIT, CH347_CMD_GPIO, CH347_CMD_JTAG_BIT_OP_RD, CH347_CMD_JTAG_DATA_SHIFT_RD, CH347_CMD_JTAG_INIT, CH347_CMD_SWD_INIT, ch347_read_data(), DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, le_to_h_u16(), LOG_ERROR, ch347_cmd::read_len, and type.

Referenced by ch347_cmd_transmit_queue().

◆ ch347_read_swd_reg()

static void ch347_read_swd_reg ( uint8_t  cmd)
static

◆ ch347_reset()

static int ch347_reset ( int  trst,
int  srst 
)
static

Control (assert/deassert) the signals SRST and TRST on the interface.

Parameters
trst1 to assert TRST, 0 to deassert TRST.
srst1 to assert SRST, 0 to deassert SRST.
Returns
Always ERROR_FAIL for asserting via SRST and TRST in SWD mode. ERROR_OK for assert/deassert in JTAG mode for TRST

Definition at line 1320 of file ch347.c.

References ch347, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_scratchpad_add_idle_clock(), ch347_scratchpad_add_pin_byte(), ERROR_FAIL, ERROR_OK, LOG_DEBUG_IO, LOG_ERROR, LOG_WARNING, swd_mode, TRST_H, TRST_L, and ch347_info::trst_pin.

◆ ch347_scan_data_to_fields()

static int ch347_scan_data_to_fields ( uint8_t *  decoded_buf,
int  decoded_buf_len 
)
static

Used to put the data from the decoded buffer into the scan command fields.

Parameters
decoded_bufPoint to a buffer for the decoded data
decoded_buf_lenlength of the decoded_buf
Returns
ERROR_OK at success

Definition at line 598 of file ch347.c.

References bit_offset, buf_cpy(), buf_set_buf(), buf_to_hex_str(), ch347, CH347_SINGLE_CMD_MAX_READ, DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, list_del(), list_for_each_entry_safe, LOG_DEBUG, LOG_DEBUG_IO, LOG_ERROR, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, scan, ch347_info::scan_queue, ch347_info::singe_read_len, and ch347_info::single_read.

Referenced by ch347_cmd_transmit_queue().

◆ ch347_scan_queue_fields()

static int ch347_scan_queue_fields ( struct scan_field scan_fields,
int  scan_fields_len 
)
static

queue the scan fields into the scan queue

Parameters
scan_fieldsarray of scan field's for data from the device
scan_fields_lenarray length
Returns
ERROR_OK at success

Definition at line 835 of file ch347.c.

References ch347, ERROR_FAIL, ERROR_OK, list_add_tail(), LOG_ERROR, scan, and ch347_info::scan_queue.

Referenced by ch347_scratchpad_add_write_read().

◆ ch347_scratchpad_add_byte()

static int ch347_scratchpad_add_byte ( uint8_t  byte)
static

adds one byte to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command

Parameters
byteadd this byte
Returns
ERROR_OK at success

Definition at line 896 of file ch347.c.

References ch347, ch347_scratchpad_check_full(), ERROR_FAIL, ERROR_OK, LOG_ERROR, ch347_info::scratchpad, ch347_info::scratchpad_cmd_type, and ch347_info::scratchpad_idx.

Referenced by ch347_adapter_init(), and ch347_scratchpad_add_pin_byte().

◆ ch347_scratchpad_add_bytes()

static int ch347_scratchpad_add_bytes ( uint8_t *  bytes,
int  count 
)
static

adds bytes from a buffer to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command

Parameters
bytesadd this bytes
countbyte count
Returns
ERROR_OK at success

Definition at line 930 of file ch347.c.

References ch347, ch347_scratchpad_check_full(), count, ERROR_FAIL, ERROR_OK, LOG_ERROR, ch347_info::scratchpad, ch347_info::scratchpad_cmd_type, ch347_info::scratchpad_idx, and UCMDPKT_DATA_MAX_BYTES_USBHS.

Referenced by ch347_gpio_set(), ch347_scratchpad_add_write_read(), and ch347_swd_init_cmd().

◆ ch347_scratchpad_add_clock_tms()

static int ch347_scratchpad_add_clock_tms ( bool  tms)
static

Function used to change the TMS value at the rising edge of TCK to switch its TAP state.

Parameters
tmsTMS value to be changed; true = output TMS high; false = output TMS low
Returns
ERROR_OK at success

Definition at line 964 of file ch347.c.

References ch347, ch347_scratchpad_add_pin_byte(), ERROR_OK, TCK_H, TCK_L, ch347_info::tck_pin, TMS_H, TMS_L, and ch347_info::tms_pin.

Referenced by ch347_scratchpad_add_move_path(), ch347_scratchpad_add_stableclocks(), and ch347_scratchpad_add_tms_change().

◆ ch347_scratchpad_add_idle_clock()

static int ch347_scratchpad_add_idle_clock ( void  )
static

Function to ensure that the clock is in a low state.

Returns
ERROR_OK at success

Definition at line 1007 of file ch347.c.

References ch347, ch347_scratchpad_add_pin_byte(), TCK_L, and ch347_info::tck_pin.

Referenced by ch347_reset(), ch347_scratchpad_add_move_path(), ch347_scratchpad_add_tms_change(), and ch347_scratchpad_add_write_read().

◆ ch347_scratchpad_add_move_path()

static int ch347_scratchpad_add_move_path ( struct pathmove_command cmd)
static

Obtain the current Tap status and switch to the status TMS value passed down by cmd.

Parameters
cmdUpper layer transfer command parameters
Returns
ERROR_OK at success; ERROR_JTAG_TRANSITION_INVALID if no transition is possible

Definition at line 1044 of file ch347.c.

References CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), cmd, ERROR_JTAG_TRANSITION_INVALID, ERROR_OK, LOG_DEBUG_IO, LOG_ERROR, tap_get_state(), tap_set_state, and tap_state_transition().

Referenced by ch347_execute_queue().

◆ ch347_scratchpad_add_move_state()

static int ch347_scratchpad_add_move_state ( enum tap_state  state,
int  skip 
)
static

Toggle the tap state to the target state.

Parameters
statePre switch target path
skipNumber of digits to skip
Returns
ERROR_OK at success

Definition at line 1078 of file ch347.c.

References ch347_scratchpad_add_tms_change(), ERROR_OK, LOG_DEBUG_IO, state, tap_get_state(), tap_get_tms_path(), tap_get_tms_path_len(), TAP_RESET, tap_set_state, and tap_state_name().

Referenced by ch347_execute_queue(), ch347_scratchpad_add_run_test(), and ch347_scratchpad_add_scan().

◆ ch347_scratchpad_add_pin_byte()

static int ch347_scratchpad_add_pin_byte ( void  )
static

adds the output pin byte to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command

Returns
ERROR_OK at success

Definition at line 915 of file ch347.c.

References ch347, ch347_scratchpad_add_byte(), ch347_info::tck_pin, ch347_info::tdi_pin, ch347_info::tms_pin, and ch347_info::trst_pin.

Referenced by ch347_adapter_init(), ch347_reset(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), and ch347_scratchpad_add_write_read().

◆ ch347_scratchpad_add_run_test()

static int ch347_scratchpad_add_run_test ( int  cycles,
enum tap_state  state 
)
static

Toggle the Tap state to run test/idle.

Parameters
cycleshow many clock cycles for output
stateJTAG end state
Returns
ERROR_OK at success

Definition at line 1199 of file ch347.c.

References ch347_scratchpad_add_move_state(), ch347_scratchpad_add_stableclocks(), ERROR_OK, LOG_DEBUG_IO, state, tap_get_state(), and TAP_IDLE.

Referenced by ch347_execute_queue().

◆ ch347_scratchpad_add_scan()

static int ch347_scratchpad_add_scan ( struct scan_command cmd)
static

Switch to SHIFT-DR or SHIFT-IR status for scanning.

Parameters
cmdUpper layer transfer command parameters
Returns
ERROR_OK at success

Definition at line 1222 of file ch347.c.

References buf_to_hex_str(), ch347_scratchpad_add_move_state(), ch347_scratchpad_add_write_read(), cmd, ERROR_OK, jtag_build_buffer(), jtag_scan_type(), LOG_DEBUG_IO, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, NULL, TAP_DRSHIFT, TAP_IRSHIFT, and type.

Referenced by ch347_execute_queue().

◆ ch347_scratchpad_add_stableclocks()

static int ch347_scratchpad_add_stableclocks ( int  count)
static

Function adds a certain amount of TCK pulses without changing the TMS pin.

Parameters
countAmount of L/H TCK pulses to add
Returns
ERROR_OK at success

Definition at line 982 of file ch347.c.

References ch347, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_scratchpad_add_clock_tms(), count, ERROR_OK, ch347_info::scratchpad_cmd_type, TMS_H, and ch347_info::tms_pin.

Referenced by ch347_execute_queue(), and ch347_scratchpad_add_run_test().

◆ ch347_scratchpad_add_tms_change()

static int ch347_scratchpad_add_tms_change ( const uint8_t *  tms_value,
int  step,
int  skip 
)
static

Function that performs state switching by changing the value of TMS.

Parameters
tms_valueThe TMS values that need to be switched form one byte of data in the switching order
stepThe number of bit values that need to be read from the tms_value value
skipCount from the skip bit of tms_value to step
Returns
ERROR_OK at success

Definition at line 1021 of file ch347.c.

References BIT, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), ERROR_OK, LOG_DEBUG_IO, and step().

Referenced by ch347_execute_queue(), and ch347_scratchpad_add_move_state().

◆ ch347_scratchpad_add_write_read()

static int ch347_scratchpad_add_write_read ( struct scan_command cmd,
uint8_t *  bits,
int  bits_len,
enum scan_type  scan 
)
static

CH347 Batch read/write function.

Parameters
cmdThe scan command
bitsRead and write data this time
bits_lenIncoming data length in bits
scanThe transmission method of incoming data to determine whether to perform data reading
Returns
ERROR_OK at success

Definition at line 1104 of file ch347.c.

References BIT, bits, ch347, ch347_cmd_from_scratchpad(), CH347_CMD_JTAG_BIT_OP, CH347_CMD_JTAG_BIT_OP_RD, CH347_CMD_JTAG_DATA_SHIFT, CH347_CMD_JTAG_DATA_SHIFT_RD, ch347_cmd_start_next(), ch347_scan_queue_fields(), ch347_scratchpad_add_bytes(), ch347_scratchpad_add_idle_clock(), ch347_scratchpad_add_pin_byte(), cmd, ERROR_OK, MAX_BITS_PER_BIT_OP, NULL, scan, SCAN_IN, SCAN_IO, TCK_H, TCK_L, ch347_info::tck_pin, TDI_H, TDI_L, ch347_info::tdi_pin, TMS_H, TMS_L, ch347_info::tms_pin, and ch347_info::use_bitwise_mode.

Referenced by ch347_scratchpad_add_scan().

◆ ch347_scratchpad_check_full()

static void ch347_scratchpad_check_full ( void  )
static

checks if the scratchpad is full.

If it's full the function creates a command from it and puts it into the command queue

Definition at line 878 of file ch347.c.

References ch347, ch347_cmd_from_scratchpad(), ch347_info::scratchpad_cmd_type, ch347_info::scratchpad_idx, type, and UCMDPKT_DATA_MAX_BYTES_USBHS.

Referenced by ch347_scratchpad_add_byte(), and ch347_scratchpad_add_bytes().

◆ ch347_single_read_get_byte()

static int ch347_single_read_get_byte ( int  read_buf_idx,
uint8_t *  byte 
)
static

Function executes the single command and deliver one byte from the buffer that's read back from USB.

Parameters
read_buf_idxindex of the byte that should be returned
bytereturns byte at index or if index is out of range the first byte
Returns
ERROR_OK at success

Definition at line 858 of file ch347.c.

References ch347, ch347_cmd_transmit_queue(), CH347_SINGLE_CMD_MAX_READ, ERROR_FAIL, ERROR_OK, LOG_ERROR, and ch347_info::single_read.

Referenced by ch347_adapter_init(), ch347_gpio_set(), and ch347_swd_init_cmd().

◆ ch347_sleep()

static int ch347_sleep ( int  us)
static

Flushes the command buffer and sleeps for a specific timespan.

Parameters
usSleep time in microseconds
Returns
ERROR_OK at success

Definition at line 1356 of file ch347.c.

References ch347_cmd_transmit_queue(), jtag_sleep(), and LOG_DEBUG_IO.

Referenced by ch347_execute_queue().

◆ ch347_speed_get()

static int ch347_speed_get ( int  speed_idx,
int *  khz 
)
static

returns the speed in kHz by the give speed index

Parameters
speed_idxCH347 speed index
khzOutput of the speed in kHz
Returns
ERROR_OK on success

Definition at line 1702 of file ch347.c.

References ch347, ch347_init_pack_size(), ch347_larger_pack_clock_speeds, ch347_standard_pack_clock_speeds, CH347_SWD_CLOCK_BASE, CH347_SWD_CLOCK_MAX, DIV_ROUND_UP, ERROR_OK, ch347_info::pack_size, STANDARD_PACK, and swd_mode.

◆ ch347_speed_get_index()

static int ch347_speed_get_index ( int  khz,
int *  speed_idx 
)
static

multiplies the input speed by 1000

Parameters
khzSpeed in kHz
speed_idxCH347 speed index
Returns
ERROR_OK at success; ERROR_FAIL if khz is zero

Definition at line 1728 of file ch347.c.

References ARRAY_SIZE, ch347, ch347_init_pack_size(), ch347_larger_pack_clock_speeds, ch347_standard_pack_clock_speeds, CH347_SWD_CLOCK_BASE, CH347_SWD_CLOCK_MAX, CH347_SWD_CLOCK_MAX_DIVISOR, DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, length, LOG_ERROR, LOG_INFO, MIN, ch347_info::pack_size, STANDARD_PACK, ch347_info::swclk_5mhz_supported, and swd_mode.

◆ ch347_speed_set()

static int ch347_speed_set ( int  speed_index)
static

Initializes the JTAG interface and set CH347 TCK frequency.

Parameters
speed_indexspeed index for JTAG_INIT command
Returns
Success returns ERROR_OK, failed returns ERROR_FAIL

Definition at line 1657 of file ch347.c.

References ch347_adapter_set_speed(), ch347_swd_init_cmd(), ERROR_OK, LOG_ERROR, and swd_mode.

◆ ch347_swd_init()

◆ ch347_swd_init_cmd()

static int ch347_swd_init_cmd ( uint8_t  clock_divisor)
static

swd init function

Parameters
clock_divisorDivisor of base SWD frequency 1 MHz or 0 for fast 5 MHz clock
Returns
ERROR_OK on success

Definition at line 1629 of file ch347.c.

References ARRAY_SIZE, ch347_cmd_start_next(), CH347_CMD_SWD_INIT, ch347_scratchpad_add_bytes(), ch347_single_read_get_byte(), ch347_swd_context::clk_divisor, ERROR_OK, and LOG_DEBUG.

Referenced by ch347_init(), and ch347_speed_set().

◆ ch347_swd_queue_cmd()

◆ ch347_swd_queue_flush()

◆ ch347_swd_read_reg()

static void ch347_swd_read_reg ( uint8_t  cmd,
uint32_t *  value,
uint32_t  ap_delay_clk 
)
static

◆ ch347_swd_run_queue()

static int ch347_swd_run_queue ( void  )
static

Definition at line 2312 of file ch347.c.

References ch347_swd_run_queue_inner(), ch347_swd_send_idle(), and ERROR_OK.

◆ ch347_swd_run_queue_inner()

◆ ch347_swd_send_idle()

◆ ch347_swd_switch_out()

◆ ch347_swd_switch_seq()

◆ ch347_swd_write_reg()

static void ch347_swd_write_reg ( uint8_t  cmd,
uint32_t  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 2421 of file ch347.c.

◆ ch347_write_data()

static int ch347_write_data ( uint8_t *  data,
int *  length 
)
static

writes data to the CH347 via libusb driver

Parameters
dataPoint to the data buffer
lengthData length in and out
Returns
ERROR_OK at success

Definition at line 375 of file ch347.c.

References CH347_EPOUT, ch347_handle, ERROR_OK, jtag_libusb_bulk_write(), length, log_buf_dump(), LOG_DEBUG_IO, LOG_ERROR, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, and USB_WRITE_TIMEOUT.

Referenced by ch347_cmd_transmit_queue(), and ch347_swd_queue_flush().

◆ ch347_write_spec_seq()

static void ch347_write_spec_seq ( const uint8_t *  out,
uint8_t  out_len 
)
static

◆ ch347_write_swd_reg()

static void ch347_write_swd_reg ( uint8_t  cmd,
const uint32_t  out 
)
static

◆ COMMAND_HANDLER() [1/3]

COMMAND_HANDLER ( ch347_handle_activity_led_command  )

The command handler for configuring which GPIO pin is used as activity LED.

Returns
ERROR_OK at success; ERROR_COMMAND_SYNTAX_ERROR otherwise

Definition at line 1817 of file ch347.c.

◆ COMMAND_HANDLER() [2/3]

COMMAND_HANDLER ( ch347_handle_device_desc_command  )

The command handler for setting the device description that should be found.

Returns
ERROR_OK at success; ERROR_COMMAND_SYNTAX_ERROR otherwise

Definition at line 1802 of file ch347.c.

References ch347_device_desc, CMD_ARGC, CMD_ARGV, ERROR_COMMAND_SYNTAX_ERROR, and ERROR_OK.

◆ COMMAND_HANDLER() [3/3]

COMMAND_HANDLER ( ch347_handle_vid_pid_command  )

The command handler for setting the device usb vid/pid.

Returns
ERROR_OK at success; ERROR_COMMAND_SYNTAX_ERROR otherwise

Definition at line 1784 of file ch347.c.

References ARRAY_SIZE, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, custom_ch347_pids, custom_ch347_vids, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and MIN.

◆ log_buf_dump()

static void log_buf_dump ( const uint8_t *  data,
unsigned int  size,
bool  recv 
)
static

Variable Documentation

◆ ch347

◆ ch347_activity_led_active_high

bool ch347_activity_led_active_high
static

Definition at line 261 of file ch347.c.

Referenced by ch347_activity_led_set().

◆ ch347_activity_led_gpio_pin

uint8_t ch347_activity_led_gpio_pin = 0xFF
static

Definition at line 260 of file ch347.c.

Referenced by ch347_activity_led_set().

◆ ch347_adapter_driver

struct adapter_driver ch347_adapter_driver
Initial value:
= {
.name = "ch347",
.transport_ids = TRANSPORT_JTAG | TRANSPORT_SWD,
.transport_preferred_id = TRANSPORT_JTAG,
.init = ch347_init,
.quit = ch347_quit,
.reset = ch347_reset,
.speed = ch347_speed_set,
.speed_div = ch347_speed_get,
.jtag_ops = &ch347_interface,
.swd_ops = &ch347_swd,
}
static int ch347_quit(void)
CH347 Device Release Function.
Definition: ch347.c:1547
static const struct command_registration ch347_command_handlers[]
Definition: ch347.c:1863
static const struct swd_driver ch347_swd
Definition: ch347.c:2429
static int ch347_speed_get_index(int khz, int *speed_idx)
multiplies the input speed by 1000
Definition: ch347.c:1728
static int ch347_speed_get(int speed_idx, int *khz)
returns the speed in kHz by the give speed index
Definition: ch347.c:1702
static struct jtag_interface ch347_interface
Definition: ch347.c:2437
static int ch347_init(void)
CH347 Initialization function.
Definition: ch347.c:1879
static int ch347_speed_set(int speed_index)
Initializes the JTAG interface and set CH347 TCK frequency.
Definition: ch347.c:1657
static int ch347_reset(int trst, int srst)
Control (assert/deassert) the signals SRST and TRST on the interface.
Definition: ch347.c:1320
#define TRANSPORT_SWD
Definition: transport.h:20
#define TRANSPORT_JTAG
Definition: transport.h:19

Definition at line 2421 of file ch347.c.

◆ ch347_command_handlers

const struct command_registration ch347_command_handlers[]
static
Initial value:
= {
{
.name = "ch347",
.mode = COMMAND_ANY,
.help = "perform ch347 management",
.usage = "",
},
}
static const struct command_registration ch347_subcommand_handlers[]
Definition: ch347.c:1838
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:251
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:239

Definition at line 1817 of file ch347.c.

◆ ch347_device_desc

char* ch347_device_desc
static

Definition at line 259 of file ch347.c.

Referenced by ch347_open_device(), and COMMAND_HANDLER().

◆ ch347_handle

struct libusb_device_handle* ch347_handle
static

Definition at line 263 of file ch347.c.

Referenced by ch347_open_device(), ch347_quit(), ch347_read_data(), and ch347_write_data().

◆ ch347_interface

struct jtag_interface ch347_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = ch347_execute_queue,
}
static int ch347_execute_queue(struct jtag_command *cmd_queue)
Executes the command queue.
Definition: ch347.c:1369
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:188

Definition at line 2421 of file ch347.c.

◆ ch347_larger_pack_clock_speeds

const int ch347_larger_pack_clock_speeds[]
static
Initial value:
= {
469,
938,
1875,
3750,
7500,
15000,
30000,
60000
}

Definition at line 175 of file ch347.c.

Referenced by ch347_speed_get(), and ch347_speed_get_index().

◆ ch347_standard_pack_clock_speeds

const int ch347_standard_pack_clock_speeds[]
static
Initial value:
= {
1875,
3750,
7500,
15000,
30000,
60000
}

Definition at line 165 of file ch347.c.

Referenced by ch347_speed_get(), and ch347_speed_get_index().

◆ ch347_subcommand_handlers

const struct command_registration ch347_subcommand_handlers[]
static
Initial value:
= {
{
.name = "vid_pid",
.handler = &ch347_handle_vid_pid_command,
.mode = COMMAND_CONFIG,
.help = "the vendor ID and product ID of the CH347 device",
.usage = "(vid pid)*",
},
{
.name = "device_desc",
.handler = &ch347_handle_device_desc_command,
.mode = COMMAND_CONFIG,
.help = "set the USB device description of the CH347 device",
.usage = "description_string",
},
{
.name = "activity_led",
.handler = &ch347_handle_activity_led_command,
.mode = COMMAND_CONFIG,
.help = "if set this CH347 GPIO pin is the JTAG activity LED; start with n for active low output",
.usage = "[n]gpio_number",
},
}
@ COMMAND_CONFIG
Definition: command.h:41

Definition at line 1817 of file ch347.c.

◆ ch347_swd

const struct swd_driver ch347_swd
static
Initial value:
= {
.init = ch347_swd_init,
.switch_seq = ch347_swd_switch_seq,
.read_reg = ch347_swd_read_reg,
.write_reg = ch347_swd_write_reg,
}
static void ch347_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: ch347.c:2413
static int ch347_swd_run_queue(void)
Definition: ch347.c:2312
static int ch347_swd_switch_seq(enum swd_special_seq seq)
Definition: ch347.c:2383
static int ch347_swd_init(void)
Initialization for the swd mode.
Definition: ch347.c:1917
static void ch347_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: ch347.c:2421

Definition at line 2421 of file ch347.c.

◆ ch347_swd_context

Definition at line 175 of file ch347.c.

◆ custom_ch347_pids

uint16_t custom_ch347_pids[] = {0, 0, 0, 0}
static

Definition at line 258 of file ch347.c.

Referenced by ch347_open_device(), and COMMAND_HANDLER().

◆ custom_ch347_vids

uint16_t custom_ch347_vids[] = {0, 0, 0, 0}
static

Definition at line 257 of file ch347.c.

Referenced by ch347_open_device(), and COMMAND_HANDLER().

◆ default_ch347_pids

uint16_t default_ch347_pids[]
static
Initial value:
#define DEFAULT_CH347F_PRODUCT_ID
Definition: ch347.c:140
#define DEFAULT_OTHER_PRODUCT_ID
Definition: ch347.c:141
#define DEFAULT_CH347T_PRODUCT_ID
Definition: ch347.c:139

Definition at line 255 of file ch347.c.

Referenced by ch347_open_device().

◆ default_ch347_vids

uint16_t default_ch347_vids[] = {DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, 0}
static

Definition at line 254 of file ch347.c.

Referenced by ch347_open_device().

◆ swd_mode