cfg: ftdi icdi enable srst open drain config
[fw/openocd] / src / jtag / stlink / stlink_interface.c
index a2ac99f74eb33cb10a43301522ef0a08a22ea003..c06d86cfa7a32d681339b35015a08563833ab5b5 100644 (file)
@@ -17,6 +17,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <jtag/stlink/stlink_tcl.h>
 #include <jtag/stlink/stlink_layout.h>
+#include <jtag/stlink/stlink_transport.h>
 #include <jtag/stlink/stlink_interface.h>
 
 #include <target/target.h>
 
-static struct stlink_interface_s stlink_if = { {0, 0, 0, 0}, 0, 0 };
+static struct stlink_interface_s stlink_if = { {0, 0, 0, 0, 0, 0}, 0, 0 };
 
-int stlink_interface_open(void)
+int stlink_interface_open(enum stlink_transports tr)
 {
        LOG_DEBUG("stlink_interface_open");
 
+       /* set transport mode */
+       stlink_if.param.transport = tr;
+
        return stlink_if.layout->open(&stlink_if);
 }
 
@@ -45,6 +50,8 @@ int stlink_interface_init_target(struct target *t)
 {
        int res;
 
+       LOG_DEBUG("stlink_interface_init_target");
+
        /* this is the interface for the current target and we
         * can setup the private pointer in the tap structure
         * if the interface match the tap idcode
@@ -60,16 +67,16 @@ int stlink_interface_init_target(struct target *t)
        for (ii = 0; ii < limit; ii++) {
                uint32_t expected = t->tap->expected_ids[ii];
 
-               if (t->tap->idcode == expected) {
+               /* treat "-expected-id 0" as a "don't-warn" wildcard */
+               if (!expected || (t->tap->idcode == expected)) {
                        found = 1;
                        break;
                }
        }
 
        if (found == 0) {
-               LOG_ERROR
-                   ("stlink_interface_init_target: target not found: idcode: %x ",
-                    t->tap->idcode);
+               LOG_ERROR("stlink_interface_init_target: target not found: idcode: 0x%08x",
+                               t->tap->idcode);
                return ERROR_FAIL;
        }
 
@@ -101,6 +108,18 @@ static int stlink_interface_speed(int speed)
        return ERROR_OK;
 }
 
+static int stlink_speed_div(int speed, int *khz)
+{
+       *khz = speed;
+       return ERROR_OK;
+}
+
+static int stlink_khz(int khz, int *jtag_speed)
+{
+       *jtag_speed = khz;
+       return ERROR_OK;
+}
+
 static int stlink_interface_execute_queue(void)
 {
        LOG_DEBUG("stlink_interface_execute_queue: ignored");
@@ -180,6 +199,21 @@ COMMAND_HANDLER(stlink_interface_handle_vid_pid_command)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(stlink_interface_handle_api_command)
+{
+       if (CMD_ARGC != 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       unsigned new_api;
+       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], new_api);
+       if ((new_api == 0) || (new_api > 2))
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       stlink_if.param.api = new_api;
+
+       return ERROR_OK;
+}
+
 static const struct command_registration stlink_interface_command_handlers[] = {
        {
         .name = "stlink_device_desc",
@@ -209,6 +243,13 @@ static const struct command_registration stlink_interface_command_handlers[] = {
         .help = "the vendor and product ID of the STLINK device",
         .usage = "(vid pid)* ",
         },
+        {
+        .name = "stlink_api",
+        .handler = &stlink_interface_handle_api_command,
+        .mode = COMMAND_CONFIG,
+        .help = "set the desired stlink api level",
+        .usage = "api version 1 or 2",
+        },
        COMMAND_REGISTRATION_DONE
 };
 
@@ -217,9 +258,10 @@ struct jtag_interface stlink_interface = {
        .supported = 0,
        .commands = stlink_interface_command_handlers,
        .transports = stlink_transports,
-
        .init = stlink_interface_init,
        .quit = stlink_interface_quit,
        .speed = stlink_interface_speed,
+       .speed_div = stlink_speed_div,
+       .khz = stlink_khz,
        .execute_queue = stlink_interface_execute_queue,
 };