107 #define JTAG_PROTO_CAPS_VER 1
114 #define JTAG_BUILTIN_DESCR_START_OFF 0
119 #define JTAG_EUB_DESCR_START_OFF 2
144 #define JTAG_PROTO_CAPS_DATA_LEN 255
145 #define JTAG_PROTO_CAPS_SPEED_APB_TYPE 1
147 #define VEND_DESCR_BUILTIN_JTAG_CAPS 0x2000
149 #define VEND_JTAG_SETDIV 0
150 #define VEND_JTAG_SETIO 1
151 #define VEND_JTAG_GETTDO 2
152 #define VEND_JTAG_SET_CHIPID 3
154 #define VEND_JTAG_SETIO_TDI BIT(0)
155 #define VEND_JTAG_SETIO_TMS BIT(1)
156 #define VEND_JTAG_SETIO_TCK BIT(2)
157 #define VEND_JTAG_SETIO_TRST BIT(3)
158 #define VEND_JTAG_SETIO_SRST BIT(4)
160 #define CMD_CLK(cap, tdi, tms) ((cap ? BIT(2) : 0) | (tms ? BIT(1) : 0) | (tdi ? BIT(0) : 0))
161 #define CMD_RST(srst) (0x8 | (srst ? BIT(0) : 0))
162 #define CMD_FLUSH 0xA
164 #define CMD_REP(r) (0xC + ((r) & 3))
168 #define CMD_REP_MAX_REPS 1024
171 #define USB_CONFIGURATION 0
178 #define OUT_BUF_SZ (OUT_EP_SZ * 32)
186 #define ESP_USB_INTERFACE 1
233 LOG_ERROR(
"esp_usb_jtag: IN buffer overflow! (%d, size %d)",
263 LOG_DEBUG(
"esp_usb_jtag: usb received only %d out of %d bytes.", tr, ct);
268 if (bits_in_buf > tr * 8)
269 bits_in_buf = tr * 8;
278 LOG_DEBUG_IO(
"esp_usb_jtag: In ep: received %d bytes; %d bytes (%d bits) left.", recvd,
287 unsigned int written = 0;
289 while (written < ct) {
297 if (written + tr != ct) {
298 LOG_DEBUG(
"esp_usb_jtag: usb sent only %d out of %d bytes.",
452 LOG_ERROR(
"esp_usb_jtag: Eeek! bitq asked us for in data while not ready!");
492 LOG_ERROR(
"esp_usb_jtag: could not find or open device!");
499 LIBUSB_CLASS_VENDOR_SPEC, LIBUSB_CLASS_VENDOR_SPEC,
ESP_USB_INTERFACE, LIBUSB_TRANSFER_TYPE_BULK);
501 LOG_ERROR(
"esp_usb_jtag: error finding/claiming JTAG interface on device!");
509 int jtag_caps_read_len;
511 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_STANDARD | LIBUSB_RECIPIENT_DEVICE,
514 &jtag_caps_read_len);
516 LOG_ERROR(
"esp_usb_jtag: could not retrieve jtag_caps descriptor!");
529 LOG_ERROR(
"esp_usb_jtag: not enough data to get header");
535 LOG_ERROR(
"esp_usb_jtag: unknown jtag_caps descriptor version 0x%X!",
539 if (hdr->
length > jtag_caps_read_len) {
540 LOG_ERROR(
"esp_usb_jtag: header length (%d) bigger then max read bytes (%d)",
541 hdr->
length, jtag_caps_read_len);
551 LOG_ERROR(
"esp_usb_jtag: not enough data to get caps speed");
567 LOG_WARNING(
"esp_usb_jtag: No speed caps found... using sane-ish defaults.");
570 LOG_INFO(
"esp_usb_jtag: Device found. Base speed %dKHz, div range %d to %d",
579 LIBUSB_REQUEST_TYPE_VENDOR,
622 LOG_DEBUG(
"Divisor for %d KHz with base clock of %d khz is %d",
637 LOG_ERROR(
"esp_usb_jtag: Adaptive clocking is not supported.");
641 LOG_DEBUG(
"esp_usb_jtag: setting divisor %d", divisor);
665 uint32_t tdi, tms, tck, trst, srst;
733 .handler = &esp_usb_jtag_tdo_cmd,
735 .help =
"Returns the current state of the TDO line",
740 .handler = &esp_usb_jtag_setio_cmd,
742 .help =
"Manually set the status of the output lines",
743 .usage =
"tdi tms tck trst srst"
747 .handler = &esp_usb_jtag_vid_pid,
749 .help =
"set vendor ID and product ID for ESP usb jtag driver",
753 .name =
"caps_descriptor",
754 .handler = &esp_usb_jtag_caps_descriptor,
756 .help =
"set jtag descriptor to read capabilities of ESP usb jtag driver",
757 .usage =
"descriptor",
761 .handler = &esp_usb_jtag_chip_id,
763 .help =
"set chip_id to transfer to the bridge",
771 .
name =
"espusbjtag",
773 .help =
"ESP-USB-JTAG commands",
786 .
name =
"esp_usb_jtag",
const char *const jtag_only[]
int bitq_execute_queue(struct jtag_command *cmd_queue)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#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.
static int esp_usb_jtag_send_buf(void)
#define VEND_JTAG_SETIO_TCK
#define JTAG_EUB_DESCR_START_OFF
#define JTAG_BUILTIN_DESCR_START_OFF
static int esp_usb_jtag_command_add_raw(unsigned int cmd)
static int esp_usb_jtag_quit(void)
static struct esp_usb_jtag * priv
#define VEND_JTAG_SETIO_TMS
struct esp_usb_jtag __attribute__
#define VEND_DESCR_BUILTIN_JTAG_CAPS
static int esp_usb_jtag_khz(int khz, int *divisor)
static int esp_usb_jtag_write_rlestream(unsigned int cmd, int ct)
#define ESP_USB_INTERFACE
static int esp_usb_jtag_flush(void)
static int esp_usb_jtag_out(int tms, int tdi, int tdo_req)
static int esp_usb_jtag_init(void)
static int esp_usb_jtag_recv_buf(void)
#define JTAG_PROTO_CAPS_DATA_LEN
static int esp_usb_jtag_caps
static int esp_usb_jtag_command_add(unsigned int cmd)
static int esp_usb_jtag_in_rdy(void)
static const struct command_registration esp_usb_jtag_subcommands[]
#define VEND_JTAG_SETIO_SRST
#define VEND_JTAG_SET_CHIPID
static int esp_usb_jtag_reset(int trst, int srst)
static int esp_usb_jtag_speed_div(int divisor, int *khz)
static int esp_usb_jtag_speed(int divisor)
#define VEND_JTAG_SETIO_TRST
#define USB_CONFIGURATION
#define VEND_JTAG_SETIO_TDI
#define JTAG_PROTO_CAPS_SPEED_APB_TYPE
static const struct command_registration esp_usb_jtag_commands[]
static int esp_usb_target_chip_id
#define JTAG_PROTO_CAPS_VER
static struct jtag_interface esp_usb_jtag_interface
COMMAND_HANDLER(esp_usb_jtag_tdo_cmd)
#define CMD_CLK(cap, tdi, tms)
struct adapter_driver esp_usb_adapter_driver
static int esp_usb_jtag_in(void)
static struct esp_usb_jtag esp_usb_jtag_priv
static int esp_usb_jtag_sleep(unsigned long us)
#define DEBUG_CAP_TMS_SEQ
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_NOT_IMPLEMENTED
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)
int jtag_libusb_set_configuration(struct libusb_device_handle *devh, int configuration)
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)
int jtag_libusb_choose_interface(struct libusb_device_handle *devh, unsigned int *usb_read_ep, unsigned int *usb_write_ep, int bclass, int subclass, int protocol, int trans_type)
Find the first interface optionally matching class, subclass and protocol and claim it.
#define LIBUSB_TIMEOUT_MS
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
int(* sleep)(unsigned long us)
int(* reset)(int trst, int srst)
int(* out)(int tms, int tdi, int tdo_req)
const char * usage
a string listing the options and arguments, required or optional
unsigned int in_buf_size_bits[IN_BUF_CT]
unsigned int out_buf_pos_nibbles
unsigned int pending_in_bits
unsigned int in_buf_pos_bits
unsigned int hw_in_fifo_len
unsigned int cur_in_buf_wr
struct bitq_interface bitq_interface
struct libusb_device_handle * usb_device
uint8_t out_buf[OUT_BUF_SZ]
unsigned int cur_in_buf_rd
uint8_t in_buf[IN_BUF_CT][IN_BUF_SZ]
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
uint8_t apb_speed_10khz[2]
static uint16_t le_to_h_u16(const uint8_t *buf)