- add support for standalone rlink
[openocd.git] / src / jtag / ft2232.c
index 9a3c986fecf6f70cb2944785dfd4bebbfb16fb82..ae72e35da906900946f7b4082650f68593d65139 100644 (file)
@@ -97,6 +97,7 @@ int ft2232_handle_latency_command(struct command_context_s* cmd_ctx, char* cmd,
 static int ft2232_stableclocks(int num_cycles, jtag_command_t* cmd);
 
 
+char *        ft2232_device_desc_A = NULL;
 char*         ft2232_device_desc = NULL;
 char*         ft2232_serial  = NULL;
 char*         ft2232_layout  = NULL;
@@ -124,6 +125,7 @@ int  turtle_init(void);
 int  comstick_init(void);
 int  stm32stick_init(void);
 int  axm0432_jtag_init(void);
+int sheevaplug_init(void);
 
 /* reset procedures for supported layouts */
 void usbjtag_reset(int trst, int srst);
@@ -134,9 +136,11 @@ void turtle_reset(int trst, int srst);
 void comstick_reset(int trst, int srst);
 void stm32stick_reset(int trst, int srst);
 void axm0432_jtag_reset(int trst, int srst);
+void sheevaplug_reset(int trst, int srst);
 
 /* blink procedures for layouts that support a blinking led */
 void olimex_jtag_blink(void);
+void flyswatter_jtag_blink(void);
 void turtle_jtag_blink(void);
 
 ft2232_layout_t            ft2232_layouts[] =
@@ -148,11 +152,12 @@ ft2232_layout_t            ft2232_layouts[] =
        { "signalyzer",           usbjtag_init,              usbjtag_reset,      NULL                    },
        { "evb_lm3s811",          usbjtag_init,              usbjtag_reset,      NULL                    },
        { "olimex-jtag",          olimex_jtag_init,          olimex_jtag_reset,  olimex_jtag_blink       },
-       { "flyswatter",           flyswatter_init,           flyswatter_reset,   NULL                    },
+       { "flyswatter",           flyswatter_init,           flyswatter_reset,   flyswatter_jtag_blink   },
        { "turtelizer2",          turtle_init,               turtle_reset,       turtle_jtag_blink       },
        { "comstick",             comstick_init,             comstick_reset,     NULL                    },
        { "stm32stick",           stm32stick_init,           stm32stick_reset,   NULL                    },
        { "axm0432_jtag",         axm0432_jtag_init,         axm0432_jtag_reset, NULL                    },
+       {"sheevaplug",            sheevaplug_init,           sheevaplug_reset,   NULL                    },
        { NULL,                   NULL,                      NULL },
 };
 
@@ -562,9 +567,9 @@ void ft2232_add_pathmove(pathmove_command_t* cmd)
 
                while (num_states_batch--)
                {
-                       if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[state_count])
+                       if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
                                buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
-                       else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[state_count])
+                       else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
                                buf_set_u32(&tms_byte, bit_count++, 1, 0x1);
                        else
                        {
@@ -1253,6 +1258,26 @@ void stm32stick_reset(int trst, int srst)
 }
 
 
