drivers/cmsis_dap_usb: restructure init sequence a bit 92/2192/2
authorPaul Fertser <fercerpav@gmail.com>
Wed, 25 Jun 2014 18:50:03 +0000 (22:50 +0400)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Thu, 3 Jul 2014 18:40:59 +0000 (18:40 +0000)
This fixes the issue of improper initialisation sequence and in
particular makes "cmsis_dap_vid_pid" config specification functional.

Not really elegant but it's in line with the ftdi driver and so can be
reworked in a uniform way later when the internal API is changed.

Change-Id: Ief9fc64ad0ac24e1c66727153f383e4f30a830c7
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2192
Reviewed-by: Andrey Yurovsky <yurovsky@gmail.com>
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/jtag/drivers/cmsis_dap_usb.c

index 7d4c579ae08342b433a1a9d97a5f7e5fbe70c65c..4073d215aedd8ffedff5f06cf8d233dc213ee794 100644 (file)
@@ -60,6 +60,7 @@
 /* vid = pid = 0 marks the end of the list */
 static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 };
 static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 };
 /* vid = pid = 0 marks the end of the list */
 static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 };
 static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 };
+static bool swd_mode;
 
 #define PACKET_SIZE       (64 + 1)     /* 64 bytes plus report id */
 #define USB_TIMEOUT       1000
 
 #define PACKET_SIZE       (64 + 1)     /* 64 bytes plus report id */
 #define USB_TIMEOUT       1000
@@ -720,11 +721,50 @@ static int cmsis_dap_reset_link(void)
        return retval;
 }
 
        return retval;
 }
 
+static int cmsis_dap_swd_open(void)
+{
+       int retval;
+
+       DEBUG_IO("CMSIS-DAP: cmsis_dap_swd_open");
+
+       if (cmsis_dap_handle == NULL) {
+
+               /* SWD init */
+               retval = cmsis_dap_usb_open();
+               if (retval != ERROR_OK)
+                       return retval;
+
+               retval = cmsis_dap_get_caps_info();
+               if (retval != ERROR_OK)
+                       return retval;
+       }
+
+       if (!(cmsis_dap_handle->caps & INFO_CAPS_SWD)) {
+               LOG_ERROR("CMSIS-DAP: SWD not supported");
+               return ERROR_JTAG_DEVICE_ERROR;
+       }
+
+       retval = cmsis_dap_cmd_DAP_Connect(CONNECT_SWD);
+       if (retval != ERROR_OK)
+               return retval;
+
+       /* Add more setup here.??... */
+
+       LOG_INFO("CMSIS-DAP: Interface Initialised (SWD)");
+       return ERROR_OK;
+}
+
 static int cmsis_dap_init(void)
 {
        int retval;
        uint8_t *data;
 
 static int cmsis_dap_init(void)
 {
        int retval;
        uint8_t *data;
 
+       if (swd_mode) {
+               retval = cmsis_dap_swd_open();
+               if (retval != ERROR_OK)
+                       return retval;
+       }
+
        if (cmsis_dap_handle == NULL) {
 
                /* JTAG init */
        if (cmsis_dap_handle == NULL) {
 
                /* JTAG init */
@@ -832,34 +872,7 @@ static int cmsis_dap_init(void)
 
 static int cmsis_dap_swd_init(void)
 {
 
 static int cmsis_dap_swd_init(void)
 {
-       int retval;
-
-       DEBUG_IO("CMSIS-DAP: cmsis_dap_swd_init");
-
-       if (cmsis_dap_handle == NULL) {
-
-               /* SWD init */
-               retval = cmsis_dap_usb_open();
-               if (retval != ERROR_OK)
-                       return retval;
-
-               retval = cmsis_dap_get_caps_info();
-               if (retval != ERROR_OK)
-                       return retval;
-       }
-
-       if (!(cmsis_dap_handle->caps & INFO_CAPS_SWD)) {
-               LOG_ERROR("CMSIS-DAP: SWD not supported");
-               return ERROR_JTAG_DEVICE_ERROR;
-       }
-
-       retval = cmsis_dap_cmd_DAP_Connect(CONNECT_SWD);
-       if (retval != ERROR_OK)
-               return retval;
-
-       /* Add more setup here.??... */
-
-       LOG_INFO("CMSIS-DAP: Interface Initialised (SWD)");
+       swd_mode = true;
        return ERROR_OK;
 }
 
        return ERROR_OK;
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)