stlink: simplify maintenance of version and features
[openocd.git] / src / jtag / drivers / stlink_usb.c
index 0eed68460f4db3c2561d9ca600a93a3a1223e110..9d6e222017f7ccd7038142a9ecac6d8240fa5426 100644 (file)
@@ -89,6 +89,8 @@ struct stlink_usb_version {
        int swim;
        /** highest supported jtag api version */
        enum stlink_jtag_api_version jtag_api_max;
+       /** one bit for each feature supported. See macros STLINK_F_* */
+       uint32_t flags;
 };
 
 /** */
@@ -272,6 +274,13 @@ enum stlink_mode {
 #define REQUEST_SENSE        0x03
 #define REQUEST_SENSE_LENGTH 18
 
+/*
+ * Map the relevant features, quirks and workaround for specific firmware
+ * version of stlink
+ */
+
+/* aliases */
+
 struct speed_map {
        int speed;
        int speed_divisor;
@@ -622,6 +631,7 @@ static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t siz
 static int stlink_usb_version(void *handle)
 {
        int res;
+       uint32_t flags;
        uint16_t v;
        struct stlink_usb_handle_s *h = handle;
 
@@ -644,13 +654,25 @@ static int stlink_usb_version(void *handle)
        h->vid = buf_get_u32(h->databuf, 16, 16);
        h->pid = buf_get_u32(h->databuf, 32, 16);
 
-       /* set the supported jtag api version
-        * API V2 is supported since JTAG V11
-        */
-       if (h->version.jtag >= 11)
+       flags = 0;
+       switch (h->version.stlink) {
+       case 1:
+               /* ST-LINK/V1 from J11 switch to api-v2 (and support SWD) */
+               if (h->version.jtag >= 11)
+                       h->version.jtag_api_max = STLINK_JTAG_API_V2;
+               else
+                       h->version.jtag_api_max = STLINK_JTAG_API_V1;
+
+               break;
+       case 2:
+               /* all ST-LINK/V2 and ST-Link/V2.1 use api-v2 */
                h->version.jtag_api_max = STLINK_JTAG_API_V2;
-       else
-               h->version.jtag_api_max = STLINK_JTAG_API_V1;
+
+               break;
+       default:
+               break;
+       }
+       h->version.flags = flags;
 
        LOG_INFO("STLINK v%d JTAG v%d API v%d SWIM v%d VID 0x%04X PID 0x%04X",
                h->version.stlink,
@@ -2316,6 +2338,9 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
 
        switch (h->transport) {
                case HL_TRANSPORT_SWD:
+                       if (h->version.jtag_api_max == STLINK_JTAG_API_V1)
+                               err = ERROR_FAIL;
+                       /* fall-through */
                case HL_TRANSPORT_JTAG:
                        if (h->version.jtag == 0)
                                err = ERROR_FAIL;

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)