78 #define JTAG_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
79 #define JTAG_MODE_ALT (LSB_FIRST | NEG_EDGE_IN | NEG_EDGE_OUT)
80 #define SWD_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
129 if (strcmp(
name, sig->name) == 0)
139 psig = &(*psig)->
next;
141 *psig = calloc(1,
sizeof(**psig));
145 (*psig)->name = strdup(
name);
146 if (!(*psig)->name) {
185 LOG_ERROR(
"invalid signal level specifier \'%c\'(0x%02x)", value, value);
189 uint16_t old_output =
output;
198 if ((
output & 0xff) != (old_output & 0xff) || (
direction & 0xff) != (old_direction & 0xff))
200 if ((
output >> 8 != old_output >> 8) || (
direction >> 8 != old_direction >> 8))
208 uint8_t data_low = 0;
209 uint8_t data_high = 0;
223 *value_out = (((uint16_t)data_high) << 8) | data_low;
226 *value_out = ~(*value_out);
253 assert(tms_count <= 8);
258 for (
int i = 0; i < tms_count; i++)
275 LOG_ERROR(
"couldn't set FTDI TCK speed");
280 LOG_INFO(
"ftdi: if you experience problems at higher adapter clocks, try "
281 "the command \"ftdi tdo_sample_edge falling\"");
298 *jtag_speed = khz * 1000;
317 cmd->cmd.runtest->num_cycles,
324 unsigned int i =
cmd->cmd.runtest->num_cycles;
327 unsigned int this_len = i > 7 ? 7 : i;
338 cmd->cmd.runtest->num_cycles,
366 cmd->cmd.tms->num_bits,
374 unsigned int num_states =
cmd->cmd.pathmove->num_states;
376 LOG_DEBUG_IO(
"pathmove: %u states, current: %s end: %s", num_states,
381 unsigned int 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) {
439 if (
cmd->cmd.scan->ir_scan) {
450 unsigned int scan_size = 0;
452 for (
unsigned 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 unsigned int num_cycles =
cmd->cmd.stableclocks->num_cycles;
585 while (num_cycles > 0) {
587 unsigned int 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");
672 LOG_ERROR(
"SWD mode is active but SWD_EN signal is not defined");
697 free((
void *)sig->
name);
715 LOG_ERROR(
"expected exactly one argument to ftdi device_desc <description>");
753 for (
unsigned int i = 1; i <
CMD_ARGC; i += 2) {
754 if (strcmp(
"-data",
CMD_ARGV[i]) == 0) {
757 }
else if (strcmp(
"-ndata",
CMD_ARGV[i]) == 0) {
760 }
else if (strcmp(
"-input",
CMD_ARGV[i]) == 0) {
763 }
else if (strcmp(
"-ninput",
CMD_ARGV[i]) == 0) {
766 }
else if (strcmp(
"-oe",
CMD_ARGV[i]) == 0) {
769 }
else if (strcmp(
"-noe",
CMD_ARGV[i]) == 0) {
772 }
else if (!strcmp(
"-alias",
CMD_ARGV[i]) ||
774 if (!strcmp(
"-nalias",
CMD_ARGV[i])) {
851 uint16_t sig_data = 0;
875 LOG_WARNING(
"incomplete ftdi vid_pid configuration directive");
900 static const struct nvp nvp_ftdi_jtag_modes[] = {
903 { .name =
NULL, .value = -1 },
922 .
name =
"device_desc",
923 .handler = &ftdi_handle_device_desc_command,
925 .help =
"set the USB device description of the FTDI device",
926 .usage =
"description_string",
930 .handler = &ftdi_handle_channel_command,
932 .help =
"set the channel of the FTDI device that is used as JTAG",
936 .name =
"layout_init",
937 .handler = &ftdi_handle_layout_init_command,
939 .help =
"initialize the FTDI GPIO signals used "
940 "to control output-enables and reset signals",
941 .usage =
"data direction",
944 .name =
"layout_signal",
945 .handler = &ftdi_handle_layout_signal_command,
947 .help =
"define a signal controlled by one or more FTDI GPIO as data "
948 "and/or output enable",
949 .usage =
"name [-data mask|-ndata mask] [-oe mask|-noe mask] [-alias|-nalias name]",
952 .name =
"set_signal",
953 .handler = &ftdi_handle_set_signal_command,
955 .help =
"control a layout-specific signal",
956 .usage =
"name (1|0|z)",
959 .name =
"get_signal",
960 .handler = &ftdi_handle_get_signal_command,
962 .help =
"read the value of a layout-specific signal",
967 .handler = &ftdi_handle_vid_pid_command,
969 .help =
"the vendor ID and product ID of the FTDI device",
970 .usage =
"(vid pid)*",
973 .name =
"tdo_sample_edge",
974 .handler = &ftdi_handle_tdo_sample_edge_command,
976 .help =
"set which TCK clock edge is used for sampling TDO "
977 "- default is rising-edge (Setting to falling-edge may "
978 "allow signalling speed increase)",
979 .usage =
"(rising|falling)",
988 .help =
"perform ftdi management",
1091 "%s%s %s %s reg %X = %08" PRIx32,
1092 check_ack ?
"" :
"ack ignored ",
1109 LOG_ERROR(
"SWD Read data parity mismatch");
1235 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 int dst_offset, const uint8_t *src, unsigned int src_offset, unsigned int bit_count)
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.
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.
#define ERROR_COMMAND_ARGUMENT_INVALID
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 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 int ftdi_execute_queue(struct jtag_command *cmd_queue)
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...
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_CUSTOM_LEVEL(level, 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_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)
void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, unsigned int length, bool tdi, uint8_t mode)
void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, uint8_t *in, unsigned int in_offset, unsigned int length, uint8_t mode)
void mpsse_clock_data_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, unsigned int length, uint8_t mode)
void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned int out_offset, uint8_t *in, unsigned int in_offset, unsigned int length, bool tdi, uint8_t mode)
struct mpsse_ctx * mpsse_open(const uint16_t vids[], const uint16_t pids[], const char *description, const char *serial, const char *location, int channel)
bool mpsse_is_high_speed(struct mpsse_ctx *ctx)
void mpsse_close(struct mpsse_ctx *ctx)
void mpsse_clock_data_in(struct mpsse_ctx *ctx, uint8_t *in, unsigned int in_offset, unsigned int length, uint8_t mode)
void mpsse_loopback_config(struct mpsse_ctx *ctx, bool enable)
void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir)
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
const struct nvp * nvp_value2name(const struct nvp *p, int value)
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
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
Name Value Pairs, aka: NVP.
This structure defines a single scan field in the scan.
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.
unsigned int num_bits
The number of bits this field specifies.
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 int swd_seq_dormant_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 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 int swd_seq_jtag_to_swd_len
static const unsigned int swd_seq_line_reset_len
static const unsigned int swd_seq_dormant_to_jtag_len
static const unsigned int swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
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 unsigned int swd_seq_swd_to_jtag_len
static const unsigned int swd_seq_jtag_to_dormant_len
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)