+
+void sheevaplug_reset(int trst, int srst)
+{
+       if (trst == 1)
+               high_output &= ~nTRST;
+       else if (trst == 0)
+               high_output |= nTRST;
+
+       if (srst == 1)
+               high_output &= ~nSRSTnOE;
+       else if (srst == 0)
+               high_output |= nSRSTnOE;
+
+       /* command "set data bits high byte" */
+       BUFFER_ADD = 0x82;
+       BUFFER_ADD = high_output;
+       BUFFER_ADD = high_direction;
+       LOG_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 */
@@ -1546,7 +1571,28 @@ static int ft2232_init_ftd2xx(u16 vid, u16 pid, int more, int* try_more)
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       if ( ( status = FT_OpenEx(openex_string, openex_flags, &ftdih) ) != FT_OK )
+       status = FT_OpenEx(openex_string, openex_flags, &ftdih);
+       if( status != FT_OK ){
+               // under Win32, the FTD2XX driver appends an "A" to the end
+               // of the description, if we tried by the desc, then
+               // try by the alternate "A" description.
+               if( openex_string == ft2232_device_desc ){
+                       // Try the alternate method.
+                       openex_string = ft2232_device_desc_A;
+                       status = FT_OpenEx(openex_string, openex_flags, &ftdih);
+                       if( status == FT_OK ){
+                               // yea, the "alternate" method worked!
+                       } else {
+                               // drat, give the user a meaningfull message.
+                               // telling the use we tried *BOTH* methods.
+                               LOG_WARNING("Unable to open FTDI Device tried: '%s' and '%s'\n",
+                                                       ft2232_device_desc,
+                                                       ft2232_device_desc_A );
+                       }
+               }
+       }
+
+       if ( status != FT_OK )
        {
                DWORD num_devices;
 
@@ -2113,7 +2159,7 @@ int flyswatter_init(void)
        high_output    = 0x00;
        high_direction = 0x0c;
 
-       /* turn red LED1 on, LED2 off */
+       /* turn red LED3 on, LED2 off */
        high_output |= 0x08;
 
        /* initialize high port */
@@ -2261,6 +2307,57 @@ int stm32stick_init(void)
 }
 
 
+int sheevaplug_init(void)
+{
+       u8 buf[3];
+       u32 bytes_written;
+
+       low_output = 0x08;
+       low_direction = 0x1b;
+
+       /* 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 */
+       LOG_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))
+       {
+               LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout"); 
+               return ERROR_JTAG_INIT_FAILED;
+       }
+
+       nTRSTnOE = 0x1;
+       nTRST = 0x02;
+       nSRSTnOE = 0x4;
+       nSRST = 0x08;
+
+       high_output = 0x0;
+       high_direction = 0x0f;
+
+       /* nTRST is always push-pull */
+       high_output &= ~nTRSTnOE;
+       high_output |= nTRST;
+
+       /* nSRST is always open-drain */
+       high_output |= nSRSTnOE;
+       high_output &= ~nSRST;
+
+       /* initialize high port */
+       buf[0] = 0x82; /* command "set data bits high byte" */
+       buf[1] = high_output; /* value */
+       buf[2] = high_direction;   /* all outputs - xRST */
+       LOG_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))
+       {
+               LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout"); 
+               return ERROR_JTAG_INIT_FAILED;
+       }
+
+       return ERROR_OK;
+}
+
 void olimex_jtag_blink(void)
 {
        /* Olimex ARM-USB-OCD has a LED connected to ACBUS3
@@ -2283,6 +2380,19 @@ void olimex_jtag_blink(void)
 }
 
 
+void flyswatter_jtag_blink(void)
+{
+       /*
+        * Flyswatter has two LEDs connected to ACBUS2 and ACBUS3
+        */
+       high_output ^= 0x0c;
+
+       BUFFER_ADD = 0x82;
+       BUFFER_ADD = high_output;
+       BUFFER_ADD = high_direction;
+}
+
+
 void turtle_jtag_blink(void)
 {
        /*
@@ -2326,9 +2436,29 @@ int ft2232_quit(void)
 
 int ft2232_handle_device_desc_command(struct command_context_s* cmd_ctx, char* cmd, char** args, int argc)
 {
+       char *cp;
+       char buf[200];
        if (argc == 1)
        {
                ft2232_device_desc = strdup(args[0]);
+               cp = strchr( ft2232_device_desc, 0 );
+               // under Win32, the FTD2XX driver appends an "A" to the end
+               // of the description, this examines the given desc
+               // and creates the 'missing' _A or non_A variable.
+               if( (cp[-1] == 'A') && (cp[-2]==' ') ){
+                       // it was, so make this the "A" version.
+                       ft2232_device_desc_A = ft2232_device_desc;
+                       // and *CREATE* the non-A version.
+                       strcpy( buf, ft2232_device_desc );
+                       cp = strchr( buf, 0 );
+                       cp[-2] = 0;
+                       ft2232_device_desc =  strdup( buf );
+               } else {
+                       // <space>A not defined
+                       // so create it
+                       sprintf( buf, "%s A", ft2232_device_desc );
+                       ft2232_device_desc_A = strdup( buf );
+               }
        }
        else
        {

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)