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 /* enable this to debug io latency
64 #define _DEBUG_USB_IO_
67 /* enable this to debug communication
70 #define _DEBUG_USB_COMMS_
73 int ft2232_execute_queue(void);
75 int ft2232_speed(int speed
);
76 int ft2232_speed_div(int speed
, int* khz
);
77 int ft2232_khz(int khz
, int* jtag_speed
);
78 int ft2232_register_commands(struct command_context_s
* cmd_ctx
);
79 int ft2232_init(void);
80 int ft2232_quit(void);
82 int ft2232_handle_device_desc_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
83 int ft2232_handle_serial_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
84 int ft2232_handle_layout_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
85 int ft2232_handle_vid_pid_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
86 int ft2232_handle_latency_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
);
90 * Function ft2232_stableclocks
91 * will send out \a num_cycles on the TCK line while the TAP(s)
92 * are in a stable state. Calling code must ensure that current state is
93 * stable, that verification is not done in here.
94 * @param num_cycles is the count of clocks cycles to send.
95 * @return int - ERROR_OK or ERROR_JTAG_QUEUE_FAILED
97 static int ft2232_stableclocks(int num_cycles
, jtag_command_t
* cmd
);
100 char* ft2232_device_desc
= NULL
;
101 char* ft2232_serial
= NULL
;
102 char* ft2232_layout
= NULL
;
103 unsigned char ft2232_latency
= 2;
105 #define MAX_USB_IDS 8
106 /* vid = pid = 0 marks the end of the list */
107 static u16 ft2232_vid
[MAX_USB_IDS
+ 1] = { 0x0403, 0 };
108 static u16 ft2232_pid
[MAX_USB_IDS
+ 1] = { 0x6010, 0 };
110 typedef struct ft2232_layout_s
114 void (*reset
)(int trst
, int srst
);
118 /* init procedures for supported layouts */
119 int usbjtag_init(void);
120 int jtagkey_init(void);
121 int olimex_jtag_init(void);
122 int flyswatter_init(void);
123 int turtle_init(void);
124 int comstick_init(void);
125 int stm32stick_init(void);
126 int axm0432_jtag_init(void);
127 int sheevaplug_init(void);
129 /* reset procedures for supported layouts */
130 void usbjtag_reset(int trst
, int srst
);
131 void jtagkey_reset(int trst
, int srst
);
132 void olimex_jtag_reset(int trst
, int srst
);
133 void flyswatter_reset(int trst
, int srst
);
134 void turtle_reset(int trst
, int srst
);
135 void comstick_reset(int trst
, int srst
);
136 void stm32stick_reset(int trst
, int srst
);
137 void axm0432_jtag_reset(int trst
, int srst
);
138 void sheevaplug_reset(int trst
, int srst
);
140 /* blink procedures for layouts that support a blinking led */
141 void olimex_jtag_blink(void);
142 void turtle_jtag_blink(void);
144 ft2232_layout_t ft2232_layouts
[] =
146 { "usbjtag", usbjtag_init
, usbjtag_reset
, NULL
},
147 { "jtagkey", jtagkey_init
, jtagkey_reset
, NULL
},
148 { "jtagkey_prototype_v1", jtagkey_init
, jtagkey_reset
, NULL
},
149 { "oocdlink", jtagkey_init
, jtagkey_reset
, NULL
},
150 { "signalyzer", usbjtag_init
, usbjtag_reset
, NULL
},
151 { "evb_lm3s811", usbjtag_init
, usbjtag_reset
, NULL
},
152 { "olimex-jtag", olimex_jtag_init
, olimex_jtag_reset
, olimex_jtag_blink
},
153 { "flyswatter", flyswatter_init
, flyswatter_reset
, NULL
},
154 { "turtelizer2", turtle_init
, turtle_reset
, turtle_jtag_blink
},
155 { "comstick", comstick_init
, comstick_reset
, NULL
},
156 { "stm32stick", stm32stick_init
, stm32stick_reset
, NULL
},
157 { "axm0432_jtag", axm0432_jtag_init
, axm0432_jtag_reset
, NULL
},
158 {"sheevaplug", sheevaplug_init
, sheevaplug_reset
, NULL
},
159 { NULL
, NULL
, NULL
},
162 static u8 nTRST
, nTRSTnOE
, nSRST
, nSRSTnOE
;
164 static ft2232_layout_t
* layout
;
165 static u8 low_output
= 0x0;
166 static u8 low_direction
= 0x0;
167 static u8 high_output
= 0x0;
168 static u8 high_direction
= 0x0;
170 #if BUILD_FT2232_FTD2XX == 1
171 static FT_HANDLE ftdih
= NULL
;
172 #elif BUILD_FT2232_LIBFTDI == 1
173 static struct ftdi_context ftdic
;
177 static jtag_command_t
* first_unsent
; /* next command that has to be sent */
178 static int require_send
;
180 static u8
* ft2232_buffer
= NULL
;
181 static int ft2232_buffer_size
= 0;
182 static int ft2232_read_pointer
= 0;
183 static int ft2232_expect_read
= 0;
185 #define FT2232_BUFFER_SIZE 131072
186 #define BUFFER_ADD ft2232_buffer[ft2232_buffer_size++]
187 #define BUFFER_READ ft2232_buffer[ft2232_read_pointer++]
189 jtag_interface_t ft2232_interface
=
192 .execute_queue
= ft2232_execute_queue
,
193 .speed
= ft2232_speed
,
194 .speed_div
= ft2232_speed_div
,
196 .register_commands
= ft2232_register_commands
,
201 int ft2232_write(u8
* buf
, int size
, u32
* bytes_written
)
203 #if BUILD_FT2232_FTD2XX == 1
205 DWORD dw_bytes_written
;
206 if ( ( status
= FT_Write(ftdih
, buf
, size
, &dw_bytes_written
) ) != FT_OK
)
208 *bytes_written
= dw_bytes_written
;
209 LOG_ERROR("FT_Write returned: %lu", status
);
210 return ERROR_JTAG_DEVICE_ERROR
;
214 *bytes_written
= dw_bytes_written
;
217 #elif BUILD_FT2232_LIBFTDI == 1
219 if ( ( retval
= ftdi_write_data(&ftdic
, buf
, size
) ) < 0 )
222 LOG_ERROR( "ftdi_write_data: %s", ftdi_get_error_string(&ftdic
) );
223 return ERROR_JTAG_DEVICE_ERROR
;
227 *bytes_written
= retval
;
234 int ft2232_read(u8
* buf
, int size
, u32
* bytes_read
)
236 #if BUILD_FT2232_FTD2XX == 1
242 while ( (*bytes_read
< size
) && timeout
-- )
244 if ( ( status
= FT_Read(ftdih
, buf
+ *bytes_read
, size
-
245 *bytes_read
, &dw_bytes_read
) ) != FT_OK
)
248 LOG_ERROR("FT_Read returned: %lu", status
);
249 return ERROR_JTAG_DEVICE_ERROR
;
251 *bytes_read
+= dw_bytes_read
;
254 #elif BUILD_FT2232_LIBFTDI == 1
259 while ( (*bytes_read
< size
) && timeout
-- )
261 if ( ( retval
= ftdi_read_data(&ftdic
, buf
+ *bytes_read
, size
- *bytes_read
) ) < 0 )
264 LOG_ERROR( "ftdi_read_data: %s", ftdi_get_error_string(&ftdic
) );
265 return ERROR_JTAG_DEVICE_ERROR
;
267 *bytes_read
+= retval
;
272 if (*bytes_read
< size
)
274 LOG_ERROR("couldn't read the requested number of bytes from FT2232 device (%i < %i)", *bytes_read
, size
);
275 return ERROR_JTAG_DEVICE_ERROR
;
282 int ft2232_speed(int speed
)
288 buf
[0] = 0x86; /* command "set divisor" */
289 buf
[1] = speed
& 0xff; /* valueL (0=6MHz, 1=3MHz, 2=2.0MHz, ...*/
290 buf
[2] = (speed
>> 8) & 0xff; /* valueH */
292 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
293 if ( ( ( retval
= ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
295 LOG_ERROR("couldn't set FT2232 TCK speed");
303 int ft2232_speed_div(int speed
, int* khz
)
305 /* Take a look in the FT2232 manual,
306 * AN2232C-01 Command Processor for
307 * MPSSE and MCU Host Bus. Chapter 3.8 */
309 *khz
= 6000 / (1 + speed
);
315 int ft2232_khz(int khz
, int* jtag_speed
)
319 LOG_ERROR("RCLK not supported");
323 /* Take a look in the FT2232 manual,
324 * AN2232C-01 Command Processor for
325 * MPSSE and MCU Host Bus. Chapter 3.8
327 * We will calc here with a multiplier
328 * of 10 for better rounding later. */
330 /* Calc speed, (6000 / khz) - 1 */
331 /* Use 65000 for better rounding */
332 *jtag_speed
= (60000 / khz
) - 10;
334 /* Add 0.9 for rounding */
337 /* Calc real speed */
338 *jtag_speed
= *jtag_speed
/ 10;
340 /* Check if speed is greater than 0 */
346 /* Check max value */
347 if (*jtag_speed
> 0xFFFF)
349 *jtag_speed
= 0xFFFF;
356 int ft2232_register_commands(struct command_context_s
* cmd_ctx
)
358 register_command(cmd_ctx
, NULL
, "ft2232_device_desc", ft2232_handle_device_desc_command
,
359 COMMAND_CONFIG
, "the USB device description of the FTDI FT2232 device");
360 register_command(cmd_ctx
, NULL
, "ft2232_serial", ft2232_handle_serial_command
,
361 COMMAND_CONFIG
, "the serial number of the FTDI FT2232 device");
362 register_command(cmd_ctx
, NULL
, "ft2232_layout", ft2232_handle_layout_command
,
363 COMMAND_CONFIG
, "the layout of the FT2232 GPIO signals used to control output-enables and reset signals");
364 register_command(cmd_ctx
, NULL
, "ft2232_vid_pid", ft2232_handle_vid_pid_command
,
365 COMMAND_CONFIG
, "the vendor ID and product ID of the FTDI FT2232 device");
366 register_command(cmd_ctx
, NULL
, "ft2232_latency", ft2232_handle_latency_command
,
367 COMMAND_CONFIG
, "set the FT2232 latency timer to a new value");
372 void ft2232_end_state(tap_state_t state
)
374 if (tap_is_state_stable(state
))
375 tap_set_end_state(state
);
378 LOG_ERROR("BUG: %i is not a valid end state", state
);
384 void ft2232_read_scan(enum scan_type type
, u8
* buffer
, int scan_size
)
386 int num_bytes
= (scan_size
+ 7) / 8;
387 int bits_left
= scan_size
;
390 while (num_bytes
-- > 1)
392 buffer
[cur_byte
] = BUFFER_READ
;
397 buffer
[cur_byte
] = 0x0;
401 buffer
[cur_byte
] = BUFFER_READ
>> 1;
404 buffer
[cur_byte
] = ( buffer
[cur_byte
] | ( (BUFFER_READ
& 0x02) << 6 ) ) >> (8 - bits_left
);
408 void ft2232_debug_dump_buffer(void)
414 for (i
= 0; i
< ft2232_buffer_size
; i
++)
416 line_p
+= snprintf(line_p
, 256 - (line_p
- line
), "%2.2x ", ft2232_buffer
[i
]);
419 LOG_DEBUG("%s", line
);
425 LOG_DEBUG("%s", line
);
429 int ft2232_send_and_recv(jtag_command_t
* first
, jtag_command_t
* last
)
439 #ifdef _DEBUG_USB_IO_
440 struct timeval start
, inter
, inter2
, end
;
441 struct timeval d_inter
, d_inter2
, d_end
;
444 #ifdef _DEBUG_USB_COMMS_
445 LOG_DEBUG("write buffer (size %i):", ft2232_buffer_size
);
446 ft2232_debug_dump_buffer();
449 #ifdef _DEBUG_USB_IO_
450 gettimeofday(&start
, NULL
);
453 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
455 LOG_ERROR("couldn't write MPSSE commands to FT2232");
459 #ifdef _DEBUG_USB_IO_
460 gettimeofday(&inter
, NULL
);
463 if (ft2232_expect_read
)
466 ft2232_buffer_size
= 0;
468 #ifdef _DEBUG_USB_IO_
469 gettimeofday(&inter2
, NULL
);
472 if ( ( retval
= ft2232_read(ft2232_buffer
, ft2232_expect_read
, &bytes_read
) ) != ERROR_OK
)
474 LOG_ERROR("couldn't read from FT2232");
478 #ifdef _DEBUG_USB_IO_
479 gettimeofday(&end
, NULL
);
481 timeval_subtract(&d_inter
, &inter
, &start
);
482 timeval_subtract(&d_inter2
, &inter2
, &start
);
483 timeval_subtract(&d_end
, &end
, &start
);
485 LOG_INFO("inter: %i.%06i, inter2: %i.%06i end: %i.%06i", d_inter
.tv_sec
, d_inter
.tv_usec
, d_inter2
.tv_sec
,
486 d_inter2
.tv_usec
, d_end
.tv_sec
,
490 ft2232_buffer_size
= bytes_read
;
492 if (ft2232_expect_read
!= ft2232_buffer_size
)
494 LOG_ERROR("ft2232_expect_read (%i) != ft2232_buffer_size (%i) (%i retries)", ft2232_expect_read
,
497 ft2232_debug_dump_buffer();
502 #ifdef _DEBUG_USB_COMMS_
503 LOG_DEBUG("read buffer (%i retries): %i bytes", 100 - timeout
, ft2232_buffer_size
);
504 ft2232_debug_dump_buffer();
508 ft2232_expect_read
= 0;
509 ft2232_read_pointer
= 0;
511 /* return ERROR_OK, unless a jtag_read_buffer returns a failed check
512 * that wasn't handled by a caller-provided error handler
522 type
= jtag_scan_type(cmd
->cmd
.scan
);
523 if (type
!= SCAN_OUT
)
525 scan_size
= jtag_scan_size(cmd
->cmd
.scan
);
526 buffer
= calloc(CEIL(scan_size
, 8), 1);
527 ft2232_read_scan(type
, buffer
, scan_size
);
528 if (jtag_read_buffer(buffer
, cmd
->cmd
.scan
) != ERROR_OK
)
529 retval
= ERROR_JTAG_QUEUE_FAILED
;
541 ft2232_buffer_size
= 0;
547 void ft2232_add_pathmove(pathmove_command_t
* cmd
)
549 int num_states
= cmd
->num_states
;
554 u8 tms_byte
= 0; /* zero this on each MPSSE batch */
558 int num_states_batch
= num_states
> 7 ? 7 : num_states
;
560 /* command "Clock Data to TMS/CS Pin (no Read)" */
563 /* number of states remaining */
564 BUFFER_ADD
= num_states_batch
- 1;
566 while (num_states_batch
--)
568 if (tap_state_transition(tap_get_state(), false) == cmd
->path
[state_count
])
569 buf_set_u32(&tms_byte
, bit_count
++, 1, 0x0);
570 else if (tap_state_transition(tap_get_state(), true) == cmd
->path
[state_count
])
571 buf_set_u32(&tms_byte
, bit_count
++, 1, 0x1);
574 LOG_ERROR( "BUG: %s -> %s isn't a valid TAP transition", tap_state_name(
575 tap_get_state() ), tap_state_name(cmd
->path
[state_count
]) );
579 tap_set_state(cmd
->path
[state_count
]);
584 BUFFER_ADD
= tms_byte
;
587 tap_set_end_state(tap_get_state());
591 void ft2232_add_scan(int ir_scan
, enum scan_type type
, u8
* buffer
, int scan_size
)
593 int num_bytes
= (scan_size
+ 7) / 8;
594 int bits_left
= scan_size
;
598 if ( !( ( !ir_scan
&& (tap_get_state() == TAP_DRSHIFT
) )
599 || ( ir_scan
&& (tap_get_state() == TAP_IRSHIFT
) ) ) )
601 /* command "Clock Data to TMS/CS Pin (no Read)" */
604 BUFFER_ADD
= 0x6; /* scan 7 bits */
609 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_IRSHIFT
);
610 tap_set_state(TAP_IRSHIFT
);
614 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_DRSHIFT
);
615 tap_set_state(TAP_DRSHIFT
);
617 /* LOG_DEBUG("added TMS scan (no read)"); */
620 /* add command for complete bytes */
621 while (num_bytes
> 1)
626 /* Clock Data Bytes In and Out LSB First */
628 /* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
630 else if (type
== SCAN_OUT
)
632 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
634 /* LOG_DEBUG("added TDI bytes (o)"); */
636 else if (type
== SCAN_IN
)
638 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
640 /* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
643 thisrun_bytes
= (num_bytes
> 65537) ? 65536 : (num_bytes
- 1);
644 num_bytes
-= thisrun_bytes
;
645 BUFFER_ADD
= (thisrun_bytes
- 1) & 0xff;
646 BUFFER_ADD
= ( (thisrun_bytes
- 1) >> 8 ) & 0xff;
650 /* add complete bytes */
651 while (thisrun_bytes
-- > 0)
653 BUFFER_ADD
= buffer
[cur_byte
];
658 else /* (type == SCAN_IN) */
660 bits_left
-= 8 * (thisrun_bytes
);
664 /* the most signifcant bit is scanned during TAP movement */
666 last_bit
= ( buffer
[cur_byte
] >> (bits_left
- 1) ) & 0x1;
670 /* process remaining bits but the last one */
675 /* Clock Data Bits In and Out LSB First */
677 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
679 else if (type
== SCAN_OUT
)
681 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
683 /* LOG_DEBUG("added TDI bits (o)"); */
685 else if (type
== SCAN_IN
)
687 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
689 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
691 BUFFER_ADD
= bits_left
- 2;
693 BUFFER_ADD
= buffer
[cur_byte
];
696 if ( ( ir_scan
&& (tap_get_end_state() == TAP_IRSHIFT
) )
697 || ( !ir_scan
&& (tap_get_end_state() == TAP_DRSHIFT
) ) )
701 /* Clock Data Bits In and Out LSB First */
703 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
705 else if (type
== SCAN_OUT
)
707 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
709 /* LOG_DEBUG("added TDI bits (o)"); */
711 else if (type
== SCAN_IN
)
713 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
715 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
718 BUFFER_ADD
= last_bit
;
722 /* move from Shift-IR/DR to end state */
723 if (type
!= SCAN_OUT
)
725 /* Clock Data to TMS/CS Pin with Read */
727 /* LOG_DEBUG("added TMS scan (read)"); */
731 /* Clock Data to TMS/CS Pin (no Read) */
733 /* LOG_DEBUG("added TMS scan (no read)"); */
735 BUFFER_ADD
= 0x6; /* scan 7 bits */
737 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() ) | (last_bit
<< 7);
738 tap_set_state( tap_get_end_state() );
743 int ft2232_large_scan(scan_command_t
* cmd
, enum scan_type type
, u8
* buffer
, int scan_size
)
745 int num_bytes
= (scan_size
+ 7) / 8;
746 int bits_left
= scan_size
;
749 u8
* receive_buffer
= malloc( CEIL(scan_size
, 8) );
750 u8
* receive_pointer
= receive_buffer
;
754 int thisrun_read
= 0;
758 LOG_ERROR("BUG: large IR scans are not supported");
762 if (tap_get_state() != TAP_DRSHIFT
)
764 /* command "Clock Data to TMS/CS Pin (no Read)" */
767 BUFFER_ADD
= 0x6; /* scan 7 bits */
770 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_DRSHIFT
);
771 tap_set_state(TAP_DRSHIFT
);
774 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
776 LOG_ERROR("couldn't write MPSSE commands to FT2232");
779 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
780 ft2232_buffer_size
= 0;
782 /* add command for complete bytes */
783 while (num_bytes
> 1)
789 /* Clock Data Bytes In and Out LSB First */
791 /* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
793 else if (type
== SCAN_OUT
)
795 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
797 /* LOG_DEBUG("added TDI bytes (o)"); */
799 else if (type
== SCAN_IN
)
801 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
803 /* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
806 thisrun_bytes
= (num_bytes
> 65537) ? 65536 : (num_bytes
- 1);
807 thisrun_read
= thisrun_bytes
;
808 num_bytes
-= thisrun_bytes
;
809 BUFFER_ADD
= (thisrun_bytes
- 1) & 0xff;
810 BUFFER_ADD
= ( (thisrun_bytes
- 1) >> 8 ) & 0xff;
814 /* add complete bytes */
815 while (thisrun_bytes
-- > 0)
817 BUFFER_ADD
= buffer
[cur_byte
];
822 else /* (type == SCAN_IN) */
824 bits_left
-= 8 * (thisrun_bytes
);
827 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
829 LOG_ERROR("couldn't write MPSSE commands to FT2232");
832 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
833 ft2232_buffer_size
= 0;
835 if (type
!= SCAN_OUT
)
837 if ( ( retval
= ft2232_read(receive_pointer
, thisrun_read
, &bytes_read
) ) != ERROR_OK
)
839 LOG_ERROR("couldn't read from FT2232");
842 LOG_DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read
, bytes_read
);
843 receive_pointer
+= bytes_read
;
849 /* the most signifcant bit is scanned during TAP movement */
851 last_bit
= ( buffer
[cur_byte
] >> (bits_left
- 1) ) & 0x1;
855 /* process remaining bits but the last one */
860 /* Clock Data Bits In and Out LSB First */
862 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
864 else if (type
== SCAN_OUT
)
866 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
868 /* LOG_DEBUG("added TDI bits (o)"); */
870 else if (type
== SCAN_IN
)
872 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
874 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
876 BUFFER_ADD
= bits_left
- 2;
878 BUFFER_ADD
= buffer
[cur_byte
];
880 if (type
!= SCAN_OUT
)
884 if (tap_get_end_state() == TAP_DRSHIFT
)
888 /* Clock Data Bits In and Out LSB First */
890 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
892 else if (type
== SCAN_OUT
)
894 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
896 /* LOG_DEBUG("added TDI bits (o)"); */
898 else if (type
== SCAN_IN
)
900 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
902 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
905 BUFFER_ADD
= last_bit
;
909 /* move from Shift-IR/DR to end state */
910 if (type
!= SCAN_OUT
)
912 /* Clock Data to TMS/CS Pin with Read */
914 /* LOG_DEBUG("added TMS scan (read)"); */
918 /* Clock Data to TMS/CS Pin (no Read) */
920 /* LOG_DEBUG("added TMS scan (no read)"); */
923 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() ) | (last_bit
<< 7);
924 tap_set_state( tap_get_end_state() );
927 if (type
!= SCAN_OUT
)
930 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
932 LOG_ERROR("couldn't write MPSSE commands to FT2232");
935 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
936 ft2232_buffer_size
= 0;
938 if (type
!= SCAN_OUT
)
940 if ( ( retval
= ft2232_read(receive_pointer
, thisrun_read
, &bytes_read
) ) != ERROR_OK
)
942 LOG_ERROR("couldn't read from FT2232");
945 LOG_DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read
, bytes_read
);
946 receive_pointer
+= bytes_read
;
953 int ft2232_predict_scan_out(int scan_size
, enum scan_type type
)
955 int predicted_size
= 3;
956 int num_bytes
= (scan_size
- 1) / 8;
958 if (tap_get_state() != TAP_DRSHIFT
)
961 if (type
== SCAN_IN
) /* only from device to host */
964 predicted_size
+= CEIL(num_bytes
, 65536) * 3;
965 /* remaining bits - 1 (up to 7) */
966 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 2 : 0;
968 else /* host to device, or bidirectional */
971 predicted_size
+= num_bytes
+ CEIL(num_bytes
, 65536) * 3;
972 /* remaining bits -1 (up to 7) */
973 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 3 : 0;
976 return predicted_size
;
980 int ft2232_predict_scan_in(int scan_size
, enum scan_type type
)
982 int predicted_size
= 0;
984 if (type
!= SCAN_OUT
)
987 predicted_size
+= (CEIL(scan_size
, 8) > 1) ? (CEIL(scan_size
, 8) - 1) : 0;
989 /* remaining bits - 1 */
990 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 1 : 0;
992 /* last bit (from TMS scan) */
996 /* LOG_DEBUG("scan_size: %i, predicted_size: %i", scan_size, predicted_size); */
998 return predicted_size
;
1002 void usbjtag_reset(int trst
, int srst
)
1006 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1007 low_direction
|= nTRSTnOE
; /* switch to output pin (output is low) */
1009 low_output
&= ~nTRST
; /* switch output low */
1013 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1014 low_direction
&= ~nTRSTnOE
; /* switch to input pin (high-Z + internal and external pullup) */
1016 low_output
|= nTRST
; /* switch output high */
1021 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1022 low_output
&= ~nSRST
; /* switch output low */
1024 low_direction
|= nSRSTnOE
; /* switch to output pin (output is low) */
1028 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1029 low_output
|= nSRST
; /* switch output high */
1031 low_direction
&= ~nSRSTnOE
; /* switch to input pin (high-Z) */
1034 /* command "set data bits low byte" */
1036 BUFFER_ADD
= low_output
;
1037 BUFFER_ADD
= low_direction
;
1041 void jtagkey_reset(int trst
, int srst
)
1045 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1046 high_output
&= ~nTRSTnOE
;
1048 high_output
&= ~nTRST
;
1052 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1053 high_output
|= nTRSTnOE
;
1055 high_output
|= nTRST
;
1060 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1061 high_output
&= ~nSRST
;
1063 high_output
&= ~nSRSTnOE
;
1067 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1068 high_output
|= nSRST
;
1070 high_output
|= nSRSTnOE
;
1073 /* command "set data bits high byte" */
1075 BUFFER_ADD
= high_output
;
1076 BUFFER_ADD
= high_direction
;
1077 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1082 void olimex_jtag_reset(int trst
, int srst
)
1086 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1087 high_output
&= ~nTRSTnOE
;
1089 high_output
&= ~nTRST
;
1093 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1094 high_output
|= nTRSTnOE
;
1096 high_output
|= nTRST
;
1101 high_output
|= nSRST
;
1105 high_output
&= ~nSRST
;
1108 /* command "set data bits high byte" */
1110 BUFFER_ADD
= high_output
;
1111 BUFFER_ADD
= high_direction
;
1112 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1117 void axm0432_jtag_reset(int trst
, int srst
)
1121 tap_set_state(TAP_RESET
);
1122 high_output
&= ~nTRST
;
1126 high_output
|= nTRST
;
1131 high_output
&= ~nSRST
;
1135 high_output
|= nSRST
;
1138 /* command "set data bits low byte" */
1140 BUFFER_ADD
= high_output
;
1141 BUFFER_ADD
= high_direction
;
1142 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1147 void flyswatter_reset(int trst
, int srst
)
1151 low_output
&= ~nTRST
;
1155 low_output
|= nTRST
;
1160 low_output
|= nSRST
;
1164 low_output
&= ~nSRST
;
1167 /* command "set data bits low byte" */
1169 BUFFER_ADD
= low_output
;
1170 BUFFER_ADD
= low_direction
;
1171 LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst
, srst
, low_output
, low_direction
);
1175 void turtle_reset(int trst
, int srst
)
1181 low_output
|= nSRST
;
1185 low_output
&= ~nSRST
;
1188 /* command "set data bits low byte" */
1190 BUFFER_ADD
= low_output
;
1191 BUFFER_ADD
= low_direction
;
1192 LOG_DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", srst
, low_output
, low_direction
);
1196 void comstick_reset(int trst
, int srst
)
1200 high_output
&= ~nTRST
;
1204 high_output
|= nTRST
;
1209 high_output
&= ~nSRST
;
1213 high_output
|= nSRST
;
1216 /* command "set data bits high byte" */
1218 BUFFER_ADD
= high_output
;
1219 BUFFER_ADD
= high_direction
;
1220 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1225 void stm32stick_reset(int trst
, int srst
)
1229 high_output
&= ~nTRST
;
1233 high_output
|= nTRST
;
1238 low_output
&= ~nSRST
;
1242 low_output
|= nSRST
;
1245 /* command "set data bits low byte" */
1247 BUFFER_ADD
= low_output
;
1248 BUFFER_ADD
= low_direction
;
1250 /* command "set data bits high byte" */
1252 BUFFER_ADD
= high_output
;
1253 BUFFER_ADD
= high_direction
;
1254 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1260 void sheevaplug_reset(int trst
, int srst
)
1263 high_output
&= ~nTRST
;
1265 high_output
|= nTRST
;
1268 high_output
&= ~nSRSTnOE
;
1270 high_output
|= nSRSTnOE
;
1272 /* command "set data bits high byte" */
1274 BUFFER_ADD
= high_output
;
1275 BUFFER_ADD
= high_direction
;
1276 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
, high_direction
);
1279 int ft2232_execute_queue()
1281 jtag_command_t
* cmd
= jtag_command_queue
; /* currently processed command */
1283 int scan_size
; /* size of IR or DR scan */
1284 enum scan_type type
;
1286 int predicted_size
= 0;
1289 first_unsent
= cmd
; /* next command that has to be sent */
1292 /* return ERROR_OK, unless ft2232_send_and_recv reports a failed check
1293 * that wasn't handled by a caller-provided error handler
1297 ft2232_buffer_size
= 0;
1298 ft2232_expect_read
= 0;
1300 /* blink, if the current layout has that feature */
1308 case JTAG_END_STATE
:
1309 if (cmd
->cmd
.end_state
->end_state
!= -1)
1310 ft2232_end_state(cmd
->cmd
.end_state
->end_state
);
1314 /* only send the maximum buffer size that FT2232C can handle */
1316 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1318 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1319 retval
= ERROR_JTAG_QUEUE_FAILED
;
1324 if ( (cmd
->cmd
.reset
->trst
== 1) || ( cmd
->cmd
.reset
->srst
&& (jtag_reset_config
& RESET_SRST_PULLS_TRST
) ) )
1326 tap_set_state(TAP_RESET
);
1328 layout
->reset(cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1331 #ifdef _DEBUG_JTAG_IO_
1332 LOG_DEBUG("trst: %i, srst: %i", cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1337 /* only send the maximum buffer size that FT2232C can handle */
1339 if (tap_get_state() != TAP_IDLE
)
1340 predicted_size
+= 3;
1341 predicted_size
+= 3 * CEIL(cmd
->cmd
.runtest
->num_cycles
, 7);
1342 if ( (cmd
->cmd
.runtest
->end_state
!= -1) && (cmd
->cmd
.runtest
->end_state
!= TAP_IDLE
) )
1343 predicted_size
+= 3;
1344 if ( (cmd
->cmd
.runtest
->end_state
== -1) && (tap_get_end_state() != TAP_IDLE
) )
1345 predicted_size
+= 3;
1346 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1348 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1349 retval
= ERROR_JTAG_QUEUE_FAILED
;
1353 if (tap_get_state() != TAP_IDLE
)
1355 /* command "Clock Data to TMS/CS Pin (no Read)" */
1357 BUFFER_ADD
= 0x6; /* scan 7 bits */
1360 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_IDLE
);
1361 tap_set_state(TAP_IDLE
);
1364 i
= cmd
->cmd
.runtest
->num_cycles
;
1367 /* command "Clock Data to TMS/CS Pin (no Read)" */
1371 BUFFER_ADD
= (i
> 7) ? 6 : (i
- 1);
1375 tap_set_state(TAP_IDLE
);
1376 i
-= (i
> 7) ? 7 : i
;
1377 /* LOG_DEBUG("added TMS scan (no read)"); */
1380 if (cmd
->cmd
.runtest
->end_state
!= -1)
1381 ft2232_end_state(cmd
->cmd
.runtest
->end_state
);
1383 if ( tap_get_state() != tap_get_end_state() )
1385 /* command "Clock Data to TMS/CS Pin (no Read)" */
1390 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() );
1391 tap_set_state( tap_get_end_state() );
1392 /* LOG_DEBUG("added TMS scan (no read)"); */
1395 #ifdef _DEBUG_JTAG_IO_
1396 LOG_DEBUG( "runtest: %i, end in %s", cmd
->cmd
.runtest
->num_cycles
, tap_state_name( tap_get_end_state() ) );
1400 case JTAG_STATEMOVE
:
1401 /* only send the maximum buffer size that FT2232C can handle */
1403 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1405 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1406 retval
= ERROR_JTAG_QUEUE_FAILED
;
1410 if (cmd
->cmd
.statemove
->end_state
!= -1)
1411 ft2232_end_state(cmd
->cmd
.statemove
->end_state
);
1413 /* command "Clock Data to TMS/CS Pin (no Read)" */
1416 BUFFER_ADD
= 0x6; /* scan 7 bits */
1419 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() );
1420 /* LOG_DEBUG("added TMS scan (no read)"); */
1421 tap_set_state( tap_get_end_state() );
1423 #ifdef _DEBUG_JTAG_IO_
1424 LOG_DEBUG( "statemove: %s", tap_state_name( tap_get_end_state() ) );
1429 /* only send the maximum buffer size that FT2232C can handle */
1430 predicted_size
= 3 * CEIL(cmd
->cmd
.pathmove
->num_states
, 7);
1431 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1433 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1434 retval
= ERROR_JTAG_QUEUE_FAILED
;
1438 ft2232_add_pathmove(cmd
->cmd
.pathmove
);
1440 #ifdef _DEBUG_JTAG_IO_
1441 LOG_DEBUG( "pathmove: %i states, end in %s", cmd
->cmd
.pathmove
->num_states
,
1442 tap_state_name(cmd
->cmd
.pathmove
->path
[cmd
->cmd
.pathmove
->num_states
- 1]) );
1447 scan_size
= jtag_build_buffer(cmd
->cmd
.scan
, &buffer
);
1448 type
= jtag_scan_type(cmd
->cmd
.scan
);
1449 predicted_size
= ft2232_predict_scan_out(scan_size
, type
);
1450 if ( (predicted_size
+ 1) > FT2232_BUFFER_SIZE
)
1452 LOG_DEBUG("oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
1453 /* unsent commands before this */
1454 if (first_unsent
!= cmd
)
1455 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1456 retval
= ERROR_JTAG_QUEUE_FAILED
;
1458 /* current command */
1459 if (cmd
->cmd
.scan
->end_state
!= -1)
1460 ft2232_end_state(cmd
->cmd
.scan
->end_state
);
1461 ft2232_large_scan(cmd
->cmd
.scan
, type
, buffer
, scan_size
);
1463 first_unsent
= cmd
->next
;
1468 else if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1470 LOG_DEBUG("ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
1473 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1474 retval
= ERROR_JTAG_QUEUE_FAILED
;
1478 ft2232_expect_read
+= ft2232_predict_scan_in(scan_size
, type
);
1479 /* LOG_DEBUG("new read size: %i", ft2232_expect_read); */
1480 if (cmd
->cmd
.scan
->end_state
!= -1)
1481 ft2232_end_state(cmd
->cmd
.scan
->end_state
);
1482 ft2232_add_scan(cmd
->cmd
.scan
->ir_scan
, type
, buffer
, scan_size
);
1486 #ifdef _DEBUG_JTAG_IO_
1487 LOG_DEBUG( "%s scan, %i bits, end in %s", (cmd
->cmd
.scan
->ir_scan
) ? "IR" : "DR", scan_size
,
1488 tap_state_name( tap_get_end_state() ) );
1493 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1494 retval
= ERROR_JTAG_QUEUE_FAILED
;
1495 first_unsent
= cmd
->next
;
1496 jtag_sleep(cmd
->cmd
.sleep
->us
);
1497 #ifdef _DEBUG_JTAG_IO_
1498 LOG_DEBUG( "sleep %i usec while in %s", cmd
->cmd
.sleep
->us
, tap_state_name( tap_get_state() ) );
1502 case JTAG_STABLECLOCKS
:
1504 /* this is only allowed while in a stable state. A check for a stable
1505 * state was done in jtag_add_clocks()
1507 if (ft2232_stableclocks(cmd
->cmd
.stableclocks
->num_cycles
, cmd
) != ERROR_OK
)
1508 retval
= ERROR_JTAG_QUEUE_FAILED
;
1509 #ifdef _DEBUG_JTAG_IO_
1510 LOG_DEBUG( "clocks %i while in %s", cmd
->cmd
.stableclocks
->num_cycles
, tap_state_name( tap_get_state() ) );
1515 LOG_ERROR("BUG: unknown JTAG command type encountered");
1522 if (require_send
> 0)
1523 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1524 retval
= ERROR_JTAG_QUEUE_FAILED
;
1530 #if BUILD_FT2232_FTD2XX == 1
1531 static int ft2232_init_ftd2xx(u16 vid
, u16 pid
, int more
, int* try_more
)
1534 DWORD openex_flags
= 0;
1535 char* openex_string
= NULL
;
1538 LOG_DEBUG("'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)", ft2232_layout
, vid
, pid
);
1541 /* Add non-standard Vid/Pid to the linux driver */
1542 if ( ( status
= FT_SetVIDPID(vid
, pid
) ) != FT_OK
)
1544 LOG_WARNING("couldn't add %4.4x:%4.4x", vid
, pid
);
1548 if (ft2232_device_desc
&& ft2232_serial
)
1550 LOG_WARNING("can't open by device description and serial number, giving precedence to serial");
1551 ft2232_device_desc
= NULL
;
1554 if (ft2232_device_desc
)
1556 openex_string
= ft2232_device_desc
;
1557 openex_flags
= FT_OPEN_BY_DESCRIPTION
;
1559 else if (ft2232_serial
)
1561 openex_string
= ft2232_serial
;
1562 openex_flags
= FT_OPEN_BY_SERIAL_NUMBER
;
1566 LOG_ERROR("neither device description nor serial number specified");
1567 LOG_ERROR("please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
1569 return ERROR_JTAG_INIT_FAILED
;
1572 if ( ( status
= FT_OpenEx(openex_string
, openex_flags
, &ftdih
) ) != FT_OK
)
1578 LOG_WARNING("unable to open ftdi device (trying more): %lu", status
);
1580 return ERROR_JTAG_INIT_FAILED
;
1582 LOG_ERROR("unable to open ftdi device: %lu", status
);
1583 status
= FT_ListDevices(&num_devices
, NULL
, FT_LIST_NUMBER_ONLY
);
1584 if (status
== FT_OK
)
1586 char** desc_array
= malloc( sizeof(char*) * (num_devices
+ 1) );
1589 for (i
= 0; i
< num_devices
; i
++)
1590 desc_array
[i
] = malloc(64);
1592 desc_array
[num_devices
] = NULL
;
1594 status
= FT_ListDevices(desc_array
, &num_devices
, FT_LIST_ALL
| openex_flags
);
1596 if (status
== FT_OK
)
1598 LOG_ERROR("ListDevices: %lu\n", num_devices
);
1599 for (i
= 0; i
< num_devices
; i
++)
1600 LOG_ERROR("%i: \"%s\"", i
, desc_array
[i
]);
1603 for (i
= 0; i
< num_devices
; i
++)
1604 free(desc_array
[i
]);
1610 LOG_ERROR("ListDevices: NONE\n");
1612 return ERROR_JTAG_INIT_FAILED
;
1615 if ( ( status
= FT_SetLatencyTimer(ftdih
, ft2232_latency
) ) != FT_OK
)
1617 LOG_ERROR("unable to set latency timer: %lu", status
);
1618 return ERROR_JTAG_INIT_FAILED
;
1621 if ( ( status
= FT_GetLatencyTimer(ftdih
, &latency_timer
) ) != FT_OK
)
1623 LOG_ERROR("unable to get latency timer: %lu", status
);
1624 return ERROR_JTAG_INIT_FAILED
;
1628 LOG_DEBUG("current latency timer: %i", latency_timer
);
1631 if ( ( status
= FT_SetTimeouts(ftdih
, 5000, 5000) ) != FT_OK
)
1633 LOG_ERROR("unable to set timeouts: %lu", status
);
1634 return ERROR_JTAG_INIT_FAILED
;
1637 if ( ( status
= FT_SetBitMode(ftdih
, 0x0b, 2) ) != FT_OK
)
1639 LOG_ERROR("unable to enable bit i/o mode: %lu", status
);
1640 return ERROR_JTAG_INIT_FAILED
;
1647 static int ft2232_purge_ftd2xx(void)
1651 if ( ( status
= FT_Purge(ftdih
, FT_PURGE_RX
| FT_PURGE_TX
) ) != FT_OK
)
1653 LOG_ERROR("error purging ftd2xx device: %lu", status
);
1654 return ERROR_JTAG_INIT_FAILED
;
1661 #endif /* BUILD_FT2232_FTD2XX == 1 */
1663 #if BUILD_FT2232_LIBFTDI == 1
1664 static int ft2232_init_libftdi(u16 vid
, u16 pid
, int more
, int* try_more
)
1668 LOG_DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
1669 ft2232_layout
, vid
, pid
);
1671 if (ftdi_init(&ftdic
) < 0)
1672 return ERROR_JTAG_INIT_FAILED
;
1674 /* context, vendor id, product id */
1675 if (ftdi_usb_open_desc(&ftdic
, vid
, pid
, ft2232_device_desc
,
1679 LOG_WARNING("unable to open ftdi device (trying more): %s",
1682 LOG_ERROR("unable to open ftdi device: %s", ftdic
.error_str
);
1684 return ERROR_JTAG_INIT_FAILED
;
1687 if (ftdi_set_interface(&ftdic
, INTERFACE_A
) < 0)
1689 LOG_ERROR("unable to select FT2232 channel A: %s", ftdic
.error_str
);
1690 return ERROR_JTAG_INIT_FAILED
;
1693 if (ftdi_usb_reset(&ftdic
) < 0)
1695 LOG_ERROR("unable to reset ftdi device");
1696 return ERROR_JTAG_INIT_FAILED
;
1699 if (ftdi_set_latency_timer(&ftdic
, ft2232_latency
) < 0)
1701 LOG_ERROR("unable to set latency timer");
1702 return ERROR_JTAG_INIT_FAILED
;
1705 if (ftdi_get_latency_timer(&ftdic
, &latency_timer
) < 0)
1707 LOG_ERROR("unable to get latency timer");
1708 return ERROR_JTAG_INIT_FAILED
;
1712 LOG_DEBUG("current latency timer: %i", latency_timer
);
1715 ftdi_set_bitmode(&ftdic
, 0x0b, 2); /* ctx, JTAG I/O mask */
1721 static int ft2232_purge_libftdi(void)
1723 if (ftdi_usb_purge_buffers(&ftdic
) < 0)
1725 LOG_ERROR("ftdi_purge_buffers: %s", ftdic
.error_str
);
1726 return ERROR_JTAG_INIT_FAILED
;
1733 #endif /* BUILD_FT2232_LIBFTDI == 1 */
1735 int ft2232_init(void)
1740 ft2232_layout_t
* cur_layout
= ft2232_layouts
;
1743 if ( (ft2232_layout
== NULL
) || (ft2232_layout
[0] == 0) )
1745 ft2232_layout
= "usbjtag";
1746 LOG_WARNING("No ft2232 layout specified, using default 'usbjtag'");
1749 while (cur_layout
->name
)
1751 if (strcmp(cur_layout
->name
, ft2232_layout
) == 0)
1753 layout
= cur_layout
;
1761 LOG_ERROR("No matching layout found for %s", ft2232_layout
);
1762 return ERROR_JTAG_INIT_FAILED
;
1768 * "more indicates that there are more IDs to try, so we should
1769 * not print an error for an ID mismatch (but for anything
1772 * try_more indicates that the error code returned indicates an
1773 * ID mismatch (and nothing else) and that we should proceeed
1774 * with the next ID pair.
1776 int more
= ft2232_vid
[i
+ 1] || ft2232_pid
[i
+ 1];
1779 #if BUILD_FT2232_FTD2XX == 1
1780 retval
= ft2232_init_ftd2xx(ft2232_vid
[i
], ft2232_pid
[i
],
1782 #elif BUILD_FT2232_LIBFTDI == 1
1783 retval
= ft2232_init_libftdi(ft2232_vid
[i
], ft2232_pid
[i
],
1788 if (!more
|| !try_more
)
1792 ft2232_buffer_size
= 0;
1793 ft2232_buffer
= malloc(FT2232_BUFFER_SIZE
);
1795 if (layout
->init() != ERROR_OK
)
1796 return ERROR_JTAG_INIT_FAILED
;
1798 ft2232_speed(jtag_speed
);
1800 buf
[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
1801 if ( ( ( retval
= ft2232_write(buf
, 1, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 1) )
1803 LOG_ERROR("couldn't write to FT2232 to disable loopback");
1804 return ERROR_JTAG_INIT_FAILED
;
1807 #if BUILD_FT2232_FTD2XX == 1
1808 return ft2232_purge_ftd2xx();
1809 #elif BUILD_FT2232_LIBFTDI == 1
1810 return ft2232_purge_libftdi();
1817 int usbjtag_init(void)
1823 low_direction
= 0x0b;
1825 if (strcmp(ft2232_layout
, "usbjtag") == 0)
1832 else if (strcmp(ft2232_layout
, "signalyzer") == 0)
1839 else if (strcmp(ft2232_layout
, "evb_lm3s811") == 0)
1846 low_direction
= 0x8b;
1850 LOG_ERROR("BUG: usbjtag_init called for unknown layout '%s'", ft2232_layout
);
1851 return ERROR_JTAG_INIT_FAILED
;
1854 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1856 low_direction
&= ~nTRSTnOE
; /* nTRST input */
1857 low_output
&= ~nTRST
; /* nTRST = 0 */
1861 low_direction
|= nTRSTnOE
; /* nTRST output */
1862 low_output
|= nTRST
; /* nTRST = 1 */
1865 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1867 low_direction
|= nSRSTnOE
; /* nSRST output */
1868 low_output
|= nSRST
; /* nSRST = 1 */
1872 low_direction
&= ~nSRSTnOE
; /* nSRST input */
1873 low_output
&= ~nSRST
; /* nSRST = 0 */
1876 /* initialize low byte for jtag */
1877 buf
[0] = 0x80; /* command "set data bits low byte" */
1878 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, xRST high) */
1879 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
1880 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1882 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1884 LOG_ERROR("couldn't initialize FT2232 with 'USBJTAG' layout");
1885 return ERROR_JTAG_INIT_FAILED
;
1892 int axm0432_jtag_init(void)
1898 low_direction
= 0x2b;
1900 /* initialize low byte for jtag */
1901 buf
[0] = 0x80; /* command "set data bits low byte" */
1902 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1903 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1904 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1906 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1908 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1909 return ERROR_JTAG_INIT_FAILED
;
1912 if (strcmp(layout
->name
, "axm0432_jtag") == 0)
1915 nTRSTnOE
= 0x0; /* No output enable for TRST*/
1917 nSRSTnOE
= 0x0; /* No output enable for SRST*/
1921 LOG_ERROR("BUG: axm0432_jtag_init called for non axm0432 layout");
1926 high_direction
= 0x0c;
1928 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1930 LOG_ERROR("can't set nTRSTOE to push-pull on the Dicarlo jtag");
1934 high_output
|= nTRST
;
1937 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1939 LOG_ERROR("can't set nSRST to push-pull on the Dicarlo jtag");
1943 high_output
|= nSRST
;
1946 /* initialize high port */
1947 buf
[0] = 0x82; /* command "set data bits high byte" */
1948 buf
[1] = high_output
; /* value */
1949 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
1950 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1952 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1954 LOG_ERROR("couldn't initialize FT2232 with 'Dicarlo' layout");
1955 return ERROR_JTAG_INIT_FAILED
;
1962 int jtagkey_init(void)
1968 low_direction
= 0x1b;
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, nOE=0) */
1973 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
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 'JTAGkey' layout");
1979 return ERROR_JTAG_INIT_FAILED
;
1982 if (strcmp(layout
->name
, "jtagkey") == 0)
1989 else if ( (strcmp(layout
->name
, "jtagkey_prototype_v1") == 0)
1990 || (strcmp(layout
->name
, "oocdlink") == 0) )
1999 LOG_ERROR("BUG: jtagkey_init called for non jtagkey layout");
2004 high_direction
= 0x0f;
2006 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2008 high_output
|= nTRSTnOE
;
2009 high_output
&= ~nTRST
;
2013 high_output
&= ~nTRSTnOE
;
2014 high_output
|= nTRST
;
2017 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2019 high_output
&= ~nSRSTnOE
;
2020 high_output
|= nSRST
;
2024 high_output
|= nSRSTnOE
;
2025 high_output
&= ~nSRST
;
2028 /* initialize high port */
2029 buf
[0] = 0x82; /* command "set data bits high byte" */
2030 buf
[1] = high_output
; /* value */
2031 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2032 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2034 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2036 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2037 return ERROR_JTAG_INIT_FAILED
;
2044 int olimex_jtag_init(void)
2050 low_direction
= 0x1b;
2052 /* initialize low byte for jtag */
2053 buf
[0] = 0x80; /* command "set data bits low byte" */
2054 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2055 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2056 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2058 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2060 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2061 return ERROR_JTAG_INIT_FAILED
;
2067 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2070 high_direction
= 0x0f;
2072 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2074 high_output
|= nTRSTnOE
;
2075 high_output
&= ~nTRST
;
2079 high_output
&= ~nTRSTnOE
;
2080 high_output
|= nTRST
;
2083 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2085 LOG_ERROR("can't set nSRST to push-pull on the Olimex ARM-USB-OCD");
2089 high_output
&= ~nSRST
;
2092 /* turn red LED on */
2093 high_output
|= 0x08;
2095 /* initialize high port */
2096 buf
[0] = 0x82; /* command "set data bits high byte" */
2097 buf
[1] = high_output
; /* value */
2098 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2099 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2101 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2103 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2104 return ERROR_JTAG_INIT_FAILED
;
2111 int flyswatter_init(void)
2117 low_direction
= 0xfb;
2119 /* initialize low byte for jtag */
2120 buf
[0] = 0x80; /* command "set data bits low byte" */
2121 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2122 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE[12]=out, n[ST]srst=out */
2123 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2125 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2127 LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
2128 return ERROR_JTAG_INIT_FAILED
;
2132 nTRSTnOE
= 0x0; /* not output enable for nTRST */
2134 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2137 high_direction
= 0x0c;
2139 /* turn red LED1 on, LED2 off */
2140 high_output
|= 0x08;
2142 /* initialize high port */
2143 buf
[0] = 0x82; /* command "set data bits high byte" */
2144 buf
[1] = high_output
; /* value */
2145 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2146 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2148 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2150 LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
2151 return ERROR_JTAG_INIT_FAILED
;
2158 int turtle_init(void)
2164 low_direction
= 0x5b;
2166 /* initialize low byte for jtag */
2167 buf
[0] = 0x80; /* command "set data bits low byte" */
2168 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2169 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2170 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2172 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2174 LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
2175 return ERROR_JTAG_INIT_FAILED
;
2181 high_direction
= 0x0C;
2183 /* initialize high port */
2184 buf
[0] = 0x82; /* command "set data bits high byte" */
2185 buf
[1] = high_output
;
2186 buf
[2] = high_direction
;
2187 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2189 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2191 LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
2192 return ERROR_JTAG_INIT_FAILED
;
2199 int comstick_init(void)
2205 low_direction
= 0x0b;
2207 /* initialize low byte for jtag */
2208 buf
[0] = 0x80; /* command "set data bits low byte" */
2209 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2210 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2211 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2213 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2215 LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
2216 return ERROR_JTAG_INIT_FAILED
;
2220 nTRSTnOE
= 0x00; /* no output enable for nTRST */
2222 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2225 high_direction
= 0x03;
2227 /* initialize high port */
2228 buf
[0] = 0x82; /* command "set data bits high byte" */
2229 buf
[1] = high_output
;
2230 buf
[2] = high_direction
;
2231 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2233 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2235 LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
2236 return ERROR_JTAG_INIT_FAILED
;
2243 int stm32stick_init(void)
2249 low_direction
= 0x8b;
2251 /* initialize low byte for jtag */
2252 buf
[0] = 0x80; /* command "set data bits low byte" */
2253 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2254 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2255 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2257 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2259 LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
2260 return ERROR_JTAG_INIT_FAILED
;
2264 nTRSTnOE
= 0x00; /* no output enable for nTRST */
2266 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2269 high_direction
= 0x03;
2271 /* initialize high port */
2272 buf
[0] = 0x82; /* command "set data bits high byte" */
2273 buf
[1] = high_output
;
2274 buf
[2] = high_direction
;
2275 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2277 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2279 LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
2280 return ERROR_JTAG_INIT_FAILED
;
2287 int sheevaplug_init(void)
2293 low_direction
= 0x1b;
2295 /* initialize low byte for jtag */
2296 buf
[0] = 0x80; /* command "set data bits low byte" */
2297 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2298 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
2299 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2301 if (((ft2232_write(buf
, 3, &bytes_written
)) != ERROR_OK
) || (bytes_written
!= 3))
2303 LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
2304 return ERROR_JTAG_INIT_FAILED
;
2313 high_direction
= 0x0f;
2315 /* nTRST is always push-pull */
2316 high_output
&= ~nTRSTnOE
;
2317 high_output
|= nTRST
;
2319 /* nSRST is always open-drain */
2320 high_output
|= nSRSTnOE
;
2321 high_output
&= ~nSRST
;
2323 /* initialize high port */
2324 buf
[0] = 0x82; /* command "set data bits high byte" */
2325 buf
[1] = high_output
; /* value */
2326 buf
[2] = high_direction
; /* all outputs - xRST */
2327 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2329 if (((ft2232_write(buf
, 3, &bytes_written
)) != ERROR_OK
) || (bytes_written
!= 3))
2331 LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
2332 return ERROR_JTAG_INIT_FAILED
;
2338 void olimex_jtag_blink(void)
2340 /* Olimex ARM-USB-OCD has a LED connected to ACBUS3
2341 * ACBUS3 is bit 3 of the GPIOH port
2343 if (high_output
& 0x08)
2345 /* set port pin high */
2346 high_output
&= 0x07;
2350 /* set port pin low */
2351 high_output
|= 0x08;
2355 BUFFER_ADD
= high_output
;
2356 BUFFER_ADD
= high_direction
;
2360 void turtle_jtag_blink(void)
2363 * Turtelizer2 has two LEDs connected to ACBUS2 and ACBUS3
2365 if (high_output
& 0x08)
2375 BUFFER_ADD
= high_output
;
2376 BUFFER_ADD
= high_direction
;
2380 int ft2232_quit(void)
2382 #if BUILD_FT2232_FTD2XX == 1
2385 status
= FT_Close(ftdih
);
2386 #elif BUILD_FT2232_LIBFTDI == 1
2387 ftdi_disable_bitbang(&ftdic
);
2389 ftdi_usb_close(&ftdic
);
2391 ftdi_deinit(&ftdic
);
2394 free(ft2232_buffer
);
2395 ft2232_buffer
= NULL
;
2401 int ft2232_handle_device_desc_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2405 ft2232_device_desc
= strdup(args
[0]);
2409 LOG_ERROR("expected exactly one argument to ft2232_device_desc <description>");
2416 int ft2232_handle_serial_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2420 ft2232_serial
= strdup(args
[0]);
2424 LOG_ERROR("expected exactly one argument to ft2232_serial <serial-number>");
2431 int ft2232_handle_layout_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2436 ft2232_layout
= malloc(strlen(args
[0]) + 1);
2437 strcpy(ft2232_layout
, args
[0]);
2443 int ft2232_handle_vid_pid_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2447 if (argc
> MAX_USB_IDS
* 2)
2449 LOG_WARNING("ignoring extra IDs in ft2232_vid_pid "
2450 "(maximum is %d pairs)", MAX_USB_IDS
);
2451 argc
= MAX_USB_IDS
* 2;
2453 if ( argc
< 2 || (argc
& 1) )
2455 LOG_WARNING("incomplete ft2232_vid_pid configuration directive");
2460 for (i
= 0; i
+ 1 < argc
; i
+= 2)
2462 ft2232_vid
[i
>> 1] = strtol(args
[i
], NULL
, 0);
2463 ft2232_pid
[i
>> 1] = strtol(args
[i
+ 1], NULL
, 0);
2467 * Explicitly terminate, in case there are multiples instances of
2470 ft2232_vid
[i
>> 1] = ft2232_pid
[i
>> 1] = 0;
2476 int ft2232_handle_latency_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2480 ft2232_latency
= atoi(args
[0]);
2484 LOG_ERROR("expected exactly one argument to ft2232_latency <ms>");
2491 static int ft2232_stableclocks(int num_cycles
, jtag_command_t
* cmd
)
2495 /* 7 bits of either ones or zeros. */
2496 u8 tms
= (tap_get_state() == TAP_RESET
? 0x7F : 0x00);
2498 while (num_cycles
> 0)
2500 /* the command 0x4b, "Clock Data to TMS/CS Pin (no Read)" handles
2501 * at most 7 bits per invocation. Here we invoke it potentially
2504 int bitcount_per_command
= (num_cycles
> 7) ? 7 : num_cycles
;
2506 if (ft2232_buffer_size
+ 3 >= FT2232_BUFFER_SIZE
)
2508 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
2509 retval
= ERROR_JTAG_QUEUE_FAILED
;
2514 /* command "Clock Data to TMS/CS Pin (no Read)" */
2518 BUFFER_ADD
= bitcount_per_command
- 1;
2520 /* TMS data bits are either all zeros or ones to stay in the current stable state */
2525 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)