Fix ft2232 for CygWin, provided by Michael Bruck <mbruck@digenius.de>.
[openocd.git] / src / jtag / ft2232.c
index a985465347e8529861b3b22577360cea3ec33382..70050babe8e9eac3bb3936cdebe9d0ec1804f77a 100644 (file)
 #include "config.h"
 #endif
 
-#if IS_CYGWIN == 1
-#include "windows.h"
-#endif
-
-#include "replacements.h"
-
 /* project specific includes */
-#include "log.h"
-#include "types.h"
 #include "jtag.h"
-#include "configuration.h"
 #include "time_support.h"
 
-/* system includes */
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
+#if IS_CYGWIN == 1
+#include <windows.h>
+#endif
+
 
 /* FT2232 access library includes */
 #if BUILD_FT2232_FTD2XX == 1
@@ -114,6 +105,7 @@ static int  comstick_init(void);
 static int  stm32stick_init(void);
 static int  axm0432_jtag_init(void);
 static int sheevaplug_init(void);
+static int icebear_jtag_init(void);
 
 /* reset procedures for supported layouts */
 static void usbjtag_reset(int trst, int srst);
@@ -125,6 +117,7 @@ static void comstick_reset(int trst, int srst);
 static void stm32stick_reset(int trst, int srst);
 static void axm0432_jtag_reset(int trst, int srst);
 static void sheevaplug_reset(int trst, int srst);
+static void icebear_jtag_reset(int trst, int srst);
 
 /* blink procedures for layouts that support a blinking led */
 static void olimex_jtag_blink(void);
@@ -146,6 +139,7 @@ ft2232_layout_t            ft2232_layouts[] =
        { "stm32stick",           stm32stick_init,           stm32stick_reset,   NULL                    },
        { "axm0432_jtag",         axm0432_jtag_init,         axm0432_jtag_reset, NULL                    },
        {"sheevaplug",            sheevaplug_init,           sheevaplug_reset,   NULL                    },
+       { "icebear",              icebear_jtag_init,         icebear_jtag_reset, NULL                    },
        { NULL,                   NULL,                      NULL,               NULL                    },
 };
 
@@ -1590,13 +1584,13 @@ static int ft2232_execute_queue()
                if (ft2232_execute_command(cmd) != ERROR_OK)
                        retval = ERROR_JTAG_QUEUE_FAILED;
                /* Start reading input before FT2232 TX buffer fills up */
-               if (ft2232_expect_read > 280)
+               cmd = cmd->next;
+               if (ft2232_expect_read > 256)
                {
                        if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
                                retval = ERROR_JTAG_QUEUE_FAILED;
                        first_unsent = cmd;
                }
-               cmd = cmd->next;
        }
 
        if (require_send > 0)
@@ -2661,3 +2655,105 @@ static int ft2232_stableclocks(int num_cycles, jtag_command_t* cmd)
 
        return retval;
 }
+
+/* ---------------------------------------------------------------------
+ * Support for IceBear JTAG adapter from Section5:
+ *     http://section5.ch/icebear
+ *
+ * Author: Sten, debian@sansys-electronic.com
+ */
+
+/* Icebear pin layout
+ *
+ * ADBUS5 (nEMU) nSRST | 2   1|        GND (10k->VCC)
+ * GND GND             | 4   3|        n.c.
+ * ADBUS3 TMS          | 6   5|        ADBUS6 VCC
+ * ADBUS0 TCK          | 8   7|        ADBUS7 (GND)
+ * ADBUS4 nTRST                |10   9|        ACBUS0 (GND)
+ * ADBUS1 TDI          |12  11|        ACBUS1 (GND)
+ * ADBUS2 TDO          |14  13|        GND GND
+ *
+ * ADBUS0 O L TCK              ACBUS0 GND
+ * ADBUS1 O L TDI              ACBUS1 GND
+ * ADBUS2 I   TDO              ACBUS2 n.c.
+ * ADBUS3 O H TMS              ACBUS3 n.c.
+ * ADBUS4 O H nTRST
+ * ADBUS5 O H nSRST
+ * ADBUS6 -   VCC
+ * ADBUS7 -   GND
+ */
+static int icebear_jtag_init(void) {
+       u8  buf[3];
+       u32 bytes_written;
+
+       low_direction   = 0x0b; /* output: TCK TDI TMS; input: TDO */
+       low_output      = 0x08; /* high: TMS; low: TCK TDI */
+       nTRST           = 0x10;
+       nSRST           = 0x20;
+
+       if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0) {
+               low_direction   &= ~nTRST;      /* nTRST high impedance */
+       }
+       else {
+               low_direction   |= nTRST;
+               low_output      |= nTRST;
+       }
+
+       low_direction   |= nSRST;
+       low_output      |= nSRST;
+
+       /* initialize low byte for jtag */
+       buf[0] = 0x80;          /* command "set data bits low byte" */
+       buf[1] = low_output;
+       buf[2] = low_direction;
+       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 'IceBear' layout (low)");
+               return ERROR_JTAG_INIT_FAILED;
+       }
+
+       high_output    = 0x0;
+       high_direction = 0x00;
+
+
+       /* initialize high port */
+       buf[0] = 0x82;              /* command "set data bits high byte" */
+       buf[1] = high_output;       /* value */
+       buf[2] = high_direction;    /* all outputs (xRST and xRSTnOE) */
+       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 'IceBear' layout (high)");
+               return ERROR_JTAG_INIT_FAILED;
+       }
+
+       return ERROR_OK;
+}
+
+static void icebear_jtag_reset(int trst, int srst) {
+
+       if (trst == 1) {
+               low_direction   |= nTRST;
+               low_output      &= ~nTRST;
+       }
+       else if (trst == 0) {
+               if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0)
+                       low_direction   &= ~nTRST;
+               else
+                       low_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;
+       LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction);
+}

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)