17 #define USB_VID 0x15ba
18 #define USB_PID 0x001e
20 #define ARMJTAGEW_EPT_BULK_OUT 0x01u
21 #define ARMJTAGEW_EPT_BULK_IN 0x82u
23 #define ARMJTAGEW_USB_TIMEOUT 2000
25 #define ARMJTAGEW_IN_BUFFER_SIZE (4*1024)
26 #define ARMJTAGEW_OUT_BUFFER_SIZE (4*1024)
29 #define CMD_GET_VERSION 0x00
30 #define CMD_SELECT_DPIMPL 0x10
31 #define CMD_SET_TCK_FREQUENCY 0x11
32 #define CMD_GET_TCK_FREQUENCY 0x12
33 #define CMD_MEASURE_MAX_TCK_FREQ 0x15
34 #define CMD_MEASURE_RTCK_RESPONSE 0x16
35 #define CMD_TAP_SHIFT 0x17
36 #define CMD_SET_TAPHW_STATE 0x20
37 #define CMD_GET_TAPHW_STATE 0x21
38 #define CMD_TGPWR_SETUP 0x22
79 #ifdef _DEBUG_USB_COMMS_
80 static void armjtagew_debug_buffer(uint8_t *
buffer,
int length);
99 cmd->cmd.runtest->num_cycles,
100 cmd->cmd.runtest->end_state);
115 cmd->cmd.pathmove->num_states,
116 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
119 cmd->cmd.pathmove->path);
130 #ifdef _DEBUG_USB_COMMS_
131 armjtagew_debug_buffer(
buffer, (scan_size + 7) / 8);
136 scan_size,
cmd->cmd.scan);
141 cmd->cmd.reset->trst,
142 cmd->cmd.reset->srst);
146 if (
cmd->cmd.reset->trst == 1)
158 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
180 LOG_ERROR(
"ARM-JTAG-EW setting speed failed (%d)", result);
188 LOG_ERROR(
"ARM-JTAG-EW getting speed failed (%d)", result);
191 LOG_INFO(
"Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
218 "Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
223 while (check_cnt < 3) {
234 LOG_INFO(
"ARM-JTAG-EW initial read failed, don't worry");
239 LOG_INFO(
"ARM-JTAG-EW JTAG Interface ready");
274 for (i = 0; i < tms_count; i++) {
275 tms = (tms_scan >> i) & 1;
284 for (
unsigned int i = 0; i < num_states; i++) {
295 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
317 for (
unsigned int i = 0; i < num_cycles; i++)
361 const uint8_t trst_mask = (1u << 5);
362 const uint8_t srst_mask = (1u << 6);
365 uint8_t change_mask = 0;
368 LOG_DEBUG(
"trst: %i, srst: %i", trst, srst);
372 outp_en &= ~srst_mask;
373 change_mask |= srst_mask;
374 }
else if (srst == 1) {
376 outp_en |= srst_mask;
377 change_mask |= srst_mask;
382 outp_en &= ~trst_mask;
383 change_mask |= trst_mask;
384 }
else if (trst == 1) {
386 outp_en |= trst_mask;
387 change_mask |= trst_mask;
396 LOG_ERROR(
"ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
409 "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
419 LOG_ERROR(
"Vref too low. Check Target Power");
421 LOG_ERROR(
"ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
437 LOG_ERROR(
"ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
447 "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s",
456 "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
474 .
name =
"armjtagew_info",
475 .handler = &armjtagew_handle_armjtagew_info_command,
477 .help =
"query armjtagew info",
488 .
name =
"arm-jtag-ew",
505 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
519 #define MAX_PENDING_SCAN_RESULTS 256
537 if (scans > available_scans ||
bits > available_bits)
548 uint8_t
bit = 1 << bit_index;
562 LOG_ERROR(
"armjtagew_tap_append_step, overflow");
576 for (i = 0; i <
length; i++)
605 for (i = 0; i < byte_length; i++)
608 tdi_offset = tms_offset + byte_length;
609 for (i = 0; i < byte_length; i++)
622 "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
627 for (i = 0; i < byte_length; i++)
643 #ifdef _DEBUG_USB_COMMS_
644 armjtagew_debug_buffer(
buffer, byte_length);
655 LOG_ERROR(
"armjtagew_tap_execute, wrong result %d, expected %d",
672 const uint16_t vids[] = {
USB_VID, 0 };
673 const uint16_t pids[] = {
USB_PID, 0 };
674 struct libusb_device_handle *dev;
684 struct libusb_config_descriptor *
config;
685 struct libusb_device *usb_dev = libusb_get_device(dev);
686 libusb_get_config_descriptor(usb_dev, 0, &
config);
687 libusb_set_configuration(dev,
config->bConfigurationValue);
689 libusb_claim_interface(dev, 0);
695 libusb_set_interface_alt_setting(dev, 0, 0);
712 if (result == out_length) {
714 if (result != in_length) {
715 LOG_ERROR(
"jtag_libusb_bulk_read failed (requested=%d, result=%d)",
721 LOG_ERROR(
"jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result);
734 LOG_ERROR(
"armjtagew_write illegal out_length=%d (max=%d)",
743 LOG_DEBUG_IO(
"armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
745 #ifdef _DEBUG_USB_COMMS_
760 LOG_DEBUG_IO(
"armjtagew_usb_read, result = %d", result);
762 #ifdef _DEBUG_USB_COMMS_
770 #ifdef _DEBUG_USB_COMMS_
771 #define BYTES_PER_LINE 16
773 static void armjtagew_debug_buffer(uint8_t *
buffer,
int length)
778 int n = snprintf(line, 9,
"%04x", i);
780 n += snprintf(line + n, 4,
" %02x",
buffer[j]);
const char *const jtag_only[]
static uint8_t tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
static void armjtagew_end_state(tap_state_t state)
#define MAX_PENDING_SCAN_RESULTS
static int armjtagew_init(void)
static uint8_t usb_in_buffer[ARMJTAGEW_IN_BUFFER_SIZE]
static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
static void armjtagew_tap_ensure_space(int scans, int bits)
#define CMD_GET_TAPHW_STATE
static int armjtagew_tap_execute(void)
static int armjtagew_execute_queue(struct jtag_command *cmd_queue)
static struct armjtagew * armjtagew_usb_open(void)
static uint8_t tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
#define CMD_SET_TCK_FREQUENCY
static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
#define ARMJTAGEW_USB_TIMEOUT
static void armjtagew_reset(int trst, int srst)
#define ARMJTAGEW_OUT_BUFFER_SIZE
static uint8_t usb_out_buffer[ARMJTAGEW_OUT_BUFFER_SIZE]
static struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS]
static void armjtagew_tap_append_step(int tms, int tdi)
static void armjtagew_runtest(unsigned int num_cycles)
static void armjtagew_state_move(void)
static int armjtagew_khz(int khz, int *jtag_speed)
#define CMD_SET_TAPHW_STATE
#define ARMJTAGEW_EPT_BULK_OUT
static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
static struct armjtagew * armjtagew_handle
static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
struct adapter_driver armjtagew_adapter_driver
#define CMD_GET_TCK_FREQUENCY
static int armjtagew_speed_div(int speed, int *khz)
#define ARMJTAGEW_EPT_BULK_IN
static void armjtagew_tap_init(void)
static const struct command_registration armjtagew_command_handlers[]
static struct jtag_interface armjtagew_interface
static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
static void armjtagew_path_move(unsigned int num_states, tap_state_t *path)
static int armjtagew_get_version_info(void)
static int armjtagew_quit(void)
static int armjtagew_speed(int speed)
static int pending_scan_results_length
#define ARMJTAGEW_TAP_BUFFER_SIZE
#define ARMJTAGEW_IN_BUFFER_SIZE
static int armjtagew_get_status(void)
COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
static void armjtagew_usb_close(struct armjtagew *armjtagew)
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
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 void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, 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...
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
tap_state_t tap_state_transition(tap_state_t 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(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#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...
static struct device_config config
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_DEVICE_ERROR
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
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_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t bit(uint32_t value, unsigned int b)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
struct libusb_device_handle * usb_handle
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
int first
First bit position in tdo_buffer to read.
int length
Number of bits to read.
uint8_t * buffer
Location to store the result.
struct scan_command * command
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...