- added str912/str710_program.script
[openocd.git] / src / jtag / ft2232.c
index 629bab08495e4b3311629efa5cdb822029ec1849..1ac61abb705b0890f7c8ec36786abf3d83c764d3 100644 (file)
@@ -100,6 +100,7 @@ int olimex_jtag_init(void);
 int flyswatter_init(void);
 int turtle_init(void);
 int comstick_init(void);
+int stm32stick_init(void);
 
 /* reset procedures for supported layouts */
 void usbjtag_reset(int trst, int srst);
@@ -108,6 +109,7 @@ void olimex_jtag_reset(int trst, int srst);
 void flyswatter_reset(int trst, int srst);
 void turtle_reset(int trst, int srst);
 void comstick_reset(int trst, int srst);
+void stm32stick_reset(int trst, int srst);
 
 /* blink procedures for layouts that support a blinking led */
 void olimex_jtag_blink(void);
@@ -125,6 +127,7 @@ ft2232_layout_t ft2232_layouts[] =
        {"flyswatter", flyswatter_init, flyswatter_reset, NULL},
        {"turtelizer2", turtle_init, turtle_reset, turtle_jtag_blink},
        {"comstick", comstick_init, comstick_reset, NULL},
+       {"stm32stick", stm32stick_init, stm32stick_reset, NULL},
        {NULL, NULL, NULL},
 };
 
@@ -157,8 +160,6 @@ jtag_interface_t ft2232_interface =
        
        .execute_queue = ft2232_execute_queue,
        
-       .support_pathmove = 1,
-       
        .speed = ft2232_speed,
        .register_commands = ft2232_register_commands,
        .init = ft2232_init,
@@ -249,7 +250,7 @@ int ft2232_speed(int speed)
        u32 bytes_written;
 
        buf[0] = 0x86; /* command "set divisor" */
-       buf[1] = speed & 0xff; /* valueL (0=6MHz, 1=3MHz, 2=1.5MHz, ...*/
+       buf[1] = speed & 0xff; /* valueL (0=6MHz, 1=3MHz, 2=2.0MHz, ...*/
        buf[2] = (speed >> 8) & 0xff; /* valueH */
        
        DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
@@ -458,12 +459,14 @@ void ft2232_add_pathmove(pathmove_command_t *cmd)
                tms_byte = 0x0;
                int bit_count = 0;
                
+               int num_states_batch = num_states > 7 ? 7 : num_states;
+
                /* command "Clock Data to TMS/CS Pin (no Read)" */
                BUFFER_ADD = 0x4b;
                /* number of states remaining */
-               BUFFER_ADD = (num_states % 7) - 1;
+               BUFFER_ADD = num_states_batch - 1;
                
-               while (num_states % 7)
+               while (num_states_batch--)
                {
                        if (tap_transitions[cur_state].low == cmd->path[state_count])
                                buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
@@ -510,7 +513,7 @@ void ft2232_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size
                        BUFFER_ADD = TAP_MOVE(cur_state, TAP_SD);
                        cur_state = TAP_SD;
                }
-               //DEBUG("added TMS scan (no read)");
+               /* DEBUG("added TMS scan (no read)"); */
        }
        
        /* add command for complete bytes */
@@ -521,19 +524,19 @@ void ft2232_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size
                {
                        /* Clock Data Bytes In and Out LSB First */
                        BUFFER_ADD = 0x39;
-                       //DEBUG("added TDI bytes (io %i)", num_bytes);
+                       /* DEBUG("added TDI bytes (io %i)", num_bytes); */
                }
                else if (type == SCAN_OUT)
                {
                        /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
                        BUFFER_ADD = 0x19;
-                       //DEBUG("added TDI bytes (o)");
+                       /* DEBUG("added TDI bytes (o)"); */
                }
                else if (type == SCAN_IN)
                {
                        /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
                        BUFFER_ADD = 0x28;
-                       //DEBUG("added TDI bytes (i %i)", num_bytes);
+                       /* DEBUG("added TDI bytes (i %i)", num_bytes); */
                }
                thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
                num_bytes -= thisrun_bytes;
