1 /***************************************************************************
2 * Copyright (C) 2004, 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2008 by Spencer Oliver *
6 * spen@spen-soft.co.uk *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
25 /* This code uses information contained in the MPSSE specification which was
27 * http://www.ftdichip.com/Documents/AppNotes/AN2232C-01_MPSSE_Cmnd.pdf
28 * Hereafter this is called the "MPSSE Spec".
40 #include "replacements.h"
42 /* project specific includes */
46 #include "configuration.h"
47 #include "time_support.h"
54 /* FT2232 access library includes */
55 #if BUILD_FT2232_FTD2XX == 1
57 #elif BUILD_FT2232_LIBFTDI == 1
61 static int ft2232_execute_queue(void);
63 static int ft2232_speed(int speed
);
64 static int ft2232_speed_div(int speed
, int* khz
);
65 static int ft2232_khz(int khz
, int* jtag_speed
);
66 static int ft2232_register_commands(struct command_context_s
* cmd_ctx
);
67 static int ft2232_init(void);
68 static int ft2232_quit(void);
70 static int ft2232_handle_device_desc_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
71 static int ft2232_handle_serial_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
72 static int ft2232_handle_layout_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
73 static int ft2232_handle_vid_pid_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
74 static int ft2232_handle_latency_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
78 * Function ft2232_stableclocks
79 * will send out \a num_cycles on the TCK line while the TAP(s)
80 * are in a stable state. Calling code must ensure that current state is
81 * stable, that verification is not done in here.
82 * @param num_cycles is the count of clocks cycles to send.
83 * @return int - ERROR_OK or ERROR_JTAG_QUEUE_FAILED
85 static int ft2232_stableclocks(int num_cycles
, jtag_command_t
* cmd
);
88 static char * ft2232_device_desc_A
= NULL
;
89 static char* ft2232_device_desc
= NULL
;
90 static char* ft2232_serial
= NULL
;
91 static char* ft2232_layout
= NULL
;
92 static unsigned char ft2232_latency
= 2;
95 /* vid = pid = 0 marks the end of the list */
96 static u16 ft2232_vid
[MAX_USB_IDS
+ 1] = { 0x0403, 0 };
97 static u16 ft2232_pid
[MAX_USB_IDS
+ 1] = { 0x6010, 0 };
99 typedef struct ft2232_layout_s
103 void (*reset
)(int trst
, int srst
);
107 /* init procedures for supported layouts */
108 static int usbjtag_init(void);
109 static int jtagkey_init(void);
110 static int olimex_jtag_init(void);
111 static int flyswatter_init(void);
112 static int turtle_init(void);
113 static int comstick_init(void);
114 static int stm32stick_init(void);
115 static int axm0432_jtag_init(void);
116 static int sheevaplug_init(void);
118 /* reset procedures for supported layouts */
119 static void usbjtag_reset(int trst
, int srst
);
120 static void jtagkey_reset(int trst
, int srst
);
121 static void olimex_jtag_reset(int trst
, int srst
);
122 static void flyswatter_reset(int trst
, int srst
);
123 static void turtle_reset(int trst
, int srst
);
124 static void comstick_reset(int trst
, int srst
);
125 static void stm32stick_reset(int trst
, int srst
);
126 static void axm0432_jtag_reset(int trst
, int srst
);
127 static void sheevaplug_reset(int trst
, int srst
);
129 /* blink procedures for layouts that support a blinking led */
130 static void olimex_jtag_blink(void);
131 static void flyswatter_jtag_blink(void);
132 static void turtle_jtag_blink(void);
134 ft2232_layout_t ft2232_layouts
[] =
136 { "usbjtag", usbjtag_init
, usbjtag_reset
, NULL
},
137 { "jtagkey", jtagkey_init
, jtagkey_reset
, NULL
},
138 { "jtagkey_prototype_v1", jtagkey_init
, jtagkey_reset
, NULL
},
139 { "oocdlink", jtagkey_init
, jtagkey_reset
, NULL
},
140 { "signalyzer", usbjtag_init
, usbjtag_reset
, NULL
},
141 { "evb_lm3s811", usbjtag_init
, usbjtag_reset
, NULL
},
142 { "olimex-jtag", olimex_jtag_init
, olimex_jtag_reset
, olimex_jtag_blink
},
143 { "flyswatter", flyswatter_init
, flyswatter_reset
, flyswatter_jtag_blink
},
144 { "turtelizer2", turtle_init
, turtle_reset
, turtle_jtag_blink
},
145 { "comstick", comstick_init
, comstick_reset
, NULL
},
146 { "stm32stick", stm32stick_init
, stm32stick_reset
, NULL
},
147 { "axm0432_jtag", axm0432_jtag_init
, axm0432_jtag_reset
, NULL
},
148 {"sheevaplug", sheevaplug_init
, sheevaplug_reset
, NULL
},
149 { NULL
, NULL
, NULL
, NULL
},
152 static u8 nTRST
, nTRSTnOE
, nSRST
, nSRSTnOE
;
154 static ft2232_layout_t
* layout
;
155 static u8 low_output
= 0x0;
156 static u8 low_direction
= 0x0;
157 static u8 high_output
= 0x0;
158 static u8 high_direction
= 0x0;
160 #if BUILD_FT2232_FTD2XX == 1
161 static FT_HANDLE ftdih
= NULL
;
162 #elif BUILD_FT2232_LIBFTDI == 1
163 static struct ftdi_context ftdic
;
167 static jtag_command_t
* first_unsent
; /* next command that has to be sent */
168 static int require_send
;
170 static u8
* ft2232_buffer
= NULL
;
171 static int ft2232_buffer_size
= 0;
172 static int ft2232_read_pointer
= 0;
173 static int ft2232_expect_read
= 0;
175 #define FT2232_BUFFER_SIZE 131072
176 #define BUFFER_ADD ft2232_buffer[ft2232_buffer_size++]
177 #define BUFFER_READ ft2232_buffer[ft2232_read_pointer++]
179 jtag_interface_t ft2232_interface
=
182 .execute_queue
= ft2232_execute_queue
,
183 .speed
= ft2232_speed
,
184 .speed_div
= ft2232_speed_div
,
186 .register_commands
= ft2232_register_commands
,
191 static int ft2232_write(u8
* buf
, int size
, u32
* bytes_written
)
193 #if BUILD_FT2232_FTD2XX == 1
195 DWORD dw_bytes_written
;
196 if ( ( status
= FT_Write(ftdih
, buf
, size
, &dw_bytes_written
) ) != FT_OK
)
198 *bytes_written
= dw_bytes_written
;
199 LOG_ERROR("FT_Write returned: %lu", status
);
200 return ERROR_JTAG_DEVICE_ERROR
;
204 *bytes_written
= dw_bytes_written
;
207 #elif BUILD_FT2232_LIBFTDI == 1
209 if ( ( retval
= ftdi_write_data(&ftdic
, buf
, size
) ) < 0 )
212 LOG_ERROR( "ftdi_write_data: %s", ftdi_get_error_string(&ftdic
) );
213 return ERROR_JTAG_DEVICE_ERROR
;
217 *bytes_written
= retval
;
224 static int ft2232_read(u8
* buf
, u32 size
, u32
* bytes_read
)
226 #if BUILD_FT2232_FTD2XX == 1
232 while ( (*bytes_read
< size
) && timeout
-- )
234 if ( ( status
= FT_Read(ftdih
, buf
+ *bytes_read
, size
-
235 *bytes_read
, &dw_bytes_read
) ) != FT_OK
)
238 LOG_ERROR("FT_Read returned: %lu", status
);
239 return ERROR_JTAG_DEVICE_ERROR
;
241 *bytes_read
+= dw_bytes_read
;
244 #elif BUILD_FT2232_LIBFTDI == 1
249 while ( (*bytes_read
< size
) && timeout
-- )
251 if ( ( retval
= ftdi_read_data(&ftdic
, buf
+ *bytes_read
, size
- *bytes_read
) ) < 0 )
254 LOG_ERROR( "ftdi_read_data: %s", ftdi_get_error_string(&ftdic
) );
255 return ERROR_JTAG_DEVICE_ERROR
;
257 *bytes_read
+= retval
;
262 if (*bytes_read
< size
)
264 LOG_ERROR("couldn't read the requested number of bytes from FT2232 device (%i < %i)", *bytes_read
, size
);
265 return ERROR_JTAG_DEVICE_ERROR
;
272 static int ft2232_speed(int speed
)
278 buf
[0] = 0x86; /* command "set divisor" */
279 buf
[1] = speed
& 0xff; /* valueL (0=6MHz, 1=3MHz, 2=2.0MHz, ...*/
280 buf
[2] = (speed
>> 8) & 0xff; /* valueH */
282 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
283 if ( ( ( retval
= ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
285 LOG_ERROR("couldn't set FT2232 TCK speed");
293 static int ft2232_speed_div(int speed
, int* khz
)
295 /* Take a look in the FT2232 manual,
296 * AN2232C-01 Command Processor for
297 * MPSSE and MCU Host Bus. Chapter 3.8 */
299 *khz
= 6000 / (1 + speed
);
305 static int ft2232_khz(int khz
, int* jtag_speed
)
309 LOG_ERROR("RCLK not supported");
313 /* Take a look in the FT2232 manual,
314 * AN2232C-01 Command Processor for
315 * MPSSE and MCU Host Bus. Chapter 3.8
317 * We will calc here with a multiplier
318 * of 10 for better rounding later. */
320 /* Calc speed, (6000 / khz) - 1 */
321 /* Use 65000 for better rounding */
322 *jtag_speed
= (60000 / khz
) - 10;
324 /* Add 0.9 for rounding */
327 /* Calc real speed */
328 *jtag_speed
= *jtag_speed
/ 10;
330 /* Check if speed is greater than 0 */
336 /* Check max value */
337 if (*jtag_speed
> 0xFFFF)
339 *jtag_speed
= 0xFFFF;
346 static int ft2232_register_commands(struct command_context_s
* cmd_ctx
)
348 register_command(cmd_ctx
, NULL
, "ft2232_device_desc", ft2232_handle_device_desc_command
,
349 COMMAND_CONFIG
, "the USB device description of the FTDI FT2232 device");
350 register_command(cmd_ctx
, NULL
, "ft2232_serial", ft2232_handle_serial_command
,
351 COMMAND_CONFIG
, "the serial number of the FTDI FT2232 device");
352 register_command(cmd_ctx
, NULL
, "ft2232_layout", ft2232_handle_layout_command
,
353 COMMAND_CONFIG
, "the layout of the FT2232 GPIO signals used to control output-enables and reset signals");
354 register_command(cmd_ctx
, NULL
, "ft2232_vid_pid", ft2232_handle_vid_pid_command
,
355 COMMAND_CONFIG
, "the vendor ID and product ID of the FTDI FT2232 device");
356 register_command(cmd_ctx
, NULL
, "ft2232_latency", ft2232_handle_latency_command
,
357 COMMAND_CONFIG
, "set the FT2232 latency timer to a new value");
362 void ft2232_end_state(tap_state_t state
)
364 if (tap_is_state_stable(state
))
365 tap_set_end_state(state
);
368 LOG_ERROR("BUG: %i is not a valid end state", state
);
374 static void ft2232_read_scan(enum scan_type type
, u8
* buffer
, int scan_size
)
376 int num_bytes
= (scan_size
+ 7) / 8;
377 int bits_left
= scan_size
;
380 while (num_bytes
-- > 1)
382 buffer
[cur_byte
] = BUFFER_READ
;
387 buffer
[cur_byte
] = 0x0;
391 buffer
[cur_byte
] = BUFFER_READ
>> 1;
394 buffer
[cur_byte
] = ( buffer
[cur_byte
] | ( (BUFFER_READ
& 0x02) << 6 ) ) >> (8 - bits_left
);
398 static void ft2232_debug_dump_buffer(void)
404 for (i
= 0; i
< ft2232_buffer_size
; i
++)
406 line_p
+= snprintf(line_p
, 256 - (line_p
- line
), "%2.2x ", ft2232_buffer
[i
]);
409 LOG_DEBUG("%s", line
);
415 LOG_DEBUG("%s", line
);
419 static int ft2232_send_and_recv(jtag_command_t
* first
, jtag_command_t
* last
)
429 #ifdef _DEBUG_USB_IO_
430 struct timeval start
, inter
, inter2
, end
;
431 struct timeval d_inter
, d_inter2
, d_end
;
434 #ifdef _DEBUG_USB_COMMS_
435 LOG_DEBUG("write buffer (size %i):", ft2232_buffer_size
);
436 ft2232_debug_dump_buffer();
439 #ifdef _DEBUG_USB_IO_
440 gettimeofday(&start
, NULL
);
443 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
445 LOG_ERROR("couldn't write MPSSE commands to FT2232");
449 #ifdef _DEBUG_USB_IO_
450 gettimeofday(&inter
, NULL
);
453 if (ft2232_expect_read
)
456 ft2232_buffer_size
= 0;
458 #ifdef _DEBUG_USB_IO_
459 gettimeofday(&inter2
, NULL
);
462 if ( ( retval
= ft2232_read(ft2232_buffer
, ft2232_expect_read
, &bytes_read
) ) != ERROR_OK
)
464 LOG_ERROR("couldn't read from FT2232");
468 #ifdef _DEBUG_USB_IO_
469 gettimeofday(&end
, NULL
);
471 timeval_subtract(&d_inter
, &inter
, &start
);
472 timeval_subtract(&d_inter2
, &inter2
, &start
);
473 timeval_subtract(&d_end
, &end
, &start
);
475 LOG_INFO("inter: %u.%06u, inter2: %u.%06u end: %u.%06u",
476 (unsigned)d_inter
.tv_sec
, (unsigned)d_inter
.tv_usec
,
477 (unsigned)d_inter2
.tv_sec
, (unsigned)d_inter2
.tv_usec
,
478 (unsigned)d_end
.tv_sec
, (unsigned)d_end
.tv_usec
);
481 ft2232_buffer_size
= bytes_read
;
483 if (ft2232_expect_read
!= ft2232_buffer_size
)
485 LOG_ERROR("ft2232_expect_read (%i) != ft2232_buffer_size (%i) (%i retries)", ft2232_expect_read
,
488 ft2232_debug_dump_buffer();
493 #ifdef _DEBUG_USB_COMMS_
494 LOG_DEBUG("read buffer (%i retries): %i bytes", 100 - timeout
, ft2232_buffer_size
);
495 ft2232_debug_dump_buffer();
499 ft2232_expect_read
= 0;
500 ft2232_read_pointer
= 0;
502 /* return ERROR_OK, unless a jtag_read_buffer returns a failed check
503 * that wasn't handled by a caller-provided error handler
513 type
= jtag_scan_type(cmd
->cmd
.scan
);
514 if (type
!= SCAN_OUT
)
516 scan_size
= jtag_scan_size(cmd
->cmd
.scan
);
517 buffer
= calloc(CEIL(scan_size
, 8), 1);
518 ft2232_read_scan(type
, buffer
, scan_size
);
519 if (jtag_read_buffer(buffer
, cmd
->cmd
.scan
) != ERROR_OK
)
520 retval
= ERROR_JTAG_QUEUE_FAILED
;
532 ft2232_buffer_size
= 0;
538 static void ft2232_add_pathmove(pathmove_command_t
* cmd
)
540 int num_states
= cmd
->num_states
;
545 u8 tms_byte
= 0; /* zero this on each MPSSE batch */
549 int num_states_batch
= num_states
> 7 ? 7 : num_states
;
551 /* command "Clock Data to TMS/CS Pin (no Read)" */
554 /* number of states remaining */
555 BUFFER_ADD
= num_states_batch
- 1;
557 while (num_states_batch
--)
559 if (tap_state_transition(tap_get_state(), false) == cmd
->path
[state_count
])
560 buf_set_u32(&tms_byte
, bit_count
++, 1, 0x0);
561 else if (tap_state_transition(tap_get_state(), true) == cmd
->path
[state_count
])
562 buf_set_u32(&tms_byte
, bit_count
++, 1, 0x1);
565 LOG_ERROR( "BUG: %s -> %s isn't a valid TAP transition", tap_state_name(
566 tap_get_state() ), tap_state_name(cmd
->path
[state_count
]) );
570 tap_set_state(cmd
->path
[state_count
]);
575 BUFFER_ADD
= tms_byte
;
578 tap_set_end_state(tap_get_state());
582 void ft2232_add_scan(int ir_scan
, enum scan_type type
, u8
* buffer
, int scan_size
)
584 int num_bytes
= (scan_size
+ 7) / 8;
585 int bits_left
= scan_size
;
589 if ( !( ( !ir_scan
&& (tap_get_state() == TAP_DRSHIFT
) )
590 || ( ir_scan
&& (tap_get_state() == TAP_IRSHIFT
) ) ) )
592 /* command "Clock Data to TMS/CS Pin (no Read)" */
595 BUFFER_ADD
= 0x6; /* scan 7 bits */
600 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_IRSHIFT
);
601 tap_set_state(TAP_IRSHIFT
);
605 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_DRSHIFT
);
606 tap_set_state(TAP_DRSHIFT
);
608 /* LOG_DEBUG("added TMS scan (no read)"); */
611 /* add command for complete bytes */
612 while (num_bytes
> 1)
617 /* Clock Data Bytes In and Out LSB First */
619 /* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
621 else if (type
== SCAN_OUT
)
623 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
625 /* LOG_DEBUG("added TDI bytes (o)"); */
627 else if (type
== SCAN_IN
)
629 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
631 /* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
634 thisrun_bytes
= (num_bytes
> 65537) ? 65536 : (num_bytes
- 1);
635 num_bytes
-= thisrun_bytes
;
636 BUFFER_ADD
= (thisrun_bytes
- 1) & 0xff;
637 BUFFER_ADD
= ( (thisrun_bytes
- 1) >> 8 ) & 0xff;
641 /* add complete bytes */
642 while (thisrun_bytes
-- > 0)
644 BUFFER_ADD
= buffer
[cur_byte
];
649 else /* (type == SCAN_IN) */
651 bits_left
-= 8 * (thisrun_bytes
);
655 /* the most signifcant bit is scanned during TAP movement */
657 last_bit
= ( buffer
[cur_byte
] >> (bits_left
- 1) ) & 0x1;
661 /* process remaining bits but the last one */
666 /* Clock Data Bits In and Out LSB First */
668 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
670 else if (type
== SCAN_OUT
)
672 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
674 /* LOG_DEBUG("added TDI bits (o)"); */
676 else if (type
== SCAN_IN
)
678 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
680 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
682 BUFFER_ADD
= bits_left
- 2;
684 BUFFER_ADD
= buffer
[cur_byte
];
687 if ( ( ir_scan
&& (tap_get_end_state() == TAP_IRSHIFT
) )
688 || ( !ir_scan
&& (tap_get_end_state() == TAP_DRSHIFT
) ) )
692 /* Clock Data Bits In and Out LSB First */
694 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
696 else if (type
== SCAN_OUT
)
698 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
700 /* LOG_DEBUG("added TDI bits (o)"); */
702 else if (type
== SCAN_IN
)
704 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
706 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
709 BUFFER_ADD
= last_bit
;
713 /* move from Shift-IR/DR to end state */
714 if (type
!= SCAN_OUT
)
716 /* Clock Data to TMS/CS Pin with Read */
718 /* LOG_DEBUG("added TMS scan (read)"); */
722 /* Clock Data to TMS/CS Pin (no Read) */
724 /* LOG_DEBUG("added TMS scan (no read)"); */
726 BUFFER_ADD
= 0x6; /* scan 7 bits */
728 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() ) | (last_bit
<< 7);
729 tap_set_state( tap_get_end_state() );
734 static int ft2232_large_scan(scan_command_t
* cmd
, enum scan_type type
, u8
* buffer
, int scan_size
)
736 int num_bytes
= (scan_size
+ 7) / 8;
737 int bits_left
= scan_size
;
740 u8
* receive_buffer
= malloc( CEIL(scan_size
, 8) );
741 u8
* receive_pointer
= receive_buffer
;
745 int thisrun_read
= 0;
749 LOG_ERROR("BUG: large IR scans are not supported");
753 if (tap_get_state() != TAP_DRSHIFT
)
755 /* command "Clock Data to TMS/CS Pin (no Read)" */
758 BUFFER_ADD
= 0x6; /* scan 7 bits */
761 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_DRSHIFT
);
762 tap_set_state(TAP_DRSHIFT
);
765 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
767 LOG_ERROR("couldn't write MPSSE commands to FT2232");
770 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
771 ft2232_buffer_size
= 0;
773 /* add command for complete bytes */
774 while (num_bytes
> 1)
780 /* Clock Data Bytes In and Out LSB First */
782 /* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
784 else if (type
== SCAN_OUT
)
786 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
788 /* LOG_DEBUG("added TDI bytes (o)"); */
790 else if (type
== SCAN_IN
)
792 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
794 /* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
797 thisrun_bytes
= (num_bytes
> 65537) ? 65536 : (num_bytes
- 1);
798 thisrun_read
= thisrun_bytes
;
799 num_bytes
-= thisrun_bytes
;
800 BUFFER_ADD
= (thisrun_bytes
- 1) & 0xff;
801 BUFFER_ADD
= ( (thisrun_bytes
- 1) >> 8 ) & 0xff;
805 /* add complete bytes */
806 while (thisrun_bytes
-- > 0)
808 BUFFER_ADD
= buffer
[cur_byte
];
813 else /* (type == SCAN_IN) */
815 bits_left
-= 8 * (thisrun_bytes
);
818 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
820 LOG_ERROR("couldn't write MPSSE commands to FT2232");
823 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
824 ft2232_buffer_size
= 0;
826 if (type
!= SCAN_OUT
)
828 if ( ( retval
= ft2232_read(receive_pointer
, thisrun_read
, &bytes_read
) ) != ERROR_OK
)
830 LOG_ERROR("couldn't read from FT2232");
833 LOG_DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read
, bytes_read
);
834 receive_pointer
+= bytes_read
;
840 /* the most signifcant bit is scanned during TAP movement */
842 last_bit
= ( buffer
[cur_byte
] >> (bits_left
- 1) ) & 0x1;
846 /* process remaining bits but the last one */
851 /* Clock Data Bits In and Out LSB First */
853 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
855 else if (type
== SCAN_OUT
)
857 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
859 /* LOG_DEBUG("added TDI bits (o)"); */
861 else if (type
== SCAN_IN
)
863 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
865 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
867 BUFFER_ADD
= bits_left
- 2;
869 BUFFER_ADD
= buffer
[cur_byte
];
871 if (type
!= SCAN_OUT
)
875 if (tap_get_end_state() == TAP_DRSHIFT
)
879 /* Clock Data Bits In and Out LSB First */
881 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
883 else if (type
== SCAN_OUT
)
885 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
887 /* LOG_DEBUG("added TDI bits (o)"); */
889 else if (type
== SCAN_IN
)
891 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
893 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
896 BUFFER_ADD
= last_bit
;
900 /* move from Shift-IR/DR to end state */
901 if (type
!= SCAN_OUT
)
903 /* Clock Data to TMS/CS Pin with Read */
905 /* LOG_DEBUG("added TMS scan (read)"); */
909 /* Clock Data to TMS/CS Pin (no Read) */
911 /* LOG_DEBUG("added TMS scan (no read)"); */
914 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() ) | (last_bit
<< 7);
915 tap_set_state( tap_get_end_state() );
918 if (type
!= SCAN_OUT
)
921 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
923 LOG_ERROR("couldn't write MPSSE commands to FT2232");
926 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
927 ft2232_buffer_size
= 0;
929 if (type
!= SCAN_OUT
)
931 if ( ( retval
= ft2232_read(receive_pointer
, thisrun_read
, &bytes_read
) ) != ERROR_OK
)
933 LOG_ERROR("couldn't read from FT2232");
936 LOG_DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read
, bytes_read
);
937 receive_pointer
+= bytes_read
;
944 static int ft2232_predict_scan_out(int scan_size
, enum scan_type type
)
946 int predicted_size
= 3;
947 int num_bytes
= (scan_size
- 1) / 8;
949 if (tap_get_state() != TAP_DRSHIFT
)
952 if (type
== SCAN_IN
) /* only from device to host */
955 predicted_size
+= CEIL(num_bytes
, 65536) * 3;
956 /* remaining bits - 1 (up to 7) */
957 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 2 : 0;
959 else /* host to device, or bidirectional */
962 predicted_size
+= num_bytes
+ CEIL(num_bytes
, 65536) * 3;
963 /* remaining bits -1 (up to 7) */
964 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 3 : 0;
967 return predicted_size
;
971 static int ft2232_predict_scan_in(int scan_size
, enum scan_type type
)
973 int predicted_size
= 0;
975 if (type
!= SCAN_OUT
)
978 predicted_size
+= (CEIL(scan_size
, 8) > 1) ? (CEIL(scan_size
, 8) - 1) : 0;
980 /* remaining bits - 1 */
981 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 1 : 0;
983 /* last bit (from TMS scan) */
987 /* LOG_DEBUG("scan_size: %i, predicted_size: %i", scan_size, predicted_size); */
989 return predicted_size
;
993 static void usbjtag_reset(int trst
, int srst
)
997 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
998 low_direction
|= nTRSTnOE
; /* switch to output pin (output is low) */
1000 low_output
&= ~nTRST
; /* switch output low */
1004 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1005 low_direction
&= ~nTRSTnOE
; /* switch to input pin (high-Z + internal and external pullup) */
1007 low_output
|= nTRST
; /* switch output high */
1012 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1013 low_output
&= ~nSRST
; /* switch output low */
1015 low_direction
|= nSRSTnOE
; /* switch to output pin (output is low) */
1019 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1020 low_output
|= nSRST
; /* switch output high */
1022 low_direction
&= ~nSRSTnOE
; /* switch to input pin (high-Z) */
1025 /* command "set data bits low byte" */
1027 BUFFER_ADD
= low_output
;
1028 BUFFER_ADD
= low_direction
;
1032 static void jtagkey_reset(int trst
, int srst
)
1036 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1037 high_output
&= ~nTRSTnOE
;
1039 high_output
&= ~nTRST
;
1043 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1044 high_output
|= nTRSTnOE
;
1046 high_output
|= nTRST
;
1051 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1052 high_output
&= ~nSRST
;
1054 high_output
&= ~nSRSTnOE
;
1058 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1059 high_output
|= nSRST
;
1061 high_output
|= nSRSTnOE
;
1064 /* command "set data bits high byte" */
1066 BUFFER_ADD
= high_output
;
1067 BUFFER_ADD
= high_direction
;
1068 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1073 static void olimex_jtag_reset(int trst
, int srst
)
1077 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1078 high_output
&= ~nTRSTnOE
;
1080 high_output
&= ~nTRST
;
1084 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1085 high_output
|= nTRSTnOE
;
1087 high_output
|= nTRST
;
1092 high_output
|= nSRST
;
1096 high_output
&= ~nSRST
;
1099 /* command "set data bits high byte" */
1101 BUFFER_ADD
= high_output
;
1102 BUFFER_ADD
= high_direction
;
1103 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1108 static void axm0432_jtag_reset(int trst
, int srst
)
1112 tap_set_state(TAP_RESET
);
1113 high_output
&= ~nTRST
;
1117 high_output
|= nTRST
;
1122 high_output
&= ~nSRST
;
1126 high_output
|= nSRST
;
1129 /* command "set data bits low byte" */
1131 BUFFER_ADD
= high_output
;
1132 BUFFER_ADD
= high_direction
;
1133 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1138 static void flyswatter_reset(int trst
, int srst
)
1142 low_output
&= ~nTRST
;
1146 low_output
|= nTRST
;
1151 low_output
|= nSRST
;
1155 low_output
&= ~nSRST
;
1158 /* command "set data bits low byte" */
1160 BUFFER_ADD
= low_output
;
1161 BUFFER_ADD
= low_direction
;
1162 LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst
, srst
, low_output
, low_direction
);
1166 static void turtle_reset(int trst
, int srst
)
1172 low_output
|= nSRST
;
1176 low_output
&= ~nSRST
;
1179 /* command "set data bits low byte" */
1181 BUFFER_ADD
= low_output
;
1182 BUFFER_ADD
= low_direction
;
1183 LOG_DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", srst
, low_output
, low_direction
);
1187 static void comstick_reset(int trst
, int srst
)
1191 high_output
&= ~nTRST
;
1195 high_output
|= nTRST
;
1200 high_output
&= ~nSRST
;
1204 high_output
|= nSRST
;
1207 /* command "set data bits high byte" */
1209 BUFFER_ADD
= high_output
;
1210 BUFFER_ADD
= high_direction
;
1211 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1216 static void stm32stick_reset(int trst
, int srst
)
1220 high_output
&= ~nTRST
;
1224 high_output
|= nTRST
;
1229 low_output
&= ~nSRST
;
1233 low_output
|= nSRST
;
1236 /* command "set data bits low byte" */
1238 BUFFER_ADD
= low_output
;
1239 BUFFER_ADD
= low_direction
;
1241 /* command "set data bits high byte" */
1243 BUFFER_ADD
= high_output
;
1244 BUFFER_ADD
= high_direction
;
1245 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1251 static void sheevaplug_reset(int trst
, int srst
)
1254 high_output
&= ~nTRST
;
1256 high_output
|= nTRST
;
1259 high_output
&= ~nSRSTnOE
;
1261 high_output
|= nSRSTnOE
;
1263 /* command "set data bits high byte" */
1265 BUFFER_ADD
= high_output
;
1266 BUFFER_ADD
= high_direction
;
1267 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
, high_direction
);
1270 static int ft2232_execute_end_state(jtag_command_t
*cmd
)
1275 DEBUG_JTAG_IO("end_state: %i", cmd
->cmd
.end_state
->end_state
);
1277 if (cmd
->cmd
.end_state
->end_state
!= TAP_INVALID
)
1278 ft2232_end_state(cmd
->cmd
.end_state
->end_state
);
1284 static int ft2232_execute_runtest(jtag_command_t
*cmd
)
1288 int predicted_size
= 0;
1291 DEBUG_JTAG_IO("runtest %i cycles, end in %i",
1292 cmd
->cmd
.runtest
->num_cycles
,
1293 cmd
->cmd
.runtest
->end_state
);
1294 /* only send the maximum buffer size that FT2232C can handle */
1296 if (tap_get_state() != TAP_IDLE
)
1297 predicted_size
+= 3;
1298 predicted_size
+= 3 * CEIL(cmd
->cmd
.runtest
->num_cycles
, 7);
1299 if ( (cmd
->cmd
.runtest
->end_state
!= TAP_INVALID
) && (cmd
->cmd
.runtest
->end_state
!= TAP_IDLE
) )
1300 predicted_size
+= 3;
1301 if ( (cmd
->cmd
.runtest
->end_state
== TAP_INVALID
) && (tap_get_end_state() != TAP_IDLE
) )
1302 predicted_size
+= 3;
1303 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1305 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1306 retval
= ERROR_JTAG_QUEUE_FAILED
;
1310 if (tap_get_state() != TAP_IDLE
)
1312 /* command "Clock Data to TMS/CS Pin (no Read)" */
1314 BUFFER_ADD
= 0x6; /* scan 7 bits */
1317 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_IDLE
);
1318 tap_set_state(TAP_IDLE
);
1321 i
= cmd
->cmd
.runtest
->num_cycles
;
1324 /* command "Clock Data to TMS/CS Pin (no Read)" */
1328 BUFFER_ADD
= (i
> 7) ? 6 : (i
- 1);
1332 tap_set_state(TAP_IDLE
);
1333 i
-= (i
> 7) ? 7 : i
;
1334 /* LOG_DEBUG("added TMS scan (no read)"); */
1337 if (cmd
->cmd
.runtest
->end_state
!= TAP_INVALID
)
1338 ft2232_end_state(cmd
->cmd
.runtest
->end_state
);
1340 if ( tap_get_state() != tap_get_end_state() )
1342 /* command "Clock Data to TMS/CS Pin (no Read)" */
1347 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() );
1348 tap_set_state( tap_get_end_state() );
1349 /* LOG_DEBUG("added TMS scan (no read)"); */
1352 #ifdef _DEBUG_JTAG_IO_
1353 LOG_DEBUG( "runtest: %i, end in %s", cmd
->cmd
.runtest
->num_cycles
, tap_state_name( tap_get_end_state() ) );
1359 static int ft2232_execute_statemove(jtag_command_t
*cmd
)
1362 int predicted_size
= 0;
1365 DEBUG_JTAG_IO("statemove end in %i", cmd
->cmd
.statemove
->end_state
);
1367 /* only send the maximum buffer size that FT2232C can handle */
1369 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1371 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1372 retval
= ERROR_JTAG_QUEUE_FAILED
;
1376 if (cmd
->cmd
.statemove
->end_state
!= TAP_INVALID
)
1377 ft2232_end_state(cmd
->cmd
.statemove
->end_state
);
1379 /* command "Clock Data to TMS/CS Pin (no Read)" */
1382 BUFFER_ADD
= 0x6; /* scan 7 bits */
1385 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() );
1386 /* LOG_DEBUG("added TMS scan (no read)"); */
1387 tap_set_state( tap_get_end_state() );
1389 #ifdef _DEBUG_JTAG_IO_
1390 LOG_DEBUG( "statemove: %s", tap_state_name( tap_get_end_state() ) );
1396 static int ft2232_execute_pathmove(jtag_command_t
*cmd
)
1399 int predicted_size
= 0;
1402 DEBUG_JTAG_IO("pathmove: %i states, end in %i",
1403 cmd
->cmd
.pathmove
->num_states
,
1404 cmd
->cmd
.pathmove
->path
[cmd
->cmd
.pathmove
->num_states
- 1]);
1405 /* only send the maximum buffer size that FT2232C can handle */
1406 predicted_size
= 3 * CEIL(cmd
->cmd
.pathmove
->num_states
, 7);
1407 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1409 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1410 retval
= ERROR_JTAG_QUEUE_FAILED
;
1414 ft2232_add_pathmove(cmd
->cmd
.pathmove
);
1416 #ifdef _DEBUG_JTAG_IO_
1417 LOG_DEBUG( "pathmove: %i states, end in %s", cmd
->cmd
.pathmove
->num_states
,
1418 tap_state_name(cmd
->cmd
.pathmove
->path
[cmd
->cmd
.pathmove
->num_states
- 1]) );
1423 static int ft2232_execute_scan(jtag_command_t
*cmd
)
1427 int scan_size
; /* size of IR or DR scan */
1428 enum scan_type type
;
1429 int predicted_size
= 0;
1432 scan_size
= jtag_build_buffer(cmd
->cmd
.scan
, &buffer
);
1433 type
= jtag_scan_type(cmd
->cmd
.scan
);
1434 predicted_size
= ft2232_predict_scan_out(scan_size
, type
);
1435 if ( (predicted_size
+ 1) > FT2232_BUFFER_SIZE
)
1437 LOG_DEBUG("oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
1438 /* unsent commands before this */
1439 if (first_unsent
!= cmd
)
1440 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1441 retval
= ERROR_JTAG_QUEUE_FAILED
;
1443 /* current command */
1444 if (cmd
->cmd
.scan
->end_state
!= TAP_INVALID
)
1445 ft2232_end_state(cmd
->cmd
.scan
->end_state
);
1446 ft2232_large_scan(cmd
->cmd
.scan
, type
, buffer
, scan_size
);
1448 first_unsent
= cmd
->next
;
1453 else if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1455 LOG_DEBUG("ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
1458 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1459 retval
= ERROR_JTAG_QUEUE_FAILED
;
1463 ft2232_expect_read
+= ft2232_predict_scan_in(scan_size
, type
);
1464 /* LOG_DEBUG("new read size: %i", ft2232_expect_read); */
1465 if (cmd
->cmd
.scan
->end_state
!= TAP_INVALID
)
1466 ft2232_end_state(cmd
->cmd
.scan
->end_state
);
1467 ft2232_add_scan(cmd
->cmd
.scan
->ir_scan
, type
, buffer
, scan_size
);
1471 #ifdef _DEBUG_JTAG_IO_
1472 LOG_DEBUG( "%s scan, %i bits, end in %s", (cmd
->cmd
.scan
->ir_scan
) ? "IR" : "DR", scan_size
,
1473 tap_state_name( tap_get_end_state() ) );
1479 static int ft2232_execute_reset(jtag_command_t
*cmd
)
1482 int predicted_size
= 0;
1485 DEBUG_JTAG_IO("reset trst: %i srst %i",
1486 cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1488 /* only send the maximum buffer size that FT2232C can handle */
1490 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1492 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1493 retval
= ERROR_JTAG_QUEUE_FAILED
;
1498 if ( (cmd
->cmd
.reset
->trst
== 1) || ( cmd
->cmd
.reset
->srst
&& (jtag_reset_config
& RESET_SRST_PULLS_TRST
) ) )
1500 tap_set_state(TAP_RESET
);
1502 layout
->reset(cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1505 #ifdef _DEBUG_JTAG_IO_
1506 LOG_DEBUG("trst: %i, srst: %i", cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1511 static int ft2232_execute_sleep(jtag_command_t
*cmd
)
1516 DEBUG_JTAG_IO("sleep %i", cmd
->cmd
.sleep
->us
);
1518 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1519 retval
= ERROR_JTAG_QUEUE_FAILED
;
1520 first_unsent
= cmd
->next
;
1521 jtag_sleep(cmd
->cmd
.sleep
->us
);
1522 #ifdef _DEBUG_JTAG_IO_
1523 LOG_DEBUG( "sleep %i usec while in %s", cmd
->cmd
.sleep
->us
, tap_state_name( tap_get_state() ) );
1529 static int ft2232_execute_stableclocks(jtag_command_t
*cmd
)
1534 /* this is only allowed while in a stable state. A check for a stable
1535 * state was done in jtag_add_clocks()
1537 if (ft2232_stableclocks(cmd
->cmd
.stableclocks
->num_cycles
, cmd
) != ERROR_OK
)
1538 retval
= ERROR_JTAG_QUEUE_FAILED
;
1539 #ifdef _DEBUG_JTAG_IO_
1540 LOG_DEBUG( "clocks %i while in %s", cmd
->cmd
.stableclocks
->num_cycles
, tap_state_name( tap_get_state() ) );
1546 static int ft2232_execute_command(jtag_command_t
*cmd
)
1553 case JTAG_END_STATE
: retval
= ft2232_execute_end_state(cmd
); break;
1554 case JTAG_RESET
: retval
= ft2232_execute_reset(cmd
); break;
1555 case JTAG_RUNTEST
: retval
= ft2232_execute_runtest(cmd
); break;
1556 case JTAG_STATEMOVE
: retval
= ft2232_execute_statemove(cmd
); break;
1557 case JTAG_PATHMOVE
: retval
= ft2232_execute_pathmove(cmd
); break;
1558 case JTAG_SCAN
: retval
= ft2232_execute_scan(cmd
); break;
1559 case JTAG_SLEEP
: retval
= ft2232_execute_sleep(cmd
); break;
1560 case JTAG_STABLECLOCKS
: retval
= ft2232_execute_stableclocks(cmd
); break;
1562 LOG_ERROR("BUG: unknown JTAG command type encountered");
1568 static int ft2232_execute_queue()
1570 jtag_command_t
* cmd
= jtag_command_queue
; /* currently processed command */
1573 first_unsent
= cmd
; /* next command that has to be sent */
1576 /* return ERROR_OK, unless ft2232_send_and_recv reports a failed check
1577 * that wasn't handled by a caller-provided error handler
1581 ft2232_buffer_size
= 0;
1582 ft2232_expect_read
= 0;
1584 /* blink, if the current layout has that feature */
1590 if (ft2232_execute_command(cmd
) != ERROR_OK
)
1591 retval
= ERROR_JTAG_QUEUE_FAILED
;
1595 if (require_send
> 0)
1596 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1597 retval
= ERROR_JTAG_QUEUE_FAILED
;
1603 #if BUILD_FT2232_FTD2XX == 1
1604 static int ft2232_init_ftd2xx(u16 vid
, u16 pid
, int more
, int* try_more
)
1607 DWORD openex_flags
= 0;
1608 char* openex_string
= NULL
;
1611 LOG_DEBUG("'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)", ft2232_layout
, vid
, pid
);
1614 /* Add non-standard Vid/Pid to the linux driver */
1615 if ( ( status
= FT_SetVIDPID(vid
, pid
) ) != FT_OK
)
1617 LOG_WARNING("couldn't add %4.4x:%4.4x", vid
, pid
);
1621 if (ft2232_device_desc
&& ft2232_serial
)
1623 LOG_WARNING("can't open by device description and serial number, giving precedence to serial");
1624 ft2232_device_desc
= NULL
;
1627 if (ft2232_device_desc
)
1629 openex_string
= ft2232_device_desc
;
1630 openex_flags
= FT_OPEN_BY_DESCRIPTION
;
1632 else if (ft2232_serial
)
1634 openex_string
= ft2232_serial
;
1635 openex_flags
= FT_OPEN_BY_SERIAL_NUMBER
;
1639 LOG_ERROR("neither device description nor serial number specified");
1640 LOG_ERROR("please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
1642 return ERROR_JTAG_INIT_FAILED
;
1645 status
= FT_OpenEx(openex_string
, openex_flags
, &ftdih
);
1646 if( status
!= FT_OK
){
1647 // under Win32, the FTD2XX driver appends an "A" to the end
1648 // of the description, if we tried by the desc, then
1649 // try by the alternate "A" description.
1650 if( openex_string
== ft2232_device_desc
){
1651 // Try the alternate method.
1652 openex_string
= ft2232_device_desc_A
;
1653 status
= FT_OpenEx(openex_string
, openex_flags
, &ftdih
);
1654 if( status
== FT_OK
){
1655 // yea, the "alternate" method worked!
1657 // drat, give the user a meaningfull message.
1658 // telling the use we tried *BOTH* methods.
1659 LOG_WARNING("Unable to open FTDI Device tried: '%s' and '%s'\n",
1661 ft2232_device_desc_A
);
1666 if ( status
!= FT_OK
)
1672 LOG_WARNING("unable to open ftdi device (trying more): %lu", status
);
1674 return ERROR_JTAG_INIT_FAILED
;
1676 LOG_ERROR("unable to open ftdi device: %lu", status
);
1677 status
= FT_ListDevices(&num_devices
, NULL
, FT_LIST_NUMBER_ONLY
);
1678 if (status
== FT_OK
)
1680 char** desc_array
= malloc( sizeof(char*) * (num_devices
+ 1) );
1683 for (i
= 0; i
< num_devices
; i
++)
1684 desc_array
[i
] = malloc(64);
1686 desc_array
[num_devices
] = NULL
;
1688 status
= FT_ListDevices(desc_array
, &num_devices
, FT_LIST_ALL
| openex_flags
);
1690 if (status
== FT_OK
)
1692 LOG_ERROR("ListDevices: %lu\n", num_devices
);
1693 for (i
= 0; i
< num_devices
; i
++)
1694 LOG_ERROR("%i: \"%s\"", i
, desc_array
[i
]);
1697 for (i
= 0; i
< num_devices
; i
++)
1698 free(desc_array
[i
]);
1704 LOG_ERROR("ListDevices: NONE\n");
1706 return ERROR_JTAG_INIT_FAILED
;
1709 if ( ( status
= FT_SetLatencyTimer(ftdih
, ft2232_latency
) ) != FT_OK
)
1711 LOG_ERROR("unable to set latency timer: %lu", status
);
1712 return ERROR_JTAG_INIT_FAILED
;
1715 if ( ( status
= FT_GetLatencyTimer(ftdih
, &latency_timer
) ) != FT_OK
)
1717 LOG_ERROR("unable to get latency timer: %lu", status
);
1718 return ERROR_JTAG_INIT_FAILED
;
1722 LOG_DEBUG("current latency timer: %i", latency_timer
);
1725 if ( ( status
= FT_SetTimeouts(ftdih
, 5000, 5000) ) != FT_OK
)
1727 LOG_ERROR("unable to set timeouts: %lu", status
);
1728 return ERROR_JTAG_INIT_FAILED
;
1731 if ( ( status
= FT_SetBitMode(ftdih
, 0x0b, 2) ) != FT_OK
)
1733 LOG_ERROR("unable to enable bit i/o mode: %lu", status
);
1734 return ERROR_JTAG_INIT_FAILED
;
1741 static int ft2232_purge_ftd2xx(void)
1745 if ( ( status
= FT_Purge(ftdih
, FT_PURGE_RX
| FT_PURGE_TX
) ) != FT_OK
)
1747 LOG_ERROR("error purging ftd2xx device: %lu", status
);
1748 return ERROR_JTAG_INIT_FAILED
;
1755 #endif /* BUILD_FT2232_FTD2XX == 1 */
1757 #if BUILD_FT2232_LIBFTDI == 1
1758 static int ft2232_init_libftdi(u16 vid
, u16 pid
, int more
, int* try_more
)
1762 LOG_DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
1763 ft2232_layout
, vid
, pid
);
1765 if (ftdi_init(&ftdic
) < 0)
1766 return ERROR_JTAG_INIT_FAILED
;
1768 /* context, vendor id, product id */
1769 if (ftdi_usb_open_desc(&ftdic
, vid
, pid
, ft2232_device_desc
,
1773 LOG_WARNING("unable to open ftdi device (trying more): %s",
1776 LOG_ERROR("unable to open ftdi device: %s", ftdic
.error_str
);
1778 return ERROR_JTAG_INIT_FAILED
;
1781 if (ftdi_set_interface(&ftdic
, INTERFACE_A
) < 0)
1783 LOG_ERROR("unable to select FT2232 channel A: %s", ftdic
.error_str
);
1784 return ERROR_JTAG_INIT_FAILED
;
1787 if (ftdi_usb_reset(&ftdic
) < 0)
1789 LOG_ERROR("unable to reset ftdi device");
1790 return ERROR_JTAG_INIT_FAILED
;
1793 if (ftdi_set_latency_timer(&ftdic
, ft2232_latency
) < 0)
1795 LOG_ERROR("unable to set latency timer");
1796 return ERROR_JTAG_INIT_FAILED
;
1799 if (ftdi_get_latency_timer(&ftdic
, &latency_timer
) < 0)
1801 LOG_ERROR("unable to get latency timer");
1802 return ERROR_JTAG_INIT_FAILED
;
1806 LOG_DEBUG("current latency timer: %i", latency_timer
);
1809 ftdi_set_bitmode(&ftdic
, 0x0b, 2); /* ctx, JTAG I/O mask */
1815 static int ft2232_purge_libftdi(void)
1817 if (ftdi_usb_purge_buffers(&ftdic
) < 0)
1819 LOG_ERROR("ftdi_purge_buffers: %s", ftdic
.error_str
);
1820 return ERROR_JTAG_INIT_FAILED
;
1827 #endif /* BUILD_FT2232_LIBFTDI == 1 */
1829 static int ft2232_init(void)
1834 ft2232_layout_t
* cur_layout
= ft2232_layouts
;
1837 if ( (ft2232_layout
== NULL
) || (ft2232_layout
[0] == 0) )
1839 ft2232_layout
= "usbjtag";
1840 LOG_WARNING("No ft2232 layout specified, using default 'usbjtag'");
1843 while (cur_layout
->name
)
1845 if (strcmp(cur_layout
->name
, ft2232_layout
) == 0)
1847 layout
= cur_layout
;
1855 LOG_ERROR("No matching layout found for %s", ft2232_layout
);
1856 return ERROR_JTAG_INIT_FAILED
;
1862 * "more indicates that there are more IDs to try, so we should
1863 * not print an error for an ID mismatch (but for anything
1866 * try_more indicates that the error code returned indicates an
1867 * ID mismatch (and nothing else) and that we should proceeed
1868 * with the next ID pair.
1870 int more
= ft2232_vid
[i
+ 1] || ft2232_pid
[i
+ 1];
1873 #if BUILD_FT2232_FTD2XX == 1
1874 retval
= ft2232_init_ftd2xx(ft2232_vid
[i
], ft2232_pid
[i
],
1876 #elif BUILD_FT2232_LIBFTDI == 1
1877 retval
= ft2232_init_libftdi(ft2232_vid
[i
], ft2232_pid
[i
],
1882 if (!more
|| !try_more
)
1886 ft2232_buffer_size
= 0;
1887 ft2232_buffer
= malloc(FT2232_BUFFER_SIZE
);
1889 if (layout
->init() != ERROR_OK
)
1890 return ERROR_JTAG_INIT_FAILED
;
1892 ft2232_speed(jtag_speed
);
1894 buf
[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
1895 if ( ( ( retval
= ft2232_write(buf
, 1, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 1) )
1897 LOG_ERROR("couldn't write to FT2232 to disable loopback");
1898 return ERROR_JTAG_INIT_FAILED
;
1901 #if BUILD_FT2232_FTD2XX == 1
1902 return ft2232_purge_ftd2xx();
1903 #elif BUILD_FT2232_LIBFTDI == 1
1904 return ft2232_purge_libftdi();
1911 static int usbjtag_init(void)
1917 low_direction
= 0x0b;
1919 if (strcmp(ft2232_layout
, "usbjtag") == 0)
1926 else if (strcmp(ft2232_layout
, "signalyzer") == 0)
1933 else if (strcmp(ft2232_layout
, "evb_lm3s811") == 0)
1940 low_direction
= 0x8b;
1944 LOG_ERROR("BUG: usbjtag_init called for unknown layout '%s'", ft2232_layout
);
1945 return ERROR_JTAG_INIT_FAILED
;
1948 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1950 low_direction
&= ~nTRSTnOE
; /* nTRST input */
1951 low_output
&= ~nTRST
; /* nTRST = 0 */
1955 low_direction
|= nTRSTnOE
; /* nTRST output */
1956 low_output
|= nTRST
; /* nTRST = 1 */
1959 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1961 low_direction
|= nSRSTnOE
; /* nSRST output */
1962 low_output
|= nSRST
; /* nSRST = 1 */
1966 low_direction
&= ~nSRSTnOE
; /* nSRST input */
1967 low_output
&= ~nSRST
; /* nSRST = 0 */
1970 /* initialize low byte for jtag */
1971 buf
[0] = 0x80; /* command "set data bits low byte" */
1972 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, xRST high) */
1973 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
1974 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1976 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1978 LOG_ERROR("couldn't initialize FT2232 with 'USBJTAG' layout");
1979 return ERROR_JTAG_INIT_FAILED
;
1986 static int axm0432_jtag_init(void)
1992 low_direction
= 0x2b;
1994 /* initialize low byte for jtag */
1995 buf
[0] = 0x80; /* command "set data bits low byte" */
1996 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1997 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1998 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2000 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2002 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2003 return ERROR_JTAG_INIT_FAILED
;
2006 if (strcmp(layout
->name
, "axm0432_jtag") == 0)
2009 nTRSTnOE
= 0x0; /* No output enable for TRST*/
2011 nSRSTnOE
= 0x0; /* No output enable for SRST*/
2015 LOG_ERROR("BUG: axm0432_jtag_init called for non axm0432 layout");
2020 high_direction
= 0x0c;
2022 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2024 LOG_ERROR("can't set nTRSTOE to push-pull on the Dicarlo jtag");
2028 high_output
|= nTRST
;
2031 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2033 LOG_ERROR("can't set nSRST to push-pull on the Dicarlo jtag");
2037 high_output
|= nSRST
;
2040 /* initialize high port */
2041 buf
[0] = 0x82; /* command "set data bits high byte" */
2042 buf
[1] = high_output
; /* value */
2043 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2044 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2046 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2048 LOG_ERROR("couldn't initialize FT2232 with 'Dicarlo' layout");
2049 return ERROR_JTAG_INIT_FAILED
;
2056 static int jtagkey_init(void)
2062 low_direction
= 0x1b;
2064 /* initialize low byte for jtag */
2065 buf
[0] = 0x80; /* command "set data bits low byte" */
2066 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2067 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2068 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2070 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2072 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2073 return ERROR_JTAG_INIT_FAILED
;
2076 if (strcmp(layout
->name
, "jtagkey") == 0)
2083 else if ( (strcmp(layout
->name
, "jtagkey_prototype_v1") == 0)
2084 || (strcmp(layout
->name
, "oocdlink") == 0) )
2093 LOG_ERROR("BUG: jtagkey_init called for non jtagkey layout");
2098 high_direction
= 0x0f;
2100 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2102 high_output
|= nTRSTnOE
;
2103 high_output
&= ~nTRST
;
2107 high_output
&= ~nTRSTnOE
;
2108 high_output
|= nTRST
;
2111 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2113 high_output
&= ~nSRSTnOE
;
2114 high_output
|= nSRST
;
2118 high_output
|= nSRSTnOE
;
2119 high_output
&= ~nSRST
;
2122 /* initialize high port */
2123 buf
[0] = 0x82; /* command "set data bits high byte" */
2124 buf
[1] = high_output
; /* value */
2125 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2126 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2128 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2130 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2131 return ERROR_JTAG_INIT_FAILED
;
2138 static int olimex_jtag_init(void)
2144 low_direction
= 0x1b;
2146 /* initialize low byte for jtag */
2147 buf
[0] = 0x80; /* command "set data bits low byte" */
2148 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2149 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2150 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2152 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2154 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2155 return ERROR_JTAG_INIT_FAILED
;
2161 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2164 high_direction
= 0x0f;
2166 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2168 high_output
|= nTRSTnOE
;
2169 high_output
&= ~nTRST
;
2173 high_output
&= ~nTRSTnOE
;
2174 high_output
|= nTRST
;
2177 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2179 LOG_ERROR("can't set nSRST to push-pull on the Olimex ARM-USB-OCD");
2183 high_output
&= ~nSRST
;
2186 /* turn red LED on */
2187 high_output
|= 0x08;
2189 /* initialize high port */
2190 buf
[0] = 0x82; /* command "set data bits high byte" */
2191 buf
[1] = high_output
; /* value */
2192 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2193 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2195 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2197 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2198 return ERROR_JTAG_INIT_FAILED
;
2205 static int flyswatter_init(void)
2211 low_direction
= 0xfb;
2213 /* initialize low byte for jtag */
2214 buf
[0] = 0x80; /* command "set data bits low byte" */
2215 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2216 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE[12]=out, n[ST]srst=out */
2217 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2219 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2221 LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
2222 return ERROR_JTAG_INIT_FAILED
;
2226 nTRSTnOE
= 0x0; /* not output enable for nTRST */
2228 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2231 high_direction
= 0x0c;
2233 /* turn red LED3 on, LED2 off */
2234 high_output
|= 0x08;
2236 /* initialize high port */
2237 buf
[0] = 0x82; /* command "set data bits high byte" */
2238 buf
[1] = high_output
; /* value */
2239 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2240 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2242 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2244 LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
2245 return ERROR_JTAG_INIT_FAILED
;
2252 static int turtle_init(void)
2258 low_direction
= 0x5b;
2260 /* initialize low byte for jtag */
2261 buf
[0] = 0x80; /* command "set data bits low byte" */
2262 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2263 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2264 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2266 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2268 LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
2269 return ERROR_JTAG_INIT_FAILED
;
2275 high_direction
= 0x0C;
2277 /* initialize high port */
2278 buf
[0] = 0x82; /* command "set data bits high byte" */
2279 buf
[1] = high_output
;
2280 buf
[2] = high_direction
;
2281 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2283 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2285 LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
2286 return ERROR_JTAG_INIT_FAILED
;
2293 static int comstick_init(void)
2299 low_direction
= 0x0b;
2301 /* initialize low byte for jtag */
2302 buf
[0] = 0x80; /* command "set data bits low byte" */
2303 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2304 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2305 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2307 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2309 LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
2310 return ERROR_JTAG_INIT_FAILED
;
2314 nTRSTnOE
= 0x00; /* no output enable for nTRST */
2316 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2319 high_direction
= 0x03;
2321 /* initialize high port */
2322 buf
[0] = 0x82; /* command "set data bits high byte" */
2323 buf
[1] = high_output
;
2324 buf
[2] = high_direction
;
2325 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2327 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2329 LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
2330 return ERROR_JTAG_INIT_FAILED
;
2337 static int stm32stick_init(void)
2343 low_direction
= 0x8b;
2345 /* initialize low byte for jtag */
2346 buf
[0] = 0x80; /* command "set data bits low byte" */
2347 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2348 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2349 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2351 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2353 LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
2354 return ERROR_JTAG_INIT_FAILED
;
2358 nTRSTnOE
= 0x00; /* no output enable for nTRST */
2360 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2363 high_direction
= 0x03;
2365 /* initialize high port */
2366 buf
[0] = 0x82; /* command "set data bits high byte" */
2367 buf
[1] = high_output
;
2368 buf
[2] = high_direction
;
2369 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2371 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2373 LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
2374 return ERROR_JTAG_INIT_FAILED
;
2381 static int sheevaplug_init(void)
2387 low_direction
= 0x1b;
2389 /* initialize low byte for jtag */
2390 buf
[0] = 0x80; /* command "set data bits low byte" */
2391 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2392 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
2393 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2395 if (((ft2232_write(buf
, 3, &bytes_written
)) != ERROR_OK
) || (bytes_written
!= 3))
2397 LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
2398 return ERROR_JTAG_INIT_FAILED
;
2407 high_direction
= 0x0f;
2409 /* nTRST is always push-pull */
2410 high_output
&= ~nTRSTnOE
;
2411 high_output
|= nTRST
;
2413 /* nSRST is always open-drain */
2414 high_output
|= nSRSTnOE
;
2415 high_output
&= ~nSRST
;
2417 /* initialize high port */
2418 buf
[0] = 0x82; /* command "set data bits high byte" */
2419 buf
[1] = high_output
; /* value */
2420 buf
[2] = high_direction
; /* all outputs - xRST */
2421 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2423 if (((ft2232_write(buf
, 3, &bytes_written
)) != ERROR_OK
) || (bytes_written
!= 3))
2425 LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
2426 return ERROR_JTAG_INIT_FAILED
;
2432 static void olimex_jtag_blink(void)
2434 /* Olimex ARM-USB-OCD has a LED connected to ACBUS3
2435 * ACBUS3 is bit 3 of the GPIOH port
2437 if (high_output
& 0x08)
2439 /* set port pin high */
2440 high_output
&= 0x07;
2444 /* set port pin low */
2445 high_output
|= 0x08;
2449 BUFFER_ADD
= high_output
;
2450 BUFFER_ADD
= high_direction
;
2454 static void flyswatter_jtag_blink(void)
2457 * Flyswatter has two LEDs connected to ACBUS2 and ACBUS3
2459 high_output
^= 0x0c;
2462 BUFFER_ADD
= high_output
;
2463 BUFFER_ADD
= high_direction
;
2467 static void turtle_jtag_blink(void)
2470 * Turtelizer2 has two LEDs connected to ACBUS2 and ACBUS3
2472 if (high_output
& 0x08)
2482 BUFFER_ADD
= high_output
;
2483 BUFFER_ADD
= high_direction
;
2487 static int ft2232_quit(void)
2489 #if BUILD_FT2232_FTD2XX == 1
2492 status
= FT_Close(ftdih
);
2493 #elif BUILD_FT2232_LIBFTDI == 1
2494 ftdi_disable_bitbang(&ftdic
);
2496 ftdi_usb_close(&ftdic
);
2498 ftdi_deinit(&ftdic
);
2501 free(ft2232_buffer
);
2502 ft2232_buffer
= NULL
;
2508 static int ft2232_handle_device_desc_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2514 ft2232_device_desc
= strdup(args
[0]);
2515 cp
= strchr( ft2232_device_desc
, 0 );
2516 // under Win32, the FTD2XX driver appends an "A" to the end
2517 // of the description, this examines the given desc
2518 // and creates the 'missing' _A or non_A variable.
2519 if( (cp
[-1] == 'A') && (cp
[-2]==' ') ){
2520 // it was, so make this the "A" version.
2521 ft2232_device_desc_A
= ft2232_device_desc
;
2522 // and *CREATE* the non-A version.
2523 strcpy( buf
, ft2232_device_desc
);
2524 cp
= strchr( buf
, 0 );
2526 ft2232_device_desc
= strdup( buf
);
2528 // <space>A not defined
2530 sprintf( buf
, "%s A", ft2232_device_desc
);
2531 ft2232_device_desc_A
= strdup( buf
);
2536 LOG_ERROR("expected exactly one argument to ft2232_device_desc <description>");
2543 static int ft2232_handle_serial_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2547 ft2232_serial
= strdup(args
[0]);
2551 LOG_ERROR("expected exactly one argument to ft2232_serial <serial-number>");
2558 static int ft2232_handle_layout_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2563 ft2232_layout
= malloc(strlen(args
[0]) + 1);
2564 strcpy(ft2232_layout
, args
[0]);
2570 static int ft2232_handle_vid_pid_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2574 if (argc
> MAX_USB_IDS
* 2)
2576 LOG_WARNING("ignoring extra IDs in ft2232_vid_pid "
2577 "(maximum is %d pairs)", MAX_USB_IDS
);
2578 argc
= MAX_USB_IDS
* 2;
2580 if ( argc
< 2 || (argc
& 1) )
2582 LOG_WARNING("incomplete ft2232_vid_pid configuration directive");
2587 for (i
= 0; i
+ 1 < argc
; i
+= 2)
2589 ft2232_vid
[i
>> 1] = strtol(args
[i
], NULL
, 0);
2590 ft2232_pid
[i
>> 1] = strtol(args
[i
+ 1], NULL
, 0);
2594 * Explicitly terminate, in case there are multiples instances of
2597 ft2232_vid
[i
>> 1] = ft2232_pid
[i
>> 1] = 0;
2603 static int ft2232_handle_latency_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2607 ft2232_latency
= atoi(args
[0]);
2611 LOG_ERROR("expected exactly one argument to ft2232_latency <ms>");
2618 static int ft2232_stableclocks(int num_cycles
, jtag_command_t
* cmd
)
2622 /* 7 bits of either ones or zeros. */
2623 u8 tms
= (tap_get_state() == TAP_RESET
? 0x7F : 0x00);
2625 while (num_cycles
> 0)
2627 /* the command 0x4b, "Clock Data to TMS/CS Pin (no Read)" handles
2628 * at most 7 bits per invocation. Here we invoke it potentially
2631 int bitcount_per_command
= (num_cycles
> 7) ? 7 : num_cycles
;
2633 if (ft2232_buffer_size
+ 3 >= FT2232_BUFFER_SIZE
)
2635 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
2636 retval
= ERROR_JTAG_QUEUE_FAILED
;
2641 /* command "Clock Data to TMS/CS Pin (no Read)" */
2645 BUFFER_ADD
= bitcount_per_command
- 1;
2647 /* TMS data bits are either all zeros or ones to stay in the current stable state */
2652 num_cycles
-= bitcount_per_command
;
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)