stlink: fix open AP for v2j37 and v3j7 91/5691/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Thu, 21 May 2020 11:24:32 +0000 (13:24 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 24 May 2020 20:36:02 +0000 (21:36 +0100)
The new stlink firmware requires opening the AP before issuing
any operation.
In the current code we have a 'questionable' check about the core
model to set the TAR autoincrement, that is issued without opening
the AP, thus causing a STLINK_BAD_AP_ERROR.

Modify the AP open API to handle this case and open AP#0 before
the memory access to check the core model.

Change-Id: I576955b5094bd41d63ff1fbad7b4fd9433253321
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-on: http://openocd.zylin.com/5691
Tested-by: jenkins
Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
src/jtag/drivers/stlink_usb.c

index 116d71c6cc57579a5133baa218c0abb31244cbcb..3fdb126cf38e53b41676342d7465a2f2b6f26033 100644 (file)
@@ -361,6 +361,7 @@ static int stlink_swim_status(void *handle);
 void stlink_dump_speed_map(const struct speed_map *map, unsigned int map_size);
 static int stlink_get_com_freq(void *handle, bool is_jtag, struct speed_map *map);
 static int stlink_speed(void *handle, int khz, bool query);
+static int stlink_usb_open_ap(void *handle, unsigned short apsel);
 
 /** */
 static unsigned int stlink_usb_block(void *handle)
@@ -2972,6 +2973,7 @@ static int stlink_usb_open(struct hl_interface_param_s *param, enum stlink_mode
        h->max_mem_packet = (1 << 10);
 
        uint8_t buffer[4];
+       stlink_usb_open_ap(h, 0);
        err = stlink_usb_read_mem32(h, CPUID, 4, buffer);
        if (err == ERROR_OK) {
                uint32_t cpuid = le_to_h_u32(buffer);
@@ -3204,13 +3206,13 @@ static int stlink_dap_get_and_clear_error(void)
        return retval;
 }
 
-/** */
-static int stlink_dap_open_ap(unsigned short apsel)
+static int stlink_usb_open_ap(void *handle, unsigned short apsel)
 {
+       struct stlink_usb_handle_s *h = handle;
        int retval;
 
        /* nothing to do on old versions */
-       if (!(stlink_dap_handle->version.flags & STLINK_F_HAS_AP_INIT))
+       if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
                return ERROR_OK;
 
        if (apsel > DP_APSEL_MAX)
@@ -3219,7 +3221,7 @@ static int stlink_dap_open_ap(unsigned short apsel)
        if (test_bit(apsel, opened_ap))
                return ERROR_OK;
 
-       retval = stlink_usb_init_access_port(stlink_dap_handle, apsel);
+       retval = stlink_usb_init_access_port(h, apsel);
        if (retval != ERROR_OK)
                return retval;
 
@@ -3228,6 +3230,11 @@ static int stlink_dap_open_ap(unsigned short apsel)
        return ERROR_OK;
 }
 
+static int stlink_dap_open_ap(unsigned short apsel)
+{
+       return stlink_usb_open_ap(stlink_dap_handle, apsel);
+}
+
 /** */
 static int stlink_dap_closeall_ap(void)
 {

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)