cmsis-dap: prevent hidapi to search again for the adapter
[openocd.git] / src / jtag / drivers / cmsis_dap_usb.c
index ee1cb533c050a730a880350b53b793be5287e304..89158368043559385211bbc965e2b6c612f5be71 100644 (file)
@@ -229,14 +229,16 @@ static int cmsis_dap_usb_open(void)
        int i;
        struct hid_device_info *devs, *cur_dev;
        unsigned short target_vid, target_pid;
-       wchar_t *target_serial = NULL;
-
        bool found = false;
-       bool serial_found = false;
 
        target_vid = 0;
        target_pid = 0;
 
+       if (hid_init() != 0) {
+               LOG_ERROR("unable to open HIDAPI");
+               return ERROR_FAIL;
+       }
+
        /*
         * The CMSIS-DAP specification stipulates:
         * "The Product String must contain "CMSIS-DAP" somewhere in the string. This is used by the
@@ -273,7 +275,6 @@ static int cmsis_dap_usb_open(void)
                        /* check serial number matches if given */
                        if (cmsis_dap_serial != NULL) {
                                if ((cur_dev->serial_number != NULL) && wcscmp(cmsis_dap_serial, cur_dev->serial_number) == 0) {
-                                       serial_found = true;
                                        break;
                                }
                        } else
@@ -288,23 +289,16 @@ static int cmsis_dap_usb_open(void)
        if (NULL != cur_dev) {
                target_vid = cur_dev->vendor_id;
                target_pid = cur_dev->product_id;
-               if (serial_found)
-                       target_serial = cmsis_dap_serial;
        }
 
-       hid_free_enumeration(devs);
-
        if (target_vid == 0 && target_pid == 0) {
                LOG_ERROR("unable to find CMSIS-DAP device");
+               hid_free_enumeration(devs);
                return ERROR_FAIL;
        }
 
-       if (hid_init() != 0) {
-               LOG_ERROR("unable to open HIDAPI");
-               return ERROR_FAIL;
-       }
-
-       dev = hid_open(target_vid, target_pid, target_serial);
+       dev = hid_open_path(cur_dev->path);
+       hid_free_enumeration(devs);
 
        if (dev == NULL) {
                LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);

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)