35 #define DEFAULT_CLOCK_SPEED_KHZ 100U
37 #define MAX_USB_IDS 16
141 LOG_ERROR(
"Debug Adapter has to be specified, "
142 "see \"adapter driver\" command");
153 LOG_WARNING(
"An adapter speed is not selected in the init scripts."
154 " OpenOCD will try to run the adapter at very low speed (%d kHz).",
156 LOG_WARNING(
"To remove this warnings and achieve reasonable communication speed with the target,"
157 " set \"adapter speed\" or \"jtag_rclk\" in the init scripts.");
174 int actual_khz = requested_khz;
184 LOG_INFO(
"adapter-specific clock speed value %d", speed_var);
185 else if (actual_khz) {
189 LOG_INFO(
"RCLK (adaptive clock speed) not supported - fallback to %d kHz"
192 LOG_INFO(
"clock speed %d kHz", actual_khz);
194 LOG_INFO(
"RCLK (adaptive clock speed)");
228 LOG_DEBUG(
"convert khz to adapter specific speed value");
234 LOG_ERROR(
"Translation from khz to adapter speed not implemented");
248 if ((retval !=
ERROR_OK) && fallback_speed_khz) {
292 LOG_ERROR(
"BUG: unknown adapter clock mode");
307 LOG_ERROR(
"Translation from adapter speed to khz not implemented");
325 #define USB_MAX_LOCATION_LENGTH 16
327 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
328 static void adapter_usb_set_location(
const char *location)
361 size_t path_step, string_length;
372 ptr = strtok(loc,
"-");
378 string_length -=
strnlen(ptr, string_length);
380 if (atoi(ptr) != dev_bus)
384 while (path_step < path_len) {
385 ptr = strtok(
NULL,
".");
392 if (path_step < path_len && atoi(ptr) != port_path[path_step])
396 string_length -=
strnlen(ptr, string_length) + 1;
400 if (path_step == path_len && !string_length)
437 if (j & transport_ids)
459 LOG_WARNING(
"Adapter driver already configured, ignoring");
486 LOG_ERROR(
"The specified adapter driver was not found (%s)",
511 if (strcmp(*
CMD_ARGV,
"srst_gates_jtag") == 0)
513 else if (strcmp(*
CMD_ARGV,
"srst_nogate") == 0)
518 LOG_ERROR(
"extra reset_config %s spec (%s)",
529 else if (strcmp(*
CMD_ARGV,
"trst_only") == 0)
531 else if (strcmp(*
CMD_ARGV,
"srst_only") == 0)
533 else if (strcmp(*
CMD_ARGV,
"trst_and_srst") == 0)
538 LOG_ERROR(
"extra reset_config %s spec (%s)",
547 if (strcmp(*
CMD_ARGV,
"separate") == 0)
549 else if (strcmp(*
CMD_ARGV,
"srst_pulls_trst") == 0)
551 else if (strcmp(*
CMD_ARGV,
"trst_pulls_srst") == 0)
553 else if (strcmp(*
CMD_ARGV,
"combined") == 0)
558 LOG_ERROR(
"extra reset_config %s spec (%s)",
567 if (strcmp(*
CMD_ARGV,
"trst_open_drain") == 0)
569 else if (strcmp(*
CMD_ARGV,
"trst_push_pull") == 0)
574 LOG_ERROR(
"extra reset_config %s spec (%s)",
583 if (strcmp(*
CMD_ARGV,
"srst_push_pull") == 0)
585 else if (strcmp(*
CMD_ARGV,
"srst_open_drain") == 0)
590 LOG_ERROR(
"extra reset_config %s spec (%s)",
599 if (strcmp(*
CMD_ARGV,
"connect_assert_srst") == 0)
601 else if (strcmp(*
CMD_ARGV,
"connect_deassert_srst") == 0)
606 LOG_ERROR(
"extra reset_config %s spec (%s)",
645 modes[0] =
"srst_only";
648 modes[0] =
"trst_only";
651 modes[0] =
"trst_and_srst";
661 modes[1] =
"srst_pulls_trst";
664 modes[1] =
"trst_pulls_srst";
667 modes[1] =
"combined";
670 modes[1] =
"separate";
677 modes[3] =
" trst_open_drain";
679 modes[3] =
" trst_push_pull";
686 modes[2] =
" srst_nogate";
688 modes[2] =
" srst_gates_jtag";
691 modes[4] =
" srst_push_pull";
693 modes[4] =
" srst_open_drain";
696 modes[5] =
" connect_assert_srst";
698 modes[5] =
" connect_deassert_srst";
707 modes[2], modes[3], modes[4], modes[5]);
747 unsigned int khz = 0;
781 VALUE_UNDEFINED = -1,
786 enum values srst = VALUE_UNDEFINED;
787 enum values trst = VALUE_UNDEFINED;
812 value = (strcmp(
CMD_NAME,
"assert") == 0) ? VALUE_ASSERT : VALUE_DEASSERT;
813 if (strcmp(
CMD_ARGV[0],
"srst") == 0)
815 else if (strcmp(
CMD_ARGV[0],
"trst") == 0)
821 if (strcmp(
CMD_ARGV[1],
"assert") == 0)
822 value = VALUE_ASSERT;
823 else if (strcmp(
CMD_ARGV[1],
"deassert") == 0)
824 value = VALUE_DEASSERT;
828 if (strcmp(
CMD_ARGV[2],
"srst") == 0 && srst == VALUE_UNDEFINED)
830 else if (strcmp(
CMD_ARGV[2],
"trst") == 0 && trst == VALUE_UNDEFINED)
836 if (trst == VALUE_UNDEFINED) {
840 trst = VALUE_DEASSERT;
843 if (srst == VALUE_UNDEFINED) {
847 srst = VALUE_DEASSERT;
851 LOG_ERROR(
"transport has no trst signal");
876 const char *active_state = gpio_config->
active_low ?
"low" :
"high";
877 const char *dir =
"";
878 const char *
drive =
"";
879 const char *
pull =
"";
896 dir =
"bidirectional";
900 if (
gpio_map[gpio_idx].permit_drive_option) {
901 switch (gpio_config->
drive) {
903 drive =
", push-pull";
906 drive =
", open-drain";
909 drive =
", open-source";
914 switch (gpio_config->
pull) {
916 pull =
", pull-none";
922 pull =
", pull-down";
926 if (
gpio_map[gpio_idx].permit_init_state_option) {
940 if (
gpio_map[gpio_idx].permit_exit_state_option) {
958 command_print(
CMD,
"adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s%s",
985 if (gpio_idx == -1) {
999 if (isdigit((
unsigned char)*
CMD_ARGV[i])) {
1005 if (strcmp(
CMD_ARGV[i],
"-chip") == 0) {
1007 LOG_ERROR(
"-chip option requires a parameter");
1016 if (strcmp(
CMD_ARGV[i],
"-active-high") == 0) {
1021 if (strcmp(
CMD_ARGV[i],
"-active-low") == 0) {
1027 if (
gpio_map[gpio_idx].permit_drive_option) {
1028 if (strcmp(
CMD_ARGV[i],
"-push-pull") == 0) {
1033 if (strcmp(
CMD_ARGV[i],
"-open-drain") == 0) {
1038 if (strcmp(
CMD_ARGV[i],
"-open-source") == 0) {
1045 if (strcmp(
CMD_ARGV[i],
"-pull-none") == 0) {
1050 if (strcmp(
CMD_ARGV[i],
"-pull-up") == 0) {
1055 if (strcmp(
CMD_ARGV[i],
"-pull-down") == 0) {
1061 if (
gpio_map[gpio_idx].permit_init_state_option) {
1062 if (strcmp(
CMD_ARGV[i],
"-init-inactive") == 0) {
1067 if (strcmp(
CMD_ARGV[i],
"-init-active") == 0) {
1074 strcmp(
CMD_ARGV[i],
"-init-input") == 0) {
1081 if (
gpio_map[gpio_idx].permit_exit_state_option) {
1082 if (strcmp(
CMD_ARGV[i],
"-exit-no-change") == 0) {
1087 if (strcmp(
CMD_ARGV[i],
"-exit-inactive") == 0) {
1092 if (strcmp(
CMD_ARGV[i],
"-exit-active") == 0) {
1099 strcmp(
CMD_ARGV[i],
"-exit-input") == 0) {
1121 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1125 adapter_usb_set_location(
CMD_ARGV[0]);
1142 LOG_WARNING(
"incomplete vid_pid configuration directive");
1147 for (i = 0; i <
CMD_ARGC; i += 2) {
1176 .handler = &handle_usb_vid_pid_command,
1178 .help =
"set the USB VID and PID of the USB device",
1179 .usage =
"(vid pid)*",
1182 .name =
"product_name",
1183 .handler = &handle_usb_product_name_command,
1185 .help =
"set the USB product name of the USB device",
1188 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
1191 .handler = &handle_usb_location_command,
1193 .help =
"display or set the USB bus location of the USB device",
1194 .usage =
"[<bus>-port[.port]...]",
1203 .handler = handle_adapter_srst_delay_command,
1205 .help =
"delay after deasserting SRST in ms",
1206 .usage =
"[milliseconds]",
1209 .name =
"pulse_width",
1210 .handler = handle_adapter_srst_pulse_width_command,
1212 .help =
"SRST assertion pulse width in ms",
1213 .usage =
"[milliseconds]",
1221 .handler = handle_adapter_driver_command,
1223 .help =
"Select a debug adapter driver",
1224 .usage =
"driver_name",
1228 .handler = handle_adapter_speed_command,
1230 .help =
"With an argument, change to the specified maximum "
1231 "jtag speed. For JTAG, 0 KHz signifies adaptive "
1233 "With or without argument, display current setting.",
1238 .handler = handle_adapter_serial_command,
1240 .help =
"Set the serial number of the adapter",
1241 .usage =
"serial_string",
1245 .handler = handle_adapter_list_command,
1247 .help =
"List all built-in debug adapter drivers",
1253 .handler = handle_adapter_name,
1254 .help =
"Returns the name of the currently "
1255 "selected adapter (driver)",
1261 .help =
"srst adapter command group",
1268 .help =
"usb adapter command group",
1274 .handler = handle_adapter_reset_de_assert,
1276 .help =
"Controls SRST and TRST lines.",
1277 .usage =
"|deassert [srst|trst [assert|deassert srst|trst]]",
1281 .handler = handle_adapter_reset_de_assert,
1283 .help =
"Controls SRST and TRST lines.",
1284 .usage =
"|assert [srst|trst [deassert|assert srst|trst]]",
1288 .handler = adapter_gpio_config_handler,
1290 .help =
"gpio adapter command group",
1291 .usage =
"[ tdo|tdi|tms|tck|trst|swdio|swdio_dir|swclk|srst|led"
1293 "[-chip chip_number] "
1294 "[-active-high|-active-low] "
1295 "[-push-pull|-open-drain|-open-source] "
1296 "[-pull-none|-pull-up|-pull-down]"
1297 "[-init-inactive|-init-active|-init-input] ]"
1298 "[-exit-no-change|-exit-inactive|-exit-active|-exit-input] ]",
1307 .help =
"adapter command group",
1312 .
name =
"reset_config",
1313 .handler = handle_reset_config_command,
1315 .help =
"configure adapter reset behavior",
1316 .usage =
"[none|trst_only|srst_only|trst_and_srst] "
1317 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
1318 "[srst_gates_jtag|srst_nogate] "
1319 "[trst_push_pull|trst_open_drain] "
1320 "[srst_push_pull|srst_open_drain] "
1321 "[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.
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>".
const uint16_t * adapter_usb_get_pids(void)
static void sync_adapter_reset_with_gpios(void)
uint16_t usb_pids[MAX_USB_IDS+1]
static int get_gpio_index(const char *signal_name)
enum adapter_clk_mode clock_mode
COMMAND_HANDLER(handle_adapter_name)
int rclk_fallback_speed_khz
static int adapter_set_speed(int speed)
int adapter_get_speed(int *speed)
bool is_adapter_initialized(void)
uint16_t usb_vids[MAX_USB_IDS+1]
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.
const char * adapter_usb_get_product_name(void)
static int adapter_khz_to_speed(unsigned int khz, int *speed)
const uint16_t * adapter_usb_get_vids(void)
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[]
static 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 struct @17 adapter_config
Adapter configuration.
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_EXIT_STATE_NO_CHANGE
@ ADAPTER_GPIO_EXIT_STATE_INPUT
@ ADAPTER_GPIO_EXIT_STATE_ACTIVE
@ ADAPTER_GPIO_EXIT_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
#define ADAPTER_GPIO_NOT_SET
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
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.
#define ERROR_COMMAND_ARGUMENT_INVALID
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 adapter_resets(int trst, int srst)
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
unsigned int jtag_get_nsrst_delay(void)
struct jtag_tap * jtag_all_taps(void)
unsigned int jtag_get_nsrst_assert_width(void)
void jtag_set_nsrst_assert_width(unsigned int delay)
static enum reset_types jtag_reset_config
void jtag_tap_free(struct jtag_tap *tap)
void jtag_set_nsrst_delay(unsigned int delay)
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.
unsigned int transport_preferred_id
ID of transport that gets auto-selected when not specified by the user.
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.
unsigned int transport_ids
Bitmask of transport IDs supported in C code.
int(* init)(void)
Interface driver must initialize any resources and connect to a JTAG device.
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_exit_state exit_state
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
bool permit_exit_state_option
struct jtag_tap * next_tap
int allow_transports(struct command_context *ctx, unsigned int transport_ids, unsigned int transport_preferred_id)
Called by debug adapter drivers, or affiliated Tcl config scripts, to declare the set of transports s...
const char * transport_name(unsigned int id)
#define TRANSPORT_VALID_MASK