@@ -568,19 +571,19 @@ void ft2232_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size
                {
                        /* Clock Data Bits In and Out LSB First */
                        BUFFER_ADD = 0x3b;
-                       //DEBUG("added TDI bits (io) %i", bits_left - 1);
+                       /* DEBUG("added TDI bits (io) %i", bits_left - 1); */
                }
                else if (type == SCAN_OUT)
                {
                        /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
                        BUFFER_ADD = 0x1b;
-                       //DEBUG("added TDI bits (o)");
+                       /* DEBUG("added TDI bits (o)"); */
                }
                else if (type == SCAN_IN)
                {
                        /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
                        BUFFER_ADD = 0x2a;
-                       //DEBUG("added TDI bits (i %i)", bits_left - 1);
+                       /* DEBUG("added TDI bits (i %i)", bits_left - 1); */
                }
                BUFFER_ADD = bits_left - 2;
                if (type != SCAN_IN)
@@ -594,19 +597,19 @@ void ft2232_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size
                {
                        /* Clock Data Bits In and Out LSB First */
                        BUFFER_ADD = 0x3b;
-                       //DEBUG("added TDI bits (io) %i", bits_left - 1);
+                       /* DEBUG("added TDI bits (io) %i", bits_left - 1); */
                }
                else if (type == SCAN_OUT)
                {
                        /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
                        BUFFER_ADD = 0x1b;
-                       //DEBUG("added TDI bits (o)");
+                       /* DEBUG("added TDI bits (o)"); */
                }
                else if (type == SCAN_IN)
                {
                        /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
                        BUFFER_ADD = 0x2a;
-                       //DEBUG("added TDI bits (i %i)", bits_left - 1);
+                       /* DEBUG("added TDI bits (i %i)", bits_left - 1); */
                }
                BUFFER_ADD = 0x0;
                BUFFER_ADD = last_bit;
@@ -618,13 +621,13 @@ void ft2232_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size
                {
                        /* Clock Data to TMS/CS Pin with Read */
                        BUFFER_ADD = 0x6b;
-                       //DEBUG("added TMS scan (read)");
+                       /* DEBUG("added TMS scan (read)"); */
                }
                else
                {
                        /* Clock Data to TMS/CS Pin (no Read) */
                        BUFFER_ADD = 0x4b;
-                       //DEBUG("added TMS scan (no read)");
+                       /* DEBUG("added TMS scan (no read)"); */
                }
                BUFFER_ADD = 0x6;
                BUFFER_ADD = TAP_MOVE(cur_state, end_state) | (last_bit << 7);
