stlink: fix handling of DPv1 and DPv2 banked registers
[openocd.git] / src / jtag / drivers / stlink_usb.c
index e121eb42b3075fbdb8e8bf7d62cf9a29d64a2d8d..5c904d4ffb6a94b9aabf73b5a76d2b9b7a7db67a 100644 (file)
@@ -316,6 +316,7 @@ enum stlink_mode {
 #define STLINK_F_HAS_DAP_REG            BIT(5)
 #define STLINK_F_QUIRK_JTAG_DP_READ     BIT(6)
 #define STLINK_F_HAS_AP_INIT            BIT(7)
+#define STLINK_F_HAS_DPBANKSEL          BIT(8)
 
 /* aliases */
 #define STLINK_F_HAS_TARGET_VOLT        STLINK_F_HAS_TRACE
@@ -1021,6 +1022,10 @@ static int stlink_usb_version(void *handle)
                if (h->version.jtag >= 28)
                        flags |= STLINK_F_HAS_AP_INIT;
 
+               /* Banked regs (DPv1 & DPv2) support from V2J32 */
+               if (h->version.jtag >= 32)
+                       flags |= STLINK_F_HAS_DPBANKSEL;
+
                break;
        case 3:
                /* all STLINK-V3 use api-v3 */
@@ -1044,6 +1049,10 @@ static int stlink_usb_version(void *handle)
                /* API required to init AP before any AP access */
                flags |= STLINK_F_HAS_AP_INIT;
 
+               /* Banked regs (DPv1 & DPv2) support from V3J2 */
+               if (h->version.jtag >= 2)
+                       flags |= STLINK_F_HAS_DPBANKSEL;
+
                break;
        default:
                break;
@@ -3259,6 +3268,12 @@ static int stlink_dap_op_queue_dp_read(struct adiv5_dap *dap, unsigned reg,
        uint32_t dummy;
        int retval;
 
+       if (!(stlink_dap_handle->version.flags & STLINK_F_HAS_DPBANKSEL))
+               if (reg & 0x000000F0) {
+                       LOG_ERROR("Banked DP registers not supported in current STLink FW");
+                       return ERROR_COMMAND_NOTFOUND;
+               }
+
        retval = stlink_dap_check_reconnect(dap);
        if (retval != ERROR_OK)
                return retval;
@@ -3286,6 +3301,18 @@ static int stlink_dap_op_queue_dp_write(struct adiv5_dap *dap, unsigned reg,
 {
        int retval;
 
+       if (!(stlink_dap_handle->version.flags & STLINK_F_HAS_DPBANKSEL))
+               if (reg & 0x000000F0) {
+                       LOG_ERROR("Banked DP registers not supported in current STLink FW");
+                       return ERROR_COMMAND_NOTFOUND;
+               }
+
+       if (reg == DP_SELECT && (data & DP_SELECT_DPBANK) != 0) {
+               /* ignored if STLINK_F_HAS_DPBANKSEL, not properly managed otherwise */
+               LOG_DEBUG("Ignoring DPBANKSEL while write SELECT");
+               data &= ~DP_SELECT_DPBANK;
+       }
+
        retval = stlink_dap_check_reconnect(dap);
        if (retval != ERROR_OK)
                return retval;

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)