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;
286 for (i = 0; i < num_states; i++) {
297 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
321 for (i = 0; i < num_cycles; i++)
365 const uint8_t trst_mask = (1u << 5);
366 const uint8_t srst_mask = (1u << 6);
369 uint8_t change_mask = 0;
372 LOG_DEBUG(
"trst: %i, srst: %i", trst, srst);
376 outp_en &= ~srst_mask;
377 change_mask |= srst_mask;
378 }
else if (srst == 1) {
380 outp_en |= srst_mask;
381 change_mask |= srst_mask;
386 outp_en &= ~trst_mask;
387 change_mask |= trst_mask;
388 }
else if (trst == 1) {
390 outp_en |= trst_mask;
391 change_mask |= trst_mask;
400 LOG_ERROR(
"ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
413 "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
423 LOG_ERROR(
"Vref too low. Check Target Power");
425 LOG_ERROR(
"ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
441 LOG_ERROR(
"ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
451 "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s",
460 "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
478 .
name =
"armjtagew_info",
479 .handler = &armjtagew_handle_armjtagew_info_command,
481 .help =
"query armjtagew info",
492 .
name =
"arm-jtag-ew",
509 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
523 #define MAX_PENDING_SCAN_RESULTS 256
541 if (scans > available_scans ||
bits > available_bits)
552 uint8_t
bit = 1 << bit_index;
566 LOG_ERROR(
"armjtagew_tap_append_step, overflow");
580 for (i = 0; i <
length; i++)
609 for (i = 0; i < byte_length; i++)
612 tdi_offset = tms_offset + byte_length;
613 for (i = 0; i < byte_length; i++)
626 "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
631 for (i = 0; i < byte_length; i++)
647 #ifdef _DEBUG_USB_COMMS_
648 armjtagew_debug_buffer(
buffer, byte_length);
659 LOG_ERROR(
"armjtagew_tap_execute, wrong result %d, expected %d",
676 const uint16_t vids[] = {
USB_VID, 0 };
677 const uint16_t pids[] = {
USB_PID, 0 };
678 struct libusb_device_handle *dev;
688 struct libusb_config_descriptor *
config;
689 struct libusb_device *usb_dev = libusb_get_device(dev);
690 libusb_get_config_descriptor(usb_dev, 0, &
config);
691 libusb_set_configuration(dev,
config->bConfigurationValue);
693 libusb_claim_interface(dev, 0);
699 libusb_set_interface_alt_setting(dev, 0, 0);
716 if (result == out_length) {
718 if (result != in_length) {
719 LOG_ERROR(
"jtag_libusb_bulk_read failed (requested=%d, result=%d)",
725 LOG_ERROR(
"jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result);
738 LOG_ERROR(
"armjtagew_write illegal out_length=%d (max=%d)",
747 LOG_DEBUG_IO(
"armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
749 #ifdef _DEBUG_USB_COMMS_
764 LOG_DEBUG_IO(
"armjtagew_usb_read, result = %d", result);
766 #ifdef _DEBUG_USB_COMMS_
774 #ifdef _DEBUG_USB_COMMS_
775 #define BYTES_PER_LINE 16
777 static void armjtagew_debug_buffer(uint8_t *
buffer,
int length)
782 int n = snprintf(line, 9,
"%04x", i);
784 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 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_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 void armjtagew_runtest(int num_cycles)
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_execute_queue(void)
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
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)
static void armjtagew_path_move(int num_states, tap_state_t *path)
COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
static void armjtagew_usb_close(struct armjtagew *armjtagew)
uint32_t flip_u32(uint32_t value, unsigned int num)
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned 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 first, unsigned 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.
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
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_s structure, indicating whether the command has the host scan in ...
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_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)
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
#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)
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)(void)
Execute queued commands.
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_s structures that should be sca...