arm946e: add icache/dcache manipulation commands.
[openocd.git] / src / jtag / drivers / stlink_usb.c
index 68179c39b4e35cbe0254730dcc860551a6e1d21c..b2f380aecb6172189cdad362769c4265e78ad15e 100644 (file)
@@ -2,6 +2,9 @@
  *   Copyright (C) 2011-2012 by Mathias Kuester                            *
  *   Mathias Kuester <kesmtp@freenet.de>                                   *
  *                                                                         *
+ *   Copyright (C) 2012 by Spencer Oliver                                  *
+ *   spen@spen-soft.co.uk                                                  *
+ *                                                                         *
  *   This code is based on https://github.com/texane/stlink                *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -48,7 +51,7 @@
 #define STLINK_CMD_SIZE_V1     (10)
 
 enum stlink_jtag_api_version {
-       STLINK_JTAG_API_V1 = 0,
+       STLINK_JTAG_API_V1 = 1,
        STLINK_JTAG_API_V2,
 };
 
@@ -400,10 +403,9 @@ static int stlink_usb_version(void *handle)
        h->pid = buf_get_u32(h->databuf, 32, 16);
 
        /* set the supported jtag api version
-        * V1 doesn't support API V2 at all
-        * V2 support API V2 since JTAG V13
+        * API V2 is supported since JTAG V11
         */
-       if ((h->version.stlink == 2) && (h->version.jtag > 12))
+       if (h->version.jtag >= 11)
                h->version.jtag_api_max = STLINK_JTAG_API_V2;
        else
                h->version.jtag_api_max = STLINK_JTAG_API_V1;
@@ -719,6 +721,8 @@ static enum target_state stlink_usb_v2_get_status(void *handle)
 
        if (status & S_HALT)
                return TARGET_HALTED;
+       else if (status & S_RESET_ST)
+               return TARGET_RESET;
 
        return TARGET_RUNNING;
 }
@@ -783,6 +787,32 @@ static int stlink_usb_reset(void *handle)
        return h->databuf[0] == STLINK_DEBUG_ERR_OK ? ERROR_OK : ERROR_FAIL;
 }
 
+static int stlink_usb_assert_srst(void *handle, int srst)
+{
+       int res;
+       struct stlink_usb_handle_s *h;
+
+       assert(handle != NULL);
+
+       h = (struct stlink_usb_handle_s *)handle;
+
+       if (h->jtag_api == STLINK_JTAG_API_V1)
+               return ERROR_COMMAND_NOTFOUND;
+
+       stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
+
+       h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
+       h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_DRIVE_NRST;
+       h->cmdbuf[h->cmdidx++] = srst;
+
+       res = stlink_usb_xfer(handle, h->databuf, 2);
+
+       if (res != ERROR_OK)
+               return res;
+
+       return h->databuf[0] == STLINK_DEBUG_ERR_OK ? ERROR_OK : ERROR_FAIL;
+}
+
 /** */
 static int stlink_usb_run(void *handle)
 {
@@ -845,8 +875,13 @@ static int stlink_usb_step(void *handle)
 
        h = (struct stlink_usb_handle_s *)handle;
 
-       if (h->jtag_api == STLINK_JTAG_API_V2)
-               return stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_STEP|C_DEBUGEN);
+       if (h->jtag_api == STLINK_JTAG_API_V2) {
+               /* TODO: this emulates the v1 api, it should really use a similar auto mask isr
+                * that the cortex-m3 currently does. */
+               stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_MASKINTS|C_DEBUGEN);
+               stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_STEP|C_MASKINTS|C_DEBUGEN);
+               return stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
+       }
 
        stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
 
@@ -1105,6 +1140,7 @@ static int stlink_usb_open(struct stlink_interface_param_s *param, void **fd)
 {
        int err;
        struct stlink_usb_handle_s *h;
+       enum stlink_jtag_api_version api;
 
        LOG_DEBUG("stlink_usb_open");
 
@@ -1186,8 +1222,17 @@ static int stlink_usb_open(struct stlink_interface_param_s *param, void **fd)
                return err;
        }
 
-       /* set the used jtag api */
-       h->jtag_api = STLINK_JTAG_API_V1;
+       api = h->version.jtag_api_max;
+
+       /* check that user has not requested certain api version
+        * and if they have check it is supported */
+       if ((param->api != 0) && (param->api <= h->version.jtag_api_max)) {
+               api = param->api;
+               LOG_INFO("using stlink api v%d", api);
+       }
+
+       /* set the used jtag api, this will default to the newest supported version */
+       h->jtag_api = api;
 
        /* initialize the debug hardware */
        err = stlink_usb_init_mode(h);
@@ -1223,6 +1268,8 @@ struct stlink_layout_api_s stlink_usb_layout_api = {
        /** */
        .reset = stlink_usb_reset,
        /** */
+       .assert_srst = stlink_usb_assert_srst,
+       /** */
        .run = stlink_usb_run,
        /** */
        .halt = stlink_usb_halt,
@@ -1242,4 +1289,6 @@ struct stlink_layout_api_s stlink_usb_layout_api = {
        .read_mem32 = stlink_usb_read_mem32,
        /** */
        .write_mem32 = stlink_usb_write_mem32,
+       /** */
+       .write_debug_reg = stlink_usb_write_debug_reg
 };

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)