77 #define JTAG_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
78 #define JTAG_MODE_ALT (LSB_FIRST | NEG_EDGE_IN | NEG_EDGE_OUT)
79 #define SWD_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
128 if (strcmp(
name, sig->name) == 0)
138 psig = &(*psig)->
next;
140 *psig = calloc(1,
sizeof(**psig));
144 (*psig)->name = strdup(
name);
145 if (!(*psig)->name) {
184 assert(0 &&
"invalid signal level specifier");
188 uint16_t old_output =
output;
197 if ((
output & 0xff) != (old_output & 0xff) || (
direction & 0xff) != (old_direction & 0xff))
199 if ((
output >> 8 != old_output >> 8) || (
direction >> 8 != old_direction >> 8))
207 uint8_t data_low = 0;
208 uint8_t data_high = 0;
222 *value_out = (((uint16_t)data_high) << 8) | data_low;
225 *value_out = ~(*value_out);
252 assert(tms_count <= 8);
257 for (
int i = 0; i < tms_count; i++)
274 LOG_ERROR(
"couldn't set FTDI TCK speed");
279 LOG_INFO(
"ftdi: if you experience problems at higher adapter clocks, try "
280 "the command \"ftdi tdo_sample_edge falling\"");
297 *jtag_speed = khz * 1000;
317 cmd->cmd.runtest->num_cycles,
324 i =
cmd->cmd.runtest->num_cycles;
327 unsigned this_len = i > 7 ? 7 : i;
338 cmd->cmd.runtest->num_cycles,
366 cmd->cmd.tms->num_bits,
374 int num_states =
cmd->cmd.pathmove->num_states;
376 LOG_DEBUG_IO(
"pathmove: %i states, current: %s end: %s", num_states,
381 unsigned bit_count = 0;
382 uint8_t tms_byte = 0;
387 while (num_states--) {
391 == path[state_count])
394 == path[state_count]) {
400 "TAP state transition",
409 if (bit_count == 7 || num_states == 0) {
424 LOG_DEBUG_IO(
"%s type:%d",
cmd->cmd.scan->ir_scan ?
"IRSCAN" :
"DRSCAN",
428 while (
cmd->cmd.scan->num_fields > 0
429 &&
cmd->cmd.scan->fields[
cmd->cmd.scan->num_fields - 1].num_bits == 0) {
430 cmd->cmd.scan->num_fields--;
434 if (
cmd->cmd.scan->num_fields == 0) {
439 if (
cmd->cmd.scan->ir_scan) {
450 unsigned scan_size = 0;
452 for (
int i = 0; i <
cmd->cmd.scan->num_fields; i++, field++) {
458 cmd->cmd.scan->num_fields,
471 uint8_t last_bit = 0;
478 uint8_t tms_bits = 0x03;
520 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR", scan_size,
536 LOG_ERROR(
"Can't assert TRST: nTRST signal is not defined");
550 LOG_ERROR(
"Can't assert SRST: nSRST signal is not defined");
578 int num_cycles =
cmd->cmd.stableclocks->num_cycles;
585 while (num_cycles > 0) {
587 unsigned this_len = num_cycles > 7 ? 7 : num_cycles;
589 num_cycles -= this_len;
593 cmd->cmd.stableclocks->num_cycles,
622 LOG_ERROR(
"BUG: unknown JTAG command type encountered: %d",
cmd->type);
644 LOG_ERROR(
"error while flushing MPSSE queue: %d", retval);
652 LOG_DEBUG(
"ftdi interface using 7 step jtag state transitions");
654 LOG_DEBUG(
"ftdi interface using shortest path jtag state transitions");
657 LOG_ERROR(
"Please specify ftdi vid_pid");
677 LOG_ERROR(
"SWD mode is active but SWD_EN signal is not defined");
702 free((
void *)sig->
name);
720 LOG_ERROR(
"expected exactly one argument to ftdi device_desc <description>");
758 for (
unsigned i = 1; i <
CMD_ARGC; i += 2) {
759 if (strcmp(
"-data",
CMD_ARGV[i]) == 0) {
762 }
else if (strcmp(
"-ndata",
CMD_ARGV[i]) == 0) {
765 }
else if (strcmp(
"-input",
CMD_ARGV[i]) == 0) {
768 }
else if (strcmp(
"-ninput",
CMD_ARGV[i]) == 0) {
771 }
else if (strcmp(
"-oe",
CMD_ARGV[i]) == 0) {
774 }
else if (strcmp(
"-noe",
CMD_ARGV[i]) == 0) {
777 }
else if (!strcmp(
"-alias",
CMD_ARGV[i]) ||
779 if (!strcmp(
"-nalias",
CMD_ARGV[i])) {
856 uint16_t sig_data = 0;
880 LOG_WARNING(
"incomplete ftdi vid_pid configuration directive");
905 static const struct jim_nvp nvp_ftdi_jtag_modes[] = {
908 { .name =
NULL, .value = -1 },
927 .
name =
"device_desc",
928 .handler = &ftdi_handle_device_desc_command,
930 .help =
"set the USB device description of the FTDI device",
931 .usage =
"description_string",
935 .handler = &ftdi_handle_channel_command,
937 .help =
"set the channel of the FTDI device that is used as JTAG",
941 .name =
"layout_init",
942 .handler = &ftdi_handle_layout_init_command,
944 .help =
"initialize the FTDI GPIO signals used "
945 "to control output-enables and reset signals",
946 .usage =
"data direction",
949 .name =
"layout_signal",
950 .handler = &ftdi_handle_layout_signal_command,
952 .help =
"define a signal controlled by one or more FTDI GPIO as data "
953 "and/or output enable",
954 .usage =
"name [-data mask|-ndata mask] [-oe mask|-noe mask] [-alias|-nalias name]",
957 .name =
"set_signal",
958 .handler = &ftdi_handle_set_signal_command,
960 .help =
"control a layout-specific signal",
961 .usage =
"name (1|0|z)",
964 .name =
"get_signal",
965 .handler = &ftdi_handle_get_signal_command,
967 .help =
"read the value of a layout-specific signal",
972 .handler = &ftdi_handle_vid_pid_command,
974 .help =
"the vendor ID and product ID of the FTDI device",
975 .usage =
"(vid pid)*",
978 .name =
"tdo_sample_edge",
979 .handler = &ftdi_handle_tdo_sample_edge_command,
981 .help =
"set which TCK clock edge is used for sampling TDO "
982 "- default is rising-edge (Setting to falling-edge may "
983 "allow signalling speed increase)",
984 .usage =
"(rising|falling)",
993 .help =
"perform ftdi management",
1096 check_ack ?
"" :
"ack ignored ",
1113 LOG_ERROR(
"SWD Read data parity mismatch");
1239 LOG_ERROR(
"Sequence %d not supported", seq);
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
const char * adapter_usb_get_location(void)
static void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
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.
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.
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
enum scan_type jtag_scan_type(const struct scan_command *cmd)
COMMAND_HANDLER(ftdi_handle_device_desc_command)
static uint8_t ftdi_channel
static const struct command_registration ftdi_command_handlers[]
static void ftdi_swd_swdio_en(bool enable)
static void ftdi_execute_sleep(struct jtag_command *cmd)
static int ftdi_execute_queue(void)
static struct signal * create_signal(const char *name)
static void ftdi_execute_stableclocks(struct jtag_command *cmd)
static void ftdi_execute_pathmove(struct jtag_command *cmd)
static int ftdi_swd_init(void)
static uint16_t direction
static char * ftdi_device_desc
static void ftdi_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static struct jtag_interface ftdi_interface
static uint16_t jtag_output_init
static int ftdi_speed(int speed)
static int ftdi_get_signal(const struct signal *s, uint16_t *value_out)
static size_t swd_cmd_queue_length
struct adapter_driver ftdi_adapter_driver
static const struct swd_driver ftdi_swd
static struct mpsse_ctx * mpsse_ctx
static void ftdi_execute_tms(struct jtag_command *cmd)
Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine.
static size_t swd_cmd_queue_alloced
static const char *const ftdi_transports[]
static int ftdi_reset(int trst, int srst)
static int ftdi_khz(int khz, int *jtag_speed)
static int ftdi_speed_div(int speed, int *khz)
static uint16_t ftdi_pid[MAX_USB_IDS+1]
static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
static int ftdi_swd_run_queue(void)
Flush the MPSSE queue and process the SWD transaction queue.
static uint16_t jtag_direction_init
static struct signal * find_signal_by_name(const char *name)
static int ftdi_initialize(void)
static int ftdi_quit(void)
static void ftdi_end_state(tap_state_t state)
static void move_to_state(tap_state_t goal_state)
Function move_to_state moves the TAP controller from the current state to a goal_state through a path...
static void ftdi_execute_statemove(struct jtag_command *cmd)
static int create_default_signal(const char *name, uint16_t data_mask)
static void ftdi_execute_scan(struct jtag_command *cmd)
static uint8_t ftdi_jtag_mode
static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static uint16_t ftdi_vid[MAX_USB_IDS+1]
static int ftdi_swd_switch_seq(enum swd_special_seq seq)
static void ftdi_execute_runtest(struct jtag_command *cmd)
static int create_signals(void)
static const struct command_registration ftdi_subcommand_handlers[]
static int ftdi_set_signal(const struct signal *s, char value)
static struct signal * signals
static struct swd_cmd_queue_entry * swd_cmd_queue
static void ftdi_execute_command(struct jtag_command *cmd)
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 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...
struct jim_nvp * jim_nvp_name2value_simple(const struct jim_nvp *p, const char *name)
struct jim_nvp * jim_nvp_value2name_simple(const struct jim_nvp *p, int value)
void jtag_sleep(uint32_t us)
enum reset_types jtag_get_reset_config(void)
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_USER(expr ...)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
int mpsse_flush(struct mpsse_ctx *ctx)
void mpsse_clock_data_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, unsigned length, uint8_t mode)
void mpsse_read_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t *data)
void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
int mpsse_set_frequency(struct mpsse_ctx *ctx, int frequency)
void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data)
struct mpsse_ctx * mpsse_open(const uint16_t *vid, const uint16_t *pid, const char *description, const char *serial, const char *location, int channel)
void mpsse_clock_data_in(struct mpsse_ctx *ctx, uint8_t *in, unsigned in_offset, unsigned length, uint8_t mode)
bool mpsse_is_high_speed(struct mpsse_ctx *ctx)
void mpsse_close(struct mpsse_ctx *ctx)
void mpsse_loopback_config(struct mpsse_ctx *ctx, bool enable)
void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in, unsigned in_offset, unsigned length, bool tdi, uint8_t mode)
void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, unsigned length, bool tdi, uint8_t mode)
void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in, unsigned in_offset, unsigned length, uint8_t mode)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
const char * usage
a string listing the options and arguments, required or optional
Name Value Pairs, aka: NVP.
Represents a driver for a debugging interface.
unsigned supported
Bit vector listing capabilities exposed by this driver.
This structure defines a single scan field in the scan.
int num_bits
The number of bits this field specifies.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4+3+32+1+4, 8)]
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned swd_seq_swd_to_jtag_len
static const unsigned swd_seq_jtag_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 const unsigned swd_seq_dormant_to_swd_len
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 const unsigned swd_seq_jtag_to_dormant_len
static const unsigned swd_seq_dormant_to_jtag_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const unsigned swd_seq_line_reset_len
static const unsigned swd_seq_swd_to_dormant_len
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 uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static unsigned int parity(unsigned int v)