@@ -679,19 +682,19 @@ int ft2232_large_scan(scan_command_t *cmd, enum scan_type type, u8 *buffer, int
                {
                        /* Clock Data Bytes In and Out LSB First */
                        BUFFER_ADD = 0x39;
-                       //DEBUG("added TDI bytes (io %i)", num_bytes);
+                       /* DEBUG("added TDI bytes (io %i)", num_bytes); */
                }
                else if (type == SCAN_OUT)
                {
                        /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
                        BUFFER_ADD = 0x19;
-                       //DEBUG("added TDI bytes (o)");
+                       /* DEBUG("added TDI bytes (o)"); */
                }
                else if (type == SCAN_IN)
                {
                        /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
                        BUFFER_ADD = 0x28;
-                       //DEBUG("added TDI bytes (i %i)", num_bytes);
+                       /* DEBUG("added TDI bytes (i %i)", num_bytes); */
                }
                thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
                thisrun_read = thisrun_bytes;
@@ -748,19 +751,19 @@ int ft2232_large_scan(scan_command_t *cmd, enum scan_type type, u8 *buffer, int
                {
                        /* Clock Data Bits In and Out LSB First */
                        BUFFER_ADD = 0x3b;
-                       //DEBUG("added TDI bits (io) %i", bits_left - 1);
+                       /* DEBUG("added TDI bits (io) %i", bits_left - 1); */
                }
                else if (type == SCAN_OUT)
                {
                        /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
                        BUFFER_ADD = 0x1b;
-                       //DEBUG("added TDI bits (o)");
+                       /* DEBUG("added TDI bits (o)"); */
                }
                else if (type == SCAN_IN)
                {
                        /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
                        BUFFER_ADD = 0x2a;
-                       //DEBUG("added TDI bits (i %i)", bits_left - 1);
+                       /* DEBUG("added TDI bits (i %i)", bits_left - 1); */
                }
                BUFFER_ADD = bits_left - 2;
                if (type != SCAN_IN)
@@ -776,19 +779,19 @@ int ft2232_large_scan(scan_command_t *cmd, enum scan_type type, u8 *buffer, int
                {
                        /* Clock Data Bits In and Out LSB First */
                        BUFFER_ADD = 0x3b;
-                       //DEBUG("added TDI bits (io) %i", bits_left - 1);
+                       /* DEBUG("added TDI bits (io) %i", bits_left - 1); */
                }
                else if (type == SCAN_OUT)
                {
                        /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
                        BUFFER_ADD = 0x1b;
-                       //DEBUG("added TDI bits (o)");
+                       /* DEBUG("added TDI bits (o)"); */
                }
                else if (type == SCAN_IN)
                {
                        /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
                        BUFFER_ADD = 0x2a;
-                       //DEBUG("added TDI bits (i %i)", bits_left - 1);
+                       /* DEBUG("added TDI bits (i %i)", bits_left - 1); */
                }
                BUFFER_ADD = 0x0;
                BUFFER_ADD = last_bit;
@@ -800,13 +803,13 @@ int ft2232_large_scan(scan_command_t *cmd, enum scan_type type, u8 *buffer, int
                {
                        /* Clock Data to TMS/CS Pin with Read */
                        BUFFER_ADD = 0x6b;
-                       //DEBUG("added TMS scan (read)");
+                       /* DEBUG("added TMS scan (read)"); */
                }
                else
                {
                        /* Clock Data to TMS/CS Pin (no Read) */
                        BUFFER_ADD = 0x4b;
-                       //DEBUG("added TMS scan (no read)");
+                       /* DEBUG("added TMS scan (no read)"); */
                }
                BUFFER_ADD = 0x6;
                BUFFER_ADD = TAP_MOVE(cur_state, end_state) | (last_bit << 7);
@@ -878,7 +881,7 @@ int ft2232_predict_scan_in(int scan_size, enum scan_type type)
                predicted_size += 1;
        }
        
-       //DEBUG("scan_size: %i, predicted_size: %i", scan_size, predicted_size);
+       /* DEBUG("scan_size: %i, predicted_size: %i", scan_size, predicted_size); */
 
        return predicted_size;
 }
@@ -1073,6 +1076,39 @@ void comstick_reset(int trst, int srst)
        DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
 }
 
+void stm32stick_reset(int trst, int srst)
+{
+       if (trst == 1)
+       {
+               cur_state = TAP_TLR;
+               high_output &= ~nTRST;
+       }
+       else if (trst == 0)
+       {
+               high_output |= nTRST;
+       }
+
+    if (srst == 1)
+    {
+        low_output &= ~nSRST;
+    }
+    else if (srst == 0)
+    {
+        low_output |= nSRST;
+    }
+       
+       /* command "set data bits low byte" */
+       BUFFER_ADD = 0x80;
+       BUFFER_ADD = low_output;
+       BUFFER_ADD = low_direction;
+       
+       /* command "set data bits high byte" */
+       BUFFER_ADD = 0x82;
+       BUFFER_ADD = high_output;
+       BUFFER_ADD = high_direction;
+       DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
+}
+
 int ft2232_execute_queue()
 {
        jtag_command_t *cmd = jtag_command_queue; /* currently processed command */
@@ -1162,7 +1198,7 @@ int ft2232_execute_queue()
                                        BUFFER_ADD = 0x0;
                                        cur_state = TAP_RTI;
                                        i -= (i > 7) ? 7 : i;
-                                       //DEBUG("added TMS scan (no read)");
+                                       /* DEBUG("added TMS scan (no read)"); */
                                }
                                if (cmd->cmd.runtest->end_state != -1)
                                        ft2232_end_state(cmd->cmd.runtest->end_state);
@@ -1175,7 +1211,7 @@ int ft2232_execute_queue()
                                        /* TMS data bits */
                                        BUFFER_ADD = TAP_MOVE(cur_state, end_state);
                                        cur_state = end_state;
-                                       //DEBUG("added TMS scan (no read)");
+                                       /* DEBUG("added TMS scan (no read)"); */
                                }
                                require_send = 1;
 #ifdef _DEBUG_JTAG_IO_                         
@@ -1200,7 +1236,7 @@ int ft2232_execute_queue()
                                BUFFER_ADD = 0x6;
                                /* TMS data bits */
                                BUFFER_ADD = TAP_MOVE(cur_state, end_state);
-                               //DEBUG("added TMS scan (no read)");
+                               /* DEBUG("added TMS scan (no read)"); */
                                cur_state = end_state;
                                require_send = 1;
 #ifdef _DEBUG_JTAG_IO_                         
@@ -1254,7 +1290,7 @@ int ft2232_execute_queue()
                                        first_unsent = cmd;
                                }
                                ft2232_expect_read += ft2232_predict_scan_in(scan_size, type);
-                               //DEBUG("new read size: %i", ft2232_expect_read);
+                               /* DEBUG("new read size: %i", ft2232_expect_read); */
                                if (cmd->cmd.scan->end_state != -1)
                                        ft2232_end_state(cmd->cmd.scan->end_state);
                                ft2232_add_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
@@ -1368,7 +1404,7 @@ static int ft2232_init_ftd2xx(u16 vid, u16 pid, int more, int *try_more)
                }
                else
                {
-                       printf("ListDevices: NONE\n");
+                       ERROR("ListDevices: NONE\n");
                }
                return ERROR_JTAG_INIT_FAILED;
        }
@@ -1916,6 +1952,49 @@ int comstick_init(void)
        return ERROR_OK;
 }
 
+int stm32stick_init(void)
+{
+       u8 buf[3];
+       u32 bytes_written;
+       
+       low_output = 0x88;
+       low_direction = 0x8b;
+       
+       /* initialize low byte for jtag */
+       buf[0] = 0x80; /* command "set data bits low byte" */
+       buf[1] = low_output; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
+       buf[2] = low_direction; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
+       DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
+       
+       if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
+       {
+               ERROR("couldn't initialize FT2232 with 'stm32stick' layout"); 
+               return ERROR_JTAG_INIT_FAILED;
+       }
+               
+       nTRST = 0x01;
+       nTRSTnOE = 0x00; /* no output enable for nTRST */
+       nSRST = 0x80;
+       nSRSTnOE = 0x00; /* no output enable for nSRST */
+       
+       high_output = 0x01;
+       high_direction = 0x03;
+       
+       /* initialize high port */
+       buf[0] = 0x82; /* command "set data bits high byte" */
+       buf[1] = high_output;
+       buf[2] = high_direction;
+       DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
+       
+       if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
+       {
+               ERROR("couldn't initialize FT2232 with 'stm32stick' layout"); 
+               return ERROR_JTAG_INIT_FAILED;
+       }
+       
+       return ERROR_OK;
+}
+
 void olimex_jtag_blink(void)
 {
        /* Olimex ARM-USB-OCD has a LED connected to ACBUS3
@@ -1972,6 +2051,7 @@ int ft2232_quit(void)
 #endif
 
        free(ft2232_buffer);
+       ft2232_buffer = NULL;
 
        return ERROR_OK;
 }
@@ -2058,3 +2138,4 @@ int ft2232_handle_latency_command(struct command_context_s *cmd_ctx, char *cmd,
        return ERROR_OK;
 }
 
+

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)