39 #define DEFAULT_CLOCK_SPEED_KHZ 100U
130 LOG_ERROR(
"Debug Adapter has to be specified, "
131 "see \"adapter driver\" command");
140 LOG_WARNING(
"An adapter speed is not selected in the init scripts."
141 " OpenOCD will try to run the adapter at the low speed (%d kHz)",
143 LOG_WARNING(
"To remove this warnings and achieve reasonable communication speed with the target,"
144 " set \"adapter speed\" or \"jtag_rclk\" in the init scripts.");
156 LOG_INFO(
"This adapter doesn't support configurable speed");
161 int actual_khz = requested_khz;
171 LOG_INFO(
"adapter-specific clock speed value %d", speed_var);
172 else if (actual_khz) {
176 LOG_INFO(
"RCLK (adaptive clock speed) not supported - fallback to %d kHz"
179 LOG_INFO(
"clock speed %d kHz", actual_khz);
181 LOG_INFO(
"RCLK (adaptive clock speed)");
215 LOG_DEBUG(
"convert khz to adapter specific speed value");
221 LOG_ERROR(
"Translation from khz to adapter speed not implemented");
235 if ((retval !=
ERROR_OK) && fallback_speed_khz) {
278 LOG_ERROR(
"BUG: unknown adapter clock mode");
293 LOG_ERROR(
"Translation from adapter speed to khz not implemented");
311 #define USB_MAX_LOCATION_LENGTH 16
313 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
314 static void adapter_usb_set_location(
const char *location)
332 size_t path_step, string_length;
343 ptr = strtok(loc,
"-");
349 string_length -=
strnlen(ptr, string_length);
351 if (atoi(ptr) != dev_bus)
355 while (path_step < path_len) {
356 ptr = strtok(
NULL,
".");
363 if (path_step < path_len && atoi(ptr) != port_path[path_step])
367 string_length -=
strnlen(ptr, string_length) + 1;
371 if (path_step == path_len && !string_length)
388 Jim_WrongNumArgs(goi.
interp, 1, goi.
argv-1,
"(no params)");
408 for (
unsigned i = 0; transports[i]; i++)
435 LOG_WARNING(
"Interface already configured, ignoring");
461 LOG_ERROR(
"The specified debug interface was not found (%s)",
485 if (strcmp(*
CMD_ARGV,
"srst_gates_jtag") == 0)
487 else if (strcmp(*
CMD_ARGV,
"srst_nogate") == 0)
492 LOG_ERROR(
"extra reset_config %s spec (%s)",
503 else if (strcmp(*
CMD_ARGV,
"trst_only") == 0)
505 else if (strcmp(*
CMD_ARGV,
"srst_only") == 0)
507 else if (strcmp(*
CMD_ARGV,
"trst_and_srst") == 0)
512 LOG_ERROR(
"extra reset_config %s spec (%s)",
521 if (strcmp(*
CMD_ARGV,
"separate") == 0)
523 else if (strcmp(*
CMD_ARGV,
"srst_pulls_trst") == 0)
525 else if (strcmp(*
CMD_ARGV,
"trst_pulls_srst") == 0)
527 else if (strcmp(*
CMD_ARGV,
"combined") == 0)
532 LOG_ERROR(
"extra reset_config %s spec (%s)",
541 if (strcmp(*
CMD_ARGV,
"trst_open_drain") == 0)
543 else if (strcmp(*
CMD_ARGV,
"trst_push_pull") == 0)
548 LOG_ERROR(
"extra reset_config %s spec (%s)",
557 if (strcmp(*
CMD_ARGV,
"srst_push_pull") == 0)
559 else if (strcmp(*
CMD_ARGV,
"srst_open_drain") == 0)
564 LOG_ERROR(
"extra reset_config %s spec (%s)",
573 if (strcmp(*
CMD_ARGV,
"connect_assert_srst") == 0)
575 else if (strcmp(*
CMD_ARGV,
"connect_deassert_srst") == 0)
580 LOG_ERROR(
"extra reset_config %s spec (%s)",
619 modes[0] =
"srst_only";
622 modes[0] =
"trst_only";
625 modes[0] =
"trst_and_srst";
635 modes[1] =
"srst_pulls_trst";
638 modes[1] =
"trst_pulls_srst";
641 modes[1] =
"combined";
644 modes[1] =
"separate";
651 modes[3] =
" trst_open_drain";
653 modes[3] =
" trst_push_pull";
660 modes[2] =
" srst_nogate";
662 modes[2] =
" srst_gates_jtag";
665 modes[4] =
" srst_push_pull";
667 modes[4] =
" srst_open_drain";
670 modes[5] =
" connect_assert_srst";
672 modes[5] =
" connect_deassert_srst";
681 modes[2], modes[3], modes[4], modes[5]);
755 VALUE_UNDEFINED = -1,
760 enum values srst = VALUE_UNDEFINED;
761 enum values trst = VALUE_UNDEFINED;
786 value = (strcmp(
CMD_NAME,
"assert") == 0) ? VALUE_ASSERT : VALUE_DEASSERT;
787 if (strcmp(
CMD_ARGV[0],
"srst") == 0)
789 else if (strcmp(
CMD_ARGV[0],
"trst") == 0)
795 if (strcmp(
CMD_ARGV[1],
"assert") == 0)
796 value = VALUE_ASSERT;
797 else if (strcmp(
CMD_ARGV[1],
"deassert") == 0)
798 value = VALUE_DEASSERT;
802 if (strcmp(
CMD_ARGV[2],
"srst") == 0 && srst == VALUE_UNDEFINED)
804 else if (strcmp(
CMD_ARGV[2],
"trst") == 0 && trst == VALUE_UNDEFINED)
810 if (trst == VALUE_UNDEFINED) {
814 trst = VALUE_DEASSERT;
817 if (srst == VALUE_UNDEFINED) {
821 srst = VALUE_DEASSERT;
825 LOG_ERROR(
"transport has no trst signal");
850 const char *active_state = gpio_config->
active_low ?
"low" :
"high";
851 const char *dir =
"";
852 const char *
drive =
"";
853 const char *
pull =
"";
864 dir =
"bidirectional";
868 if (
gpio_map[gpio_idx].permit_drive_option) {
869 switch (gpio_config->
drive) {
871 drive =
", push-pull";
874 drive =
", open-drain";
877 drive =
", open-source";
882 switch (gpio_config->
pull) {
884 pull =
", pull-none";
890 pull =
", pull-down";
894 if (
gpio_map[gpio_idx].permit_init_state_option) {
908 command_print(
CMD,
"adapter gpio %s (%s): num %d, chip %d, active-%s%s%s%s",
935 if (gpio_idx == -1) {
957 if (strcmp(
CMD_ARGV[i],
"-chip") == 0) {
959 LOG_ERROR(
"-chip option requires a parameter");
970 if (strcmp(
CMD_ARGV[i],
"-active-high") == 0) {
975 if (strcmp(
CMD_ARGV[i],
"-active-low") == 0) {
981 if (
gpio_map[gpio_idx].permit_drive_option) {
982 if (strcmp(
CMD_ARGV[i],
"-push-pull") == 0) {
987 if (strcmp(
CMD_ARGV[i],
"-open-drain") == 0) {
992 if (strcmp(
CMD_ARGV[i],
"-open-source") == 0) {
999 if (strcmp(
CMD_ARGV[i],
"-pull-none") == 0) {
1004 if (strcmp(
CMD_ARGV[i],
"-pull-up") == 0) {
1009 if (strcmp(
CMD_ARGV[i],
"-pull-down") == 0) {
1015 if (
gpio_map[gpio_idx].permit_init_state_option) {
1016 if (strcmp(
CMD_ARGV[i],
"-init-inactive") == 0) {
1021 if (strcmp(
CMD_ARGV[i],
"-init-active") == 0) {
1028 strcmp(
CMD_ARGV[i],
"-init-input") == 0) {
1035 LOG_ERROR(
"illegal option for adapter %s %s: %s",
1050 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1054 adapter_usb_set_location(
CMD_ARGV[0]);
1063 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1066 .handler = &handle_usb_location_command,
1068 .help =
"display or set the USB bus location of the USB device",
1069 .usage =
"[<bus>-port[.port]...]",
1078 .handler = handle_adapter_srst_delay_command,
1080 .help =
"delay after deasserting SRST in ms",
1081 .usage =
"[milliseconds]",
1084 .name =
"pulse_width",
1085 .handler = handle_adapter_srst_pulse_width_command,
1087 .help =
"SRST assertion pulse width in ms",
1088 .usage =
"[milliseconds]",
1096 .handler = handle_adapter_driver_command,
1098 .help =
"Select a debug adapter driver",
1099 .usage =
"driver_name",
1103 .handler = handle_adapter_speed_command,
1105 .help =
"With an argument, change to the specified maximum "
1106 "jtag speed. For JTAG, 0 KHz signifies adaptive "
1108 "With or without argument, display current setting.",
1113 .handler = handle_adapter_serial_command,
1115 .help =
"Set the serial number of the adapter",
1116 .usage =
"serial_string",
1120 .handler = handle_adapter_list_command,
1122 .help =
"List all built-in debug adapter drivers",
1129 .help =
"Returns the name of the currently "
1130 "selected adapter (driver)",
1135 .help =
"srst adapter command group",
1140 .
name =
"transports",
1141 .handler = adapter_transports_command,
1143 .help =
"Declare transports the adapter supports.",
1144 .usage =
"transport ...",
1149 .help =
"usb adapter command group",
1155 .handler = handle_adapter_reset_de_assert,
1157 .help =
"Controls SRST and TRST lines.",
1158 .usage =
"|deassert [srst|trst [assert|deassert srst|trst]]",
1162 .handler = handle_adapter_reset_de_assert,
1164 .help =
"Controls SRST and TRST lines.",
1165 .usage =
"|assert [srst|trst [deassert|assert srst|trst]]",
1169 .handler = adapter_gpio_config_handler,
1171 .help =
"gpio adapter command group",
1172 .usage =
"[ tdo|tdi|tms|tck|trst|swdio|swdio_dir|swclk|srst|led"
1174 "[-chip chip_number] "
1175 "[-active-high|-active-low] "
1176 "[-push-pull|-open-drain|-open-source] "
1177 "[-pull-none|-pull-up|-pull-down]"
1178 "[-init-inactive|-init-active|-init-input] ]",
1187 .help =
"adapter command group",
1192 .
name =
"reset_config",
1193 .handler = handle_reset_config_command,
1195 .help =
"configure adapter reset behavior",
1196 .usage =
"[none|trst_only|srst_only|trst_and_srst] "
1197 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
1198 "[srst_gates_jtag|srst_nogate] "
1199 "[trst_push_pull|trst_open_drain] "
1200 "[srst_push_pull|srst_open_drain] "
1201 "[connect_deassert_srst|connect_assert_srst]",
static const struct command_registration adapter_srst_command_handlers[]
static int adapter_rclk_to_speed(unsigned int fallback_speed_khz, int *speed)
int adapter_config_rclk(unsigned int fallback_speed_khz)
Attempt to enable RTCK/RCLK.
COMMAND_HANDLER(adapter_transports_command)
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
static void sync_adapter_reset_with_gpios(void)
const char *const jtag_only[]
static int get_gpio_index(const char *signal_name)
enum adapter_clk_mode clock_mode
int rclk_fallback_speed_khz
static int adapter_set_speed(int speed)
int adapter_get_speed(int *speed)
bool is_adapter_initialized(void)
int adapter_quit(void)
Shutdown the debug adapter upon program exit.
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
static struct @13 adapter_config
Adapter configuration.
static int adapter_khz_to_speed(unsigned int khz, int *speed)
static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
int adapter_get_speed_readable(int *khz)
Given a speed setting, use the interface speed_div callback to adjust the setting.
static const struct command_registration adapter_usb_command_handlers[]
#define DEFAULT_CLOCK_SPEED_KHZ
struct adapter_gpio_config gpios[ADAPTER_GPIO_IDX_NUM]
const char * adapter_usb_get_location(void)
int adapter_register_commands(struct command_context *ctx)
Register the commands which deal with arbitrary debug adapter drivers.
int adapter_init(struct command_context *cmd_ctx)
Do low-level setup like initializing registers, output signals, and clocking.
static const struct command_registration adapter_command_handlers[]
int adapter_config_khz(unsigned int khz)
Attempt to configure the adapter for the specified kHz.
struct adapter_driver * adapter_driver
#define USB_MAX_LOCATION_LENGTH
static void adapter_driver_gpios_init(void)
static const struct command_registration interface_command_handlers[]
static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
@ ADAPTER_GPIO_INIT_STATE_ACTIVE
@ ADAPTER_GPIO_INIT_STATE_INPUT
@ ADAPTER_GPIO_INIT_STATE_INACTIVE
adapter_gpio_config_index
Adapter GPIO.
@ ADAPTER_GPIO_IDX_SWDIO_DIR
adapter_gpio_direction
Supported GPIO directions.
@ ADAPTER_GPIO_DIRECTION_OUTPUT
@ ADAPTER_GPIO_DIRECTION_INPUT
@ ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_SOURCE
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_DRAIN
@ ADAPTER_GPIO_DRIVE_MODE_PUSH_PULL
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 CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#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 CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
static uint16_t direction
struct adapter_driver * adapter_drivers[]
The list of built-in JTAG interfaces, containing entries for those drivers that were enabled by the c...
Exports the list of JTAG interface drivers, along with routines for loading and unloading them dynami...
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
int adapter_resets(int trst, int srst)
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
struct jtag_tap * jtag_all_taps(void)
void jtag_set_nsrst_assert_width(unsigned delay)
unsigned jtag_get_nsrst_delay(void)
void jtag_set_nsrst_delay(unsigned delay)
static enum reset_types jtag_reset_config
void jtag_tap_free(struct jtag_tap *tap)
unsigned jtag_get_nsrst_assert_width(void)
void jtag_set_reset_config(enum reset_types type)
enum reset_types jtag_get_reset_config(void)
The JTAG interface can be implemented with a software or hardware fifo.
#define ERROR_JTAG_INIT_FAILED
#define ERROR_JTAG_INVALID_INTERFACE
#define SRST_DEASSERT
Defines arguments for reset functions.
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
char * strndup(const char *s, size_t n)
size_t strnlen(const char *s, size_t maxlen)
Represents a driver for a debugging interface.
int(* speed)(int speed)
Set the interface speed.
int(* khz)(int khz, int *jtag_speed)
Returns JTAG maximum speed for KHz.
int(* speed_div)(int speed, int *khz)
Calculate the clock frequency (in KHz) for the given speed.
int(* init)(void)
Interface driver must initialize any resources and connect to a JTAG device.
const char *const * transports
transports supported in C code (NULL terminated vector)
const char *const name
The name of the interface driver.
int(* quit)(void)
Interface driver must tear down all resources and disconnect from the JTAG device.
Configuration options for a single GPIO.
enum adapter_gpio_pull pull
enum adapter_gpio_init_state init_state
enum adapter_gpio_drive_mode drive
enum adapter_gpio_direction direction
bool permit_init_state_option
A TCL -ish GetOpt like code.
struct jtag_tap * next_tap
int allow_transports(struct command_context *ctx, const char *const *vector)
Called by debug adapter drivers, or affiliated Tcl config scripts, to declare the set of transports s...