Zach Welch <zw@superlucidity.net> use memcpy
[openocd.git] / src / jtag / jlink.c
index 022afe5fd4ee37d6f51d7fd5aea2c92d08cf71ec..8626b18cda31099f8e6db78a3faa0cc6bb1f151b 100644 (file)
@@ -42,8 +42,9 @@
 
 #define JLINK_USB_TIMEOUT              1000
 
-#define JLINK_IN_BUFFER_SIZE                   8192
-#define JLINK_OUT_BUFFER_SIZE                  8192
+// See Section 1.3.2 of the Segger JLink USB protocol manual
+#define JLINK_IN_BUFFER_SIZE                   2048
+#define JLINK_OUT_BUFFER_SIZE                  2048
 #define JLINK_EMU_RESULT_BUFFER_SIZE   64
 
 /* Global USB buffers */
@@ -328,6 +329,7 @@ static int jlink_init(void)
 
        jlink_reset(0, 0);
        jlink_tap_init();
+       jlink_speed(jtag_speed);
 
        return ERROR_OK;
 }
@@ -462,6 +464,8 @@ static void jlink_reset(int trst, int srst)
        if (srst == 0)
        {
                jlink_simple_command(EMU_CMD_HW_RESET1);
+               jlink_end_state(TAP_RESET);
+               jlink_state_move();
        }
        else if (srst == 1)
        {
@@ -471,6 +475,8 @@ static void jlink_reset(int trst, int srst)
        if (trst == 0)
        {
                jlink_simple_command(EMU_CMD_HW_TRST1);
+               jlink_end_state(TAP_RESET);
+               jlink_state_move();
        }
        else if (trst == 1)
        {
@@ -617,6 +623,10 @@ static void jlink_tap_append_step(int tms, int tdi)
        int bit_index = tap_length % 8;
        u8 bit = 1 << bit_index;
 
+       // we do not pad TMS, so be sure to initialize all bits
+       if (0 == bit_index)
+               tms_buffer[index] = tdi_buffer[index] = 0;
+
        if (tms)
                tms_buffer[index] |= bit;
        else
@@ -655,43 +665,23 @@ static void jlink_tap_append_scan(int length, u8 *buffer, scan_command_t *comman
 static int jlink_tap_execute(void)
 {
        int byte_length;
-       int tms_offset;
-       int tdi_offset;
        int i;
        int result;
 
        if (!tap_length)
                return ERROR_OK;
 
-       /* Pad last byte so that tap_length is divisible by 8 */
-       while (tap_length % 8 != 0)
-       {
-               /* More of the last TMS value keeps us in the same state,
-                * analogous to free-running JTAG interfaces. */
-               jlink_tap_append_step(last_tms, 0);
-       }
-
-       byte_length = tap_length / 8;
+       // number of full bytes (plus one if some would be left over)
+       byte_length = tap_length / 8 + !!(tap_length % 8);
 
        usb_out_buffer[0] = EMU_CMD_HW_JTAG3;
        usb_out_buffer[1] = 0;
        usb_out_buffer[2] = (tap_length >> 0) & 0xff;
        usb_out_buffer[3] = (tap_length >> 8) & 0xff;
-
-       tms_offset = 4;
-       for (i = 0; i < byte_length; i++)
-       {
-               usb_out_buffer[tms_offset + i] = tms_buffer[i];
-       }
-
-       tdi_offset = tms_offset + byte_length;
-       for (i = 0; i < byte_length; i++)
-       {
-               usb_out_buffer[tdi_offset + i] = tdi_buffer[i];
-       }
+       memcpy(usb_out_buffer + 4, tms_buffer, byte_length);
+       memcpy(usb_out_buffer + 4 + byte_length, tdi_buffer, byte_length);
 
        result = jlink_usb_message(jlink_jtag_handle, 4 + 2 * byte_length, byte_length);
-
        if (result != byte_length)
        {
                LOG_ERROR("jlink_tap_execute, wrong result %d (expected %d)",
@@ -699,8 +689,7 @@ static int jlink_tap_execute(void)
                return ERROR_JTAG_QUEUE_FAILED;
        }
 
-       for (i = 0; i < byte_length; i++)
-               tdo_buffer[i] = usb_in_buffer[i];
+       memcpy(tdo_buffer, usb_in_buffer, byte_length);
 
        for (i = 0; i < pending_scan_results_length; i++)
        {

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)