jtag: drivers: stlink: handle all versions with single config
[openocd.git] / src / jtag / drivers / stlink_usb.c
index 0bdcd316b70df27c2b6b4345e1cdd875e3be659e..64868ea9e3d2eed26775196d85f20f93c730feda 100644 (file)
@@ -1650,13 +1650,11 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
 
        h->transport = param->transport;
 
-       const uint16_t vids[] = { param->vid, 0 };
-       const uint16_t pids[] = { param->pid, 0 };
-       const char *serial = param->serial;
-
-       LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s",
-                       param->transport, param->vid, param->pid,
-                       param->serial ? param->serial : "");
+       for (unsigned i = 0; param->vid[i]; i++) {
+               LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s",
+                         param->transport, param->vid[i], param->pid[i],
+                         param->serial ? param->serial : "");
+       }
 
        /*
          On certain host USB configurations(e.g. MacBook Air)
@@ -1668,7 +1666,7 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
          in order to become operational.
         */
        do {
-               if (jtag_libusb_open(vids, pids, serial, &h->fd) != ERROR_OK) {
+               if (jtag_libusb_open(param->vid, param->pid, param->serial, &h->fd) != ERROR_OK) {
                        LOG_ERROR("open failed");
                        goto error_open;
                }
@@ -1683,8 +1681,14 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
                /* RX EP is common for all versions */
                h->rx_ep = STLINK_RX_EP;
 
+               uint16_t pid;
+               if (jtag_libusb_get_pid(jtag_libusb_get_device(h->fd), &pid) != ERROR_OK) {
+                       LOG_DEBUG("libusb_get_pid failed");
+                       goto error_open;
+               }
+
                /* wrap version for first read */
-               switch (param->pid) {
+               switch (pid) {
                        case STLINK_V1_PID:
                                h->version.stlink = 1;
                                h->tx_ep = STLINK_TX_EP;
@@ -1736,12 +1740,6 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
                }
        } while (1);
 
-       /* compare usb vid/pid */
-       if ((param->vid != h->vid) || (param->pid != h->pid))
-               LOG_INFO("vid/pid are not identical: 0x%04X/0x%04X 0x%04X/0x%04X",
-                       param->vid, param->pid,
-                       h->vid, h->pid);
-
        /* check if mode is supported */
        err = 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)