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: %i.%06i, inter2: %i.%06i end: %i.%06i", d_inter
.tv_sec
, d_inter
.tv_usec
, d_inter2
.tv_sec
,
476 d_inter2
.tv_usec
, d_end
.tv_sec
,
480 ft2232_buffer_size
= bytes_read
;
482 if (ft2232_expect_read
!= ft2232_buffer_size
)
484 LOG_ERROR("ft2232_expect_read (%i) != ft2232_buffer_size (%i) (%i retries)", ft2232_expect_read
,
487 ft2232_debug_dump_buffer();
492 #ifdef _DEBUG_USB_COMMS_
493 LOG_DEBUG("read buffer (%i retries): %i bytes", 100 - timeout
, ft2232_buffer_size
);
494 ft2232_debug_dump_buffer();
498 ft2232_expect_read
= 0;
499 ft2232_read_pointer
= 0;
501 /* return ERROR_OK, unless a jtag_read_buffer returns a failed check
502 * that wasn't handled by a caller-provided error handler
512 type
= jtag_scan_type(cmd
->cmd
.scan
);
513 if (type
!= SCAN_OUT
)
515 scan_size
= jtag_scan_size(cmd
->cmd
.scan
);
516 buffer
= calloc(CEIL(scan_size
, 8), 1);
517 ft2232_read_scan(type
, buffer
, scan_size
);
518 if (jtag_read_buffer(buffer
, cmd
->cmd
.scan
) != ERROR_OK
)
519 retval
= ERROR_JTAG_QUEUE_FAILED
;
531 ft2232_buffer_size
= 0;
537 static void ft2232_add_pathmove(pathmove_command_t
* cmd
)
539 int num_states
= cmd
->num_states
;
544 u8 tms_byte
= 0; /* zero this on each MPSSE batch */
548 int num_states_batch
= num_states
> 7 ? 7 : num_states
;
550 /* command "Clock Data to TMS/CS Pin (no Read)" */
553 /* number of states remaining */
554 BUFFER_ADD
= num_states_batch
- 1;
556 while (num_states_batch
--)
558 if (tap_state_transition(tap_get_state(), false) == cmd
->path
[state_count
])
559 buf_set_u32(&tms_byte
, bit_count
++, 1, 0x0);
560 else if (tap_state_transition(tap_get_state(), true) == cmd
->path
[state_count
])
561 buf_set_u32(&tms_byte
, bit_count
++, 1, 0x1);
564 LOG_ERROR( "BUG: %s -> %s isn't a valid TAP transition", tap_state_name(
565 tap_get_state() ), tap_state_name(cmd
->path
[state_count
]) );
569 tap_set_state(cmd
->path
[state_count
]);
574 BUFFER_ADD
= tms_byte
;
577 tap_set_end_state(tap_get_state());
581 void ft2232_add_scan(int ir_scan
, enum scan_type type
, u8
* buffer
, int scan_size
)
583 int num_bytes
= (scan_size
+ 7) / 8;
584 int bits_left
= scan_size
;
588 if ( !( ( !ir_scan
&& (tap_get_state() == TAP_DRSHIFT
) )
589 || ( ir_scan
&& (tap_get_state() == TAP_IRSHIFT
) ) ) )
591 /* command "Clock Data to TMS/CS Pin (no Read)" */
594 BUFFER_ADD
= 0x6; /* scan 7 bits */
599 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_IRSHIFT
);
600 tap_set_state(TAP_IRSHIFT
);
604 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_DRSHIFT
);
605 tap_set_state(TAP_DRSHIFT
);
607 /* LOG_DEBUG("added TMS scan (no read)"); */
610 /* add command for complete bytes */
611 while (num_bytes
> 1)
616 /* Clock Data Bytes In and Out LSB First */
618 /* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
620 else if (type
== SCAN_OUT
)
622 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
624 /* LOG_DEBUG("added TDI bytes (o)"); */
626 else if (type
== SCAN_IN
)
628 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
630 /* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
633 thisrun_bytes
= (num_bytes
> 65537) ? 65536 : (num_bytes
- 1);
634 num_bytes
-= thisrun_bytes
;
635 BUFFER_ADD
= (thisrun_bytes
- 1) & 0xff;
636 BUFFER_ADD
= ( (thisrun_bytes
- 1) >> 8 ) & 0xff;
640 /* add complete bytes */
641 while (thisrun_bytes
-- > 0)
643 BUFFER_ADD
= buffer
[cur_byte
];
648 else /* (type == SCAN_IN) */
650 bits_left
-= 8 * (thisrun_bytes
);
654 /* the most signifcant bit is scanned during TAP movement */
656 last_bit
= ( buffer
[cur_byte
] >> (bits_left
- 1) ) & 0x1;
660 /* process remaining bits but the last one */
665 /* Clock Data Bits In and Out LSB First */
667 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
669 else if (type
== SCAN_OUT
)
671 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
673 /* LOG_DEBUG("added TDI bits (o)"); */
675 else if (type
== SCAN_IN
)
677 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
679 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
681 BUFFER_ADD
= bits_left
- 2;
683 BUFFER_ADD
= buffer
[cur_byte
];
686 if ( ( ir_scan
&& (tap_get_end_state() == TAP_IRSHIFT
) )
687 || ( !ir_scan
&& (tap_get_end_state() == TAP_DRSHIFT
) ) )
691 /* Clock Data Bits In and Out LSB First */
693 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
695 else if (type
== SCAN_OUT
)
697 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
699 /* LOG_DEBUG("added TDI bits (o)"); */
701 else if (type
== SCAN_IN
)
703 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
705 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
708 BUFFER_ADD
= last_bit
;
712 /* move from Shift-IR/DR to end state */
713 if (type
!= SCAN_OUT
)
715 /* Clock Data to TMS/CS Pin with Read */
717 /* LOG_DEBUG("added TMS scan (read)"); */
721 /* Clock Data to TMS/CS Pin (no Read) */
723 /* LOG_DEBUG("added TMS scan (no read)"); */
725 BUFFER_ADD
= 0x6; /* scan 7 bits */
727 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() ) | (last_bit
<< 7);
728 tap_set_state( tap_get_end_state() );
733 static int ft2232_large_scan(scan_command_t
* cmd
, enum scan_type type
, u8
* buffer
, int scan_size
)
735 int num_bytes
= (scan_size
+ 7) / 8;
736 int bits_left
= scan_size
;
739 u8
* receive_buffer
= malloc( CEIL(scan_size
, 8) );
740 u8
* receive_pointer
= receive_buffer
;
744 int thisrun_read
= 0;
748 LOG_ERROR("BUG: large IR scans are not supported");
752 if (tap_get_state() != TAP_DRSHIFT
)
754 /* command "Clock Data to TMS/CS Pin (no Read)" */
757 BUFFER_ADD
= 0x6; /* scan 7 bits */
760 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_DRSHIFT
);
761 tap_set_state(TAP_DRSHIFT
);
764 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
766 LOG_ERROR("couldn't write MPSSE commands to FT2232");
769 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
770 ft2232_buffer_size
= 0;
772 /* add command for complete bytes */
773 while (num_bytes
> 1)
779 /* Clock Data Bytes In and Out LSB First */
781 /* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
783 else if (type
== SCAN_OUT
)
785 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
787 /* LOG_DEBUG("added TDI bytes (o)"); */
789 else if (type
== SCAN_IN
)
791 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
793 /* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
796 thisrun_bytes
= (num_bytes
> 65537) ? 65536 : (num_bytes
- 1);
797 thisrun_read
= thisrun_bytes
;
798 num_bytes
-= thisrun_bytes
;
799 BUFFER_ADD
= (thisrun_bytes
- 1) & 0xff;
800 BUFFER_ADD
= ( (thisrun_bytes
- 1) >> 8 ) & 0xff;
804 /* add complete bytes */
805 while (thisrun_bytes
-- > 0)
807 BUFFER_ADD
= buffer
[cur_byte
];
812 else /* (type == SCAN_IN) */
814 bits_left
-= 8 * (thisrun_bytes
);
817 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
819 LOG_ERROR("couldn't write MPSSE commands to FT2232");
822 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
823 ft2232_buffer_size
= 0;
825 if (type
!= SCAN_OUT
)
827 if ( ( retval
= ft2232_read(receive_pointer
, thisrun_read
, &bytes_read
) ) != ERROR_OK
)
829 LOG_ERROR("couldn't read from FT2232");
832 LOG_DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read
, bytes_read
);
833 receive_pointer
+= bytes_read
;
839 /* the most signifcant bit is scanned during TAP movement */
841 last_bit
= ( buffer
[cur_byte
] >> (bits_left
- 1) ) & 0x1;
845 /* process remaining bits but the last one */
850 /* Clock Data Bits In and Out LSB First */
852 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
854 else if (type
== SCAN_OUT
)
856 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
858 /* LOG_DEBUG("added TDI bits (o)"); */
860 else if (type
== SCAN_IN
)
862 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
864 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
866 BUFFER_ADD
= bits_left
- 2;
868 BUFFER_ADD
= buffer
[cur_byte
];
870 if (type
!= SCAN_OUT
)
874 if (tap_get_end_state() == TAP_DRSHIFT
)
878 /* Clock Data Bits In and Out LSB First */
880 /* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
882 else if (type
== SCAN_OUT
)
884 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
886 /* LOG_DEBUG("added TDI bits (o)"); */
888 else if (type
== SCAN_IN
)
890 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
892 /* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
895 BUFFER_ADD
= last_bit
;
899 /* move from Shift-IR/DR to end state */
900 if (type
!= SCAN_OUT
)
902 /* Clock Data to TMS/CS Pin with Read */
904 /* LOG_DEBUG("added TMS scan (read)"); */
908 /* Clock Data to TMS/CS Pin (no Read) */
910 /* LOG_DEBUG("added TMS scan (no read)"); */
913 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() ) | (last_bit
<< 7);
914 tap_set_state( tap_get_end_state() );
917 if (type
!= SCAN_OUT
)
920 if ( ( retval
= ft2232_write(ft2232_buffer
, ft2232_buffer_size
, &bytes_written
) ) != ERROR_OK
)
922 LOG_ERROR("couldn't write MPSSE commands to FT2232");
925 LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size
, bytes_written
);
926 ft2232_buffer_size
= 0;
928 if (type
!= SCAN_OUT
)
930 if ( ( retval
= ft2232_read(receive_pointer
, thisrun_read
, &bytes_read
) ) != ERROR_OK
)
932 LOG_ERROR("couldn't read from FT2232");
935 LOG_DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read
, bytes_read
);
936 receive_pointer
+= bytes_read
;
943 static int ft2232_predict_scan_out(int scan_size
, enum scan_type type
)
945 int predicted_size
= 3;
946 int num_bytes
= (scan_size
- 1) / 8;
948 if (tap_get_state() != TAP_DRSHIFT
)
951 if (type
== SCAN_IN
) /* only from device to host */
954 predicted_size
+= CEIL(num_bytes
, 65536) * 3;
955 /* remaining bits - 1 (up to 7) */
956 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 2 : 0;
958 else /* host to device, or bidirectional */
961 predicted_size
+= num_bytes
+ CEIL(num_bytes
, 65536) * 3;
962 /* remaining bits -1 (up to 7) */
963 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 3 : 0;
966 return predicted_size
;
970 static int ft2232_predict_scan_in(int scan_size
, enum scan_type type
)
972 int predicted_size
= 0;
974 if (type
!= SCAN_OUT
)
977 predicted_size
+= (CEIL(scan_size
, 8) > 1) ? (CEIL(scan_size
, 8) - 1) : 0;
979 /* remaining bits - 1 */
980 predicted_size
+= ( (scan_size
- 1) % 8 ) ? 1 : 0;
982 /* last bit (from TMS scan) */
986 /* LOG_DEBUG("scan_size: %i, predicted_size: %i", scan_size, predicted_size); */
988 return predicted_size
;
992 static void usbjtag_reset(int trst
, int srst
)
996 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
997 low_direction
|= nTRSTnOE
; /* switch to output pin (output is low) */
999 low_output
&= ~nTRST
; /* switch output low */
1003 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1004 low_direction
&= ~nTRSTnOE
; /* switch to input pin (high-Z + internal and external pullup) */
1006 low_output
|= nTRST
; /* switch output high */
1011 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1012 low_output
&= ~nSRST
; /* switch output low */
1014 low_direction
|= nSRSTnOE
; /* switch to output pin (output is low) */
1018 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1019 low_output
|= nSRST
; /* switch output high */
1021 low_direction
&= ~nSRSTnOE
; /* switch to input pin (high-Z) */
1024 /* command "set data bits low byte" */
1026 BUFFER_ADD
= low_output
;
1027 BUFFER_ADD
= low_direction
;
1031 static void jtagkey_reset(int trst
, int srst
)
1035 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1036 high_output
&= ~nTRSTnOE
;
1038 high_output
&= ~nTRST
;
1042 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1043 high_output
|= nTRSTnOE
;
1045 high_output
|= nTRST
;
1050 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1051 high_output
&= ~nSRST
;
1053 high_output
&= ~nSRSTnOE
;
1057 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1058 high_output
|= nSRST
;
1060 high_output
|= nSRSTnOE
;
1063 /* command "set data bits high byte" */
1065 BUFFER_ADD
= high_output
;
1066 BUFFER_ADD
= high_direction
;
1067 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1072 static void olimex_jtag_reset(int trst
, int srst
)
1076 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1077 high_output
&= ~nTRSTnOE
;
1079 high_output
&= ~nTRST
;
1083 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1084 high_output
|= nTRSTnOE
;
1086 high_output
|= nTRST
;
1091 high_output
|= nSRST
;
1095 high_output
&= ~nSRST
;
1098 /* command "set data bits high byte" */
1100 BUFFER_ADD
= high_output
;
1101 BUFFER_ADD
= high_direction
;
1102 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1107 static void axm0432_jtag_reset(int trst
, int srst
)
1111 tap_set_state(TAP_RESET
);
1112 high_output
&= ~nTRST
;
1116 high_output
|= nTRST
;
1121 high_output
&= ~nSRST
;
1125 high_output
|= nSRST
;
1128 /* command "set data bits low byte" */
1130 BUFFER_ADD
= high_output
;
1131 BUFFER_ADD
= high_direction
;
1132 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1137 static void flyswatter_reset(int trst
, int srst
)
1141 low_output
&= ~nTRST
;
1145 low_output
|= nTRST
;
1150 low_output
|= nSRST
;
1154 low_output
&= ~nSRST
;
1157 /* command "set data bits low byte" */
1159 BUFFER_ADD
= low_output
;
1160 BUFFER_ADD
= low_direction
;
1161 LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst
, srst
, low_output
, low_direction
);
1165 static void turtle_reset(int trst
, int srst
)
1171 low_output
|= nSRST
;
1175 low_output
&= ~nSRST
;
1178 /* command "set data bits low byte" */
1180 BUFFER_ADD
= low_output
;
1181 BUFFER_ADD
= low_direction
;
1182 LOG_DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", srst
, low_output
, low_direction
);
1186 static void comstick_reset(int trst
, int srst
)
1190 high_output
&= ~nTRST
;
1194 high_output
|= nTRST
;
1199 high_output
&= ~nSRST
;
1203 high_output
|= nSRST
;
1206 /* command "set data bits high byte" */
1208 BUFFER_ADD
= high_output
;
1209 BUFFER_ADD
= high_direction
;
1210 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1215 static void stm32stick_reset(int trst
, int srst
)
1219 high_output
&= ~nTRST
;
1223 high_output
|= nTRST
;
1228 low_output
&= ~nSRST
;
1232 low_output
|= nSRST
;
1235 /* command "set data bits low byte" */
1237 BUFFER_ADD
= low_output
;
1238 BUFFER_ADD
= low_direction
;
1240 /* command "set data bits high byte" */
1242 BUFFER_ADD
= high_output
;
1243 BUFFER_ADD
= high_direction
;
1244 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
,
1250 static void sheevaplug_reset(int trst
, int srst
)
1253 high_output
&= ~nTRST
;
1255 high_output
|= nTRST
;
1258 high_output
&= ~nSRSTnOE
;
1260 high_output
|= nSRSTnOE
;
1262 /* command "set data bits high byte" */
1264 BUFFER_ADD
= high_output
;
1265 BUFFER_ADD
= high_direction
;
1266 LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst
, srst
, high_output
, high_direction
);
1269 static int ft2232_execute_queue()
1271 jtag_command_t
* cmd
= jtag_command_queue
; /* currently processed command */
1273 int scan_size
; /* size of IR or DR scan */
1274 enum scan_type type
;
1276 int predicted_size
= 0;
1279 first_unsent
= cmd
; /* next command that has to be sent */
1282 /* return ERROR_OK, unless ft2232_send_and_recv reports a failed check
1283 * that wasn't handled by a caller-provided error handler
1287 ft2232_buffer_size
= 0;
1288 ft2232_expect_read
= 0;
1290 /* blink, if the current layout has that feature */
1298 case JTAG_END_STATE
:
1299 if (cmd
->cmd
.end_state
->end_state
!= TAP_INVALID
)
1300 ft2232_end_state(cmd
->cmd
.end_state
->end_state
);
1304 /* only send the maximum buffer size that FT2232C can handle */
1306 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1308 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1309 retval
= ERROR_JTAG_QUEUE_FAILED
;
1314 if ( (cmd
->cmd
.reset
->trst
== 1) || ( cmd
->cmd
.reset
->srst
&& (jtag_reset_config
& RESET_SRST_PULLS_TRST
) ) )
1316 tap_set_state(TAP_RESET
);
1318 layout
->reset(cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1321 #ifdef _DEBUG_JTAG_IO_
1322 LOG_DEBUG("trst: %i, srst: %i", cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
1327 /* only send the maximum buffer size that FT2232C can handle */
1329 if (tap_get_state() != TAP_IDLE
)
1330 predicted_size
+= 3;
1331 predicted_size
+= 3 * CEIL(cmd
->cmd
.runtest
->num_cycles
, 7);
1332 if ( (cmd
->cmd
.runtest
->end_state
!= TAP_INVALID
) && (cmd
->cmd
.runtest
->end_state
!= TAP_IDLE
) )
1333 predicted_size
+= 3;
1334 if ( (cmd
->cmd
.runtest
->end_state
== TAP_INVALID
) && (tap_get_end_state() != TAP_IDLE
) )
1335 predicted_size
+= 3;
1336 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1338 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1339 retval
= ERROR_JTAG_QUEUE_FAILED
;
1343 if (tap_get_state() != TAP_IDLE
)
1345 /* command "Clock Data to TMS/CS Pin (no Read)" */
1347 BUFFER_ADD
= 0x6; /* scan 7 bits */
1350 BUFFER_ADD
= tap_get_tms_path(tap_get_state(), TAP_IDLE
);
1351 tap_set_state(TAP_IDLE
);
1354 i
= cmd
->cmd
.runtest
->num_cycles
;
1357 /* command "Clock Data to TMS/CS Pin (no Read)" */
1361 BUFFER_ADD
= (i
> 7) ? 6 : (i
- 1);
1365 tap_set_state(TAP_IDLE
);
1366 i
-= (i
> 7) ? 7 : i
;
1367 /* LOG_DEBUG("added TMS scan (no read)"); */
1370 if (cmd
->cmd
.runtest
->end_state
!= TAP_INVALID
)
1371 ft2232_end_state(cmd
->cmd
.runtest
->end_state
);
1373 if ( tap_get_state() != tap_get_end_state() )
1375 /* command "Clock Data to TMS/CS Pin (no Read)" */
1380 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() );
1381 tap_set_state( tap_get_end_state() );
1382 /* LOG_DEBUG("added TMS scan (no read)"); */
1385 #ifdef _DEBUG_JTAG_IO_
1386 LOG_DEBUG( "runtest: %i, end in %s", cmd
->cmd
.runtest
->num_cycles
, tap_state_name( tap_get_end_state() ) );
1390 case JTAG_STATEMOVE
:
1391 /* only send the maximum buffer size that FT2232C can handle */
1393 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1395 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1396 retval
= ERROR_JTAG_QUEUE_FAILED
;
1400 if (cmd
->cmd
.statemove
->end_state
!= TAP_INVALID
)
1401 ft2232_end_state(cmd
->cmd
.statemove
->end_state
);
1403 /* command "Clock Data to TMS/CS Pin (no Read)" */
1406 BUFFER_ADD
= 0x6; /* scan 7 bits */
1409 BUFFER_ADD
= tap_get_tms_path( tap_get_state(), tap_get_end_state() );
1410 /* LOG_DEBUG("added TMS scan (no read)"); */
1411 tap_set_state( tap_get_end_state() );
1413 #ifdef _DEBUG_JTAG_IO_
1414 LOG_DEBUG( "statemove: %s", tap_state_name( tap_get_end_state() ) );
1419 /* only send the maximum buffer size that FT2232C can handle */
1420 predicted_size
= 3 * CEIL(cmd
->cmd
.pathmove
->num_states
, 7);
1421 if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1423 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1424 retval
= ERROR_JTAG_QUEUE_FAILED
;
1428 ft2232_add_pathmove(cmd
->cmd
.pathmove
);
1430 #ifdef _DEBUG_JTAG_IO_
1431 LOG_DEBUG( "pathmove: %i states, end in %s", cmd
->cmd
.pathmove
->num_states
,
1432 tap_state_name(cmd
->cmd
.pathmove
->path
[cmd
->cmd
.pathmove
->num_states
- 1]) );
1437 scan_size
= jtag_build_buffer(cmd
->cmd
.scan
, &buffer
);
1438 type
= jtag_scan_type(cmd
->cmd
.scan
);
1439 predicted_size
= ft2232_predict_scan_out(scan_size
, type
);
1440 if ( (predicted_size
+ 1) > FT2232_BUFFER_SIZE
)
1442 LOG_DEBUG("oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
1443 /* unsent commands before this */
1444 if (first_unsent
!= cmd
)
1445 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1446 retval
= ERROR_JTAG_QUEUE_FAILED
;
1448 /* current command */
1449 if (cmd
->cmd
.scan
->end_state
!= TAP_INVALID
)
1450 ft2232_end_state(cmd
->cmd
.scan
->end_state
);
1451 ft2232_large_scan(cmd
->cmd
.scan
, type
, buffer
, scan_size
);
1453 first_unsent
= cmd
->next
;
1458 else if (ft2232_buffer_size
+ predicted_size
+ 1 > FT2232_BUFFER_SIZE
)
1460 LOG_DEBUG("ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
1463 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1464 retval
= ERROR_JTAG_QUEUE_FAILED
;
1468 ft2232_expect_read
+= ft2232_predict_scan_in(scan_size
, type
);
1469 /* LOG_DEBUG("new read size: %i", ft2232_expect_read); */
1470 if (cmd
->cmd
.scan
->end_state
!= TAP_INVALID
)
1471 ft2232_end_state(cmd
->cmd
.scan
->end_state
);
1472 ft2232_add_scan(cmd
->cmd
.scan
->ir_scan
, type
, buffer
, scan_size
);
1476 #ifdef _DEBUG_JTAG_IO_
1477 LOG_DEBUG( "%s scan, %i bits, end in %s", (cmd
->cmd
.scan
->ir_scan
) ? "IR" : "DR", scan_size
,
1478 tap_state_name( tap_get_end_state() ) );
1483 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1484 retval
= ERROR_JTAG_QUEUE_FAILED
;
1485 first_unsent
= cmd
->next
;
1486 jtag_sleep(cmd
->cmd
.sleep
->us
);
1487 #ifdef _DEBUG_JTAG_IO_
1488 LOG_DEBUG( "sleep %i usec while in %s", cmd
->cmd
.sleep
->us
, tap_state_name( tap_get_state() ) );
1492 case JTAG_STABLECLOCKS
:
1494 /* this is only allowed while in a stable state. A check for a stable
1495 * state was done in jtag_add_clocks()
1497 if (ft2232_stableclocks(cmd
->cmd
.stableclocks
->num_cycles
, cmd
) != ERROR_OK
)
1498 retval
= ERROR_JTAG_QUEUE_FAILED
;
1499 #ifdef _DEBUG_JTAG_IO_
1500 LOG_DEBUG( "clocks %i while in %s", cmd
->cmd
.stableclocks
->num_cycles
, tap_state_name( tap_get_state() ) );
1505 LOG_ERROR("BUG: unknown JTAG command type encountered");
1512 if (require_send
> 0)
1513 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
1514 retval
= ERROR_JTAG_QUEUE_FAILED
;
1520 #if BUILD_FT2232_FTD2XX == 1
1521 static int ft2232_init_ftd2xx(u16 vid
, u16 pid
, int more
, int* try_more
)
1524 DWORD openex_flags
= 0;
1525 char* openex_string
= NULL
;
1528 LOG_DEBUG("'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)", ft2232_layout
, vid
, pid
);
1531 /* Add non-standard Vid/Pid to the linux driver */
1532 if ( ( status
= FT_SetVIDPID(vid
, pid
) ) != FT_OK
)
1534 LOG_WARNING("couldn't add %4.4x:%4.4x", vid
, pid
);
1538 if (ft2232_device_desc
&& ft2232_serial
)
1540 LOG_WARNING("can't open by device description and serial number, giving precedence to serial");
1541 ft2232_device_desc
= NULL
;
1544 if (ft2232_device_desc
)
1546 openex_string
= ft2232_device_desc
;
1547 openex_flags
= FT_OPEN_BY_DESCRIPTION
;
1549 else if (ft2232_serial
)
1551 openex_string
= ft2232_serial
;
1552 openex_flags
= FT_OPEN_BY_SERIAL_NUMBER
;
1556 LOG_ERROR("neither device description nor serial number specified");
1557 LOG_ERROR("please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
1559 return ERROR_JTAG_INIT_FAILED
;
1562 status
= FT_OpenEx(openex_string
, openex_flags
, &ftdih
);
1563 if( status
!= FT_OK
){
1564 // under Win32, the FTD2XX driver appends an "A" to the end
1565 // of the description, if we tried by the desc, then
1566 // try by the alternate "A" description.
1567 if( openex_string
== ft2232_device_desc
){
1568 // Try the alternate method.
1569 openex_string
= ft2232_device_desc_A
;
1570 status
= FT_OpenEx(openex_string
, openex_flags
, &ftdih
);
1571 if( status
== FT_OK
){
1572 // yea, the "alternate" method worked!
1574 // drat, give the user a meaningfull message.
1575 // telling the use we tried *BOTH* methods.
1576 LOG_WARNING("Unable to open FTDI Device tried: '%s' and '%s'\n",
1578 ft2232_device_desc_A
);
1583 if ( status
!= FT_OK
)
1589 LOG_WARNING("unable to open ftdi device (trying more): %lu", status
);
1591 return ERROR_JTAG_INIT_FAILED
;
1593 LOG_ERROR("unable to open ftdi device: %lu", status
);
1594 status
= FT_ListDevices(&num_devices
, NULL
, FT_LIST_NUMBER_ONLY
);
1595 if (status
== FT_OK
)
1597 char** desc_array
= malloc( sizeof(char*) * (num_devices
+ 1) );
1600 for (i
= 0; i
< num_devices
; i
++)
1601 desc_array
[i
] = malloc(64);
1603 desc_array
[num_devices
] = NULL
;
1605 status
= FT_ListDevices(desc_array
, &num_devices
, FT_LIST_ALL
| openex_flags
);
1607 if (status
== FT_OK
)
1609 LOG_ERROR("ListDevices: %lu\n", num_devices
);
1610 for (i
= 0; i
< num_devices
; i
++)
1611 LOG_ERROR("%i: \"%s\"", i
, desc_array
[i
]);
1614 for (i
= 0; i
< num_devices
; i
++)
1615 free(desc_array
[i
]);
1621 LOG_ERROR("ListDevices: NONE\n");
1623 return ERROR_JTAG_INIT_FAILED
;
1626 if ( ( status
= FT_SetLatencyTimer(ftdih
, ft2232_latency
) ) != FT_OK
)
1628 LOG_ERROR("unable to set latency timer: %lu", status
);
1629 return ERROR_JTAG_INIT_FAILED
;
1632 if ( ( status
= FT_GetLatencyTimer(ftdih
, &latency_timer
) ) != FT_OK
)
1634 LOG_ERROR("unable to get latency timer: %lu", status
);
1635 return ERROR_JTAG_INIT_FAILED
;
1639 LOG_DEBUG("current latency timer: %i", latency_timer
);
1642 if ( ( status
= FT_SetTimeouts(ftdih
, 5000, 5000) ) != FT_OK
)
1644 LOG_ERROR("unable to set timeouts: %lu", status
);
1645 return ERROR_JTAG_INIT_FAILED
;
1648 if ( ( status
= FT_SetBitMode(ftdih
, 0x0b, 2) ) != FT_OK
)
1650 LOG_ERROR("unable to enable bit i/o mode: %lu", status
);
1651 return ERROR_JTAG_INIT_FAILED
;
1658 static int ft2232_purge_ftd2xx(void)
1662 if ( ( status
= FT_Purge(ftdih
, FT_PURGE_RX
| FT_PURGE_TX
) ) != FT_OK
)
1664 LOG_ERROR("error purging ftd2xx device: %lu", status
);
1665 return ERROR_JTAG_INIT_FAILED
;
1672 #endif /* BUILD_FT2232_FTD2XX == 1 */
1674 #if BUILD_FT2232_LIBFTDI == 1
1675 static int ft2232_init_libftdi(u16 vid
, u16 pid
, int more
, int* try_more
)
1679 LOG_DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
1680 ft2232_layout
, vid
, pid
);
1682 if (ftdi_init(&ftdic
) < 0)
1683 return ERROR_JTAG_INIT_FAILED
;
1685 /* context, vendor id, product id */
1686 if (ftdi_usb_open_desc(&ftdic
, vid
, pid
, ft2232_device_desc
,
1690 LOG_WARNING("unable to open ftdi device (trying more): %s",
1693 LOG_ERROR("unable to open ftdi device: %s", ftdic
.error_str
);
1695 return ERROR_JTAG_INIT_FAILED
;
1698 if (ftdi_set_interface(&ftdic
, INTERFACE_A
) < 0)
1700 LOG_ERROR("unable to select FT2232 channel A: %s", ftdic
.error_str
);
1701 return ERROR_JTAG_INIT_FAILED
;
1704 if (ftdi_usb_reset(&ftdic
) < 0)
1706 LOG_ERROR("unable to reset ftdi device");
1707 return ERROR_JTAG_INIT_FAILED
;
1710 if (ftdi_set_latency_timer(&ftdic
, ft2232_latency
) < 0)
1712 LOG_ERROR("unable to set latency timer");
1713 return ERROR_JTAG_INIT_FAILED
;
1716 if (ftdi_get_latency_timer(&ftdic
, &latency_timer
) < 0)
1718 LOG_ERROR("unable to get latency timer");
1719 return ERROR_JTAG_INIT_FAILED
;
1723 LOG_DEBUG("current latency timer: %i", latency_timer
);
1726 ftdi_set_bitmode(&ftdic
, 0x0b, 2); /* ctx, JTAG I/O mask */
1732 static int ft2232_purge_libftdi(void)
1734 if (ftdi_usb_purge_buffers(&ftdic
) < 0)
1736 LOG_ERROR("ftdi_purge_buffers: %s", ftdic
.error_str
);
1737 return ERROR_JTAG_INIT_FAILED
;
1744 #endif /* BUILD_FT2232_LIBFTDI == 1 */
1746 static int ft2232_init(void)
1751 ft2232_layout_t
* cur_layout
= ft2232_layouts
;
1754 if ( (ft2232_layout
== NULL
) || (ft2232_layout
[0] == 0) )
1756 ft2232_layout
= "usbjtag";
1757 LOG_WARNING("No ft2232 layout specified, using default 'usbjtag'");
1760 while (cur_layout
->name
)
1762 if (strcmp(cur_layout
->name
, ft2232_layout
) == 0)
1764 layout
= cur_layout
;
1772 LOG_ERROR("No matching layout found for %s", ft2232_layout
);
1773 return ERROR_JTAG_INIT_FAILED
;
1779 * "more indicates that there are more IDs to try, so we should
1780 * not print an error for an ID mismatch (but for anything
1783 * try_more indicates that the error code returned indicates an
1784 * ID mismatch (and nothing else) and that we should proceeed
1785 * with the next ID pair.
1787 int more
= ft2232_vid
[i
+ 1] || ft2232_pid
[i
+ 1];
1790 #if BUILD_FT2232_FTD2XX == 1
1791 retval
= ft2232_init_ftd2xx(ft2232_vid
[i
], ft2232_pid
[i
],
1793 #elif BUILD_FT2232_LIBFTDI == 1
1794 retval
= ft2232_init_libftdi(ft2232_vid
[i
], ft2232_pid
[i
],
1799 if (!more
|| !try_more
)
1803 ft2232_buffer_size
= 0;
1804 ft2232_buffer
= malloc(FT2232_BUFFER_SIZE
);
1806 if (layout
->init() != ERROR_OK
)
1807 return ERROR_JTAG_INIT_FAILED
;
1809 ft2232_speed(jtag_speed
);
1811 buf
[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
1812 if ( ( ( retval
= ft2232_write(buf
, 1, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 1) )
1814 LOG_ERROR("couldn't write to FT2232 to disable loopback");
1815 return ERROR_JTAG_INIT_FAILED
;
1818 #if BUILD_FT2232_FTD2XX == 1
1819 return ft2232_purge_ftd2xx();
1820 #elif BUILD_FT2232_LIBFTDI == 1
1821 return ft2232_purge_libftdi();
1828 static int usbjtag_init(void)
1834 low_direction
= 0x0b;
1836 if (strcmp(ft2232_layout
, "usbjtag") == 0)
1843 else if (strcmp(ft2232_layout
, "signalyzer") == 0)
1850 else if (strcmp(ft2232_layout
, "evb_lm3s811") == 0)
1857 low_direction
= 0x8b;
1861 LOG_ERROR("BUG: usbjtag_init called for unknown layout '%s'", ft2232_layout
);
1862 return ERROR_JTAG_INIT_FAILED
;
1865 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1867 low_direction
&= ~nTRSTnOE
; /* nTRST input */
1868 low_output
&= ~nTRST
; /* nTRST = 0 */
1872 low_direction
|= nTRSTnOE
; /* nTRST output */
1873 low_output
|= nTRST
; /* nTRST = 1 */
1876 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1878 low_direction
|= nSRSTnOE
; /* nSRST output */
1879 low_output
|= nSRST
; /* nSRST = 1 */
1883 low_direction
&= ~nSRSTnOE
; /* nSRST input */
1884 low_output
&= ~nSRST
; /* nSRST = 0 */
1887 /* initialize low byte for jtag */
1888 buf
[0] = 0x80; /* command "set data bits low byte" */
1889 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, xRST high) */
1890 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
1891 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1893 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1895 LOG_ERROR("couldn't initialize FT2232 with 'USBJTAG' layout");
1896 return ERROR_JTAG_INIT_FAILED
;
1903 static int axm0432_jtag_init(void)
1909 low_direction
= 0x2b;
1911 /* initialize low byte for jtag */
1912 buf
[0] = 0x80; /* command "set data bits low byte" */
1913 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1914 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1915 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1917 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1919 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1920 return ERROR_JTAG_INIT_FAILED
;
1923 if (strcmp(layout
->name
, "axm0432_jtag") == 0)
1926 nTRSTnOE
= 0x0; /* No output enable for TRST*/
1928 nSRSTnOE
= 0x0; /* No output enable for SRST*/
1932 LOG_ERROR("BUG: axm0432_jtag_init called for non axm0432 layout");
1937 high_direction
= 0x0c;
1939 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
1941 LOG_ERROR("can't set nTRSTOE to push-pull on the Dicarlo jtag");
1945 high_output
|= nTRST
;
1948 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
1950 LOG_ERROR("can't set nSRST to push-pull on the Dicarlo jtag");
1954 high_output
|= nSRST
;
1957 /* initialize high port */
1958 buf
[0] = 0x82; /* command "set data bits high byte" */
1959 buf
[1] = high_output
; /* value */
1960 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
1961 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1963 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1965 LOG_ERROR("couldn't initialize FT2232 with 'Dicarlo' layout");
1966 return ERROR_JTAG_INIT_FAILED
;
1973 static int jtagkey_init(void)
1979 low_direction
= 0x1b;
1981 /* initialize low byte for jtag */
1982 buf
[0] = 0x80; /* command "set data bits low byte" */
1983 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1984 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1985 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
1987 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
1989 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1990 return ERROR_JTAG_INIT_FAILED
;
1993 if (strcmp(layout
->name
, "jtagkey") == 0)
2000 else if ( (strcmp(layout
->name
, "jtagkey_prototype_v1") == 0)
2001 || (strcmp(layout
->name
, "oocdlink") == 0) )
2010 LOG_ERROR("BUG: jtagkey_init called for non jtagkey layout");
2015 high_direction
= 0x0f;
2017 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2019 high_output
|= nTRSTnOE
;
2020 high_output
&= ~nTRST
;
2024 high_output
&= ~nTRSTnOE
;
2025 high_output
|= nTRST
;
2028 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2030 high_output
&= ~nSRSTnOE
;
2031 high_output
|= nSRST
;
2035 high_output
|= nSRSTnOE
;
2036 high_output
&= ~nSRST
;
2039 /* initialize high port */
2040 buf
[0] = 0x82; /* command "set data bits high byte" */
2041 buf
[1] = high_output
; /* value */
2042 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2043 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2045 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2047 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2048 return ERROR_JTAG_INIT_FAILED
;
2055 static int olimex_jtag_init(void)
2061 low_direction
= 0x1b;
2063 /* initialize low byte for jtag */
2064 buf
[0] = 0x80; /* command "set data bits low byte" */
2065 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2066 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2067 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2069 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2071 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2072 return ERROR_JTAG_INIT_FAILED
;
2078 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2081 high_direction
= 0x0f;
2083 if (jtag_reset_config
& RESET_TRST_OPEN_DRAIN
)
2085 high_output
|= nTRSTnOE
;
2086 high_output
&= ~nTRST
;
2090 high_output
&= ~nTRSTnOE
;
2091 high_output
|= nTRST
;
2094 if (jtag_reset_config
& RESET_SRST_PUSH_PULL
)
2096 LOG_ERROR("can't set nSRST to push-pull on the Olimex ARM-USB-OCD");
2100 high_output
&= ~nSRST
;
2103 /* turn red LED on */
2104 high_output
|= 0x08;
2106 /* initialize high port */
2107 buf
[0] = 0x82; /* command "set data bits high byte" */
2108 buf
[1] = high_output
; /* value */
2109 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2110 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2112 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2114 LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
2115 return ERROR_JTAG_INIT_FAILED
;
2122 static int flyswatter_init(void)
2128 low_direction
= 0xfb;
2130 /* initialize low byte for jtag */
2131 buf
[0] = 0x80; /* command "set data bits low byte" */
2132 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2133 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE[12]=out, n[ST]srst=out */
2134 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2136 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2138 LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
2139 return ERROR_JTAG_INIT_FAILED
;
2143 nTRSTnOE
= 0x0; /* not output enable for nTRST */
2145 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2148 high_direction
= 0x0c;
2150 /* turn red LED3 on, LED2 off */
2151 high_output
|= 0x08;
2153 /* initialize high port */
2154 buf
[0] = 0x82; /* command "set data bits high byte" */
2155 buf
[1] = high_output
; /* value */
2156 buf
[2] = high_direction
; /* all outputs (xRST and xRSTnOE) */
2157 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2159 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2161 LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
2162 return ERROR_JTAG_INIT_FAILED
;
2169 static int turtle_init(void)
2175 low_direction
= 0x5b;
2177 /* initialize low byte for jtag */
2178 buf
[0] = 0x80; /* command "set data bits low byte" */
2179 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2180 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2181 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2183 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2185 LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
2186 return ERROR_JTAG_INIT_FAILED
;
2192 high_direction
= 0x0C;
2194 /* initialize high port */
2195 buf
[0] = 0x82; /* command "set data bits high byte" */
2196 buf
[1] = high_output
;
2197 buf
[2] = high_direction
;
2198 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2200 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2202 LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
2203 return ERROR_JTAG_INIT_FAILED
;
2210 static int comstick_init(void)
2216 low_direction
= 0x0b;
2218 /* initialize low byte for jtag */
2219 buf
[0] = 0x80; /* command "set data bits low byte" */
2220 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2221 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2222 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2224 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2226 LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
2227 return ERROR_JTAG_INIT_FAILED
;
2231 nTRSTnOE
= 0x00; /* no output enable for nTRST */
2233 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2236 high_direction
= 0x03;
2238 /* initialize high port */
2239 buf
[0] = 0x82; /* command "set data bits high byte" */
2240 buf
[1] = high_output
;
2241 buf
[2] = high_direction
;
2242 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2244 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2246 LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
2247 return ERROR_JTAG_INIT_FAILED
;
2254 static int stm32stick_init(void)
2260 low_direction
= 0x8b;
2262 /* initialize low byte for jtag */
2263 buf
[0] = 0x80; /* command "set data bits low byte" */
2264 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2265 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
2266 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2268 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2270 LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
2271 return ERROR_JTAG_INIT_FAILED
;
2275 nTRSTnOE
= 0x00; /* no output enable for nTRST */
2277 nSRSTnOE
= 0x00; /* no output enable for nSRST */
2280 high_direction
= 0x03;
2282 /* initialize high port */
2283 buf
[0] = 0x82; /* command "set data bits high byte" */
2284 buf
[1] = high_output
;
2285 buf
[2] = high_direction
;
2286 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2288 if ( ( ( ft2232_write(buf
, 3, &bytes_written
) ) != ERROR_OK
) || (bytes_written
!= 3) )
2290 LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
2291 return ERROR_JTAG_INIT_FAILED
;
2298 static int sheevaplug_init(void)
2304 low_direction
= 0x1b;
2306 /* initialize low byte for jtag */
2307 buf
[0] = 0x80; /* command "set data bits low byte" */
2308 buf
[1] = low_output
; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
2309 buf
[2] = low_direction
; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
2310 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2312 if (((ft2232_write(buf
, 3, &bytes_written
)) != ERROR_OK
) || (bytes_written
!= 3))
2314 LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
2315 return ERROR_JTAG_INIT_FAILED
;
2324 high_direction
= 0x0f;
2326 /* nTRST is always push-pull */
2327 high_output
&= ~nTRSTnOE
;
2328 high_output
|= nTRST
;
2330 /* nSRST is always open-drain */
2331 high_output
|= nSRSTnOE
;
2332 high_output
&= ~nSRST
;
2334 /* initialize high port */
2335 buf
[0] = 0x82; /* command "set data bits high byte" */
2336 buf
[1] = high_output
; /* value */
2337 buf
[2] = high_direction
; /* all outputs - xRST */
2338 LOG_DEBUG("%2.2x %2.2x %2.2x", buf
[0], buf
[1], buf
[2]);
2340 if (((ft2232_write(buf
, 3, &bytes_written
)) != ERROR_OK
) || (bytes_written
!= 3))
2342 LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
2343 return ERROR_JTAG_INIT_FAILED
;
2349 static void olimex_jtag_blink(void)
2351 /* Olimex ARM-USB-OCD has a LED connected to ACBUS3
2352 * ACBUS3 is bit 3 of the GPIOH port
2354 if (high_output
& 0x08)
2356 /* set port pin high */
2357 high_output
&= 0x07;
2361 /* set port pin low */
2362 high_output
|= 0x08;
2366 BUFFER_ADD
= high_output
;
2367 BUFFER_ADD
= high_direction
;
2371 static void flyswatter_jtag_blink(void)
2374 * Flyswatter has two LEDs connected to ACBUS2 and ACBUS3
2376 high_output
^= 0x0c;
2379 BUFFER_ADD
= high_output
;
2380 BUFFER_ADD
= high_direction
;
2384 static void turtle_jtag_blink(void)
2387 * Turtelizer2 has two LEDs connected to ACBUS2 and ACBUS3
2389 if (high_output
& 0x08)
2399 BUFFER_ADD
= high_output
;
2400 BUFFER_ADD
= high_direction
;
2404 static int ft2232_quit(void)
2406 #if BUILD_FT2232_FTD2XX == 1
2409 status
= FT_Close(ftdih
);
2410 #elif BUILD_FT2232_LIBFTDI == 1
2411 ftdi_disable_bitbang(&ftdic
);
2413 ftdi_usb_close(&ftdic
);
2415 ftdi_deinit(&ftdic
);
2418 free(ft2232_buffer
);
2419 ft2232_buffer
= NULL
;
2425 static int ft2232_handle_device_desc_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2431 ft2232_device_desc
= strdup(args
[0]);
2432 cp
= strchr( ft2232_device_desc
, 0 );
2433 // under Win32, the FTD2XX driver appends an "A" to the end
2434 // of the description, this examines the given desc
2435 // and creates the 'missing' _A or non_A variable.
2436 if( (cp
[-1] == 'A') && (cp
[-2]==' ') ){
2437 // it was, so make this the "A" version.
2438 ft2232_device_desc_A
= ft2232_device_desc
;
2439 // and *CREATE* the non-A version.
2440 strcpy( buf
, ft2232_device_desc
);
2441 cp
= strchr( buf
, 0 );
2443 ft2232_device_desc
= strdup( buf
);
2445 // <space>A not defined
2447 sprintf( buf
, "%s A", ft2232_device_desc
);
2448 ft2232_device_desc_A
= strdup( buf
);
2453 LOG_ERROR("expected exactly one argument to ft2232_device_desc <description>");
2460 static int ft2232_handle_serial_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2464 ft2232_serial
= strdup(args
[0]);
2468 LOG_ERROR("expected exactly one argument to ft2232_serial <serial-number>");
2475 static int ft2232_handle_layout_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2480 ft2232_layout
= malloc(strlen(args
[0]) + 1);
2481 strcpy(ft2232_layout
, args
[0]);
2487 static int ft2232_handle_vid_pid_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2491 if (argc
> MAX_USB_IDS
* 2)
2493 LOG_WARNING("ignoring extra IDs in ft2232_vid_pid "
2494 "(maximum is %d pairs)", MAX_USB_IDS
);
2495 argc
= MAX_USB_IDS
* 2;
2497 if ( argc
< 2 || (argc
& 1) )
2499 LOG_WARNING("incomplete ft2232_vid_pid configuration directive");
2504 for (i
= 0; i
+ 1 < argc
; i
+= 2)
2506 ft2232_vid
[i
>> 1] = strtol(args
[i
], NULL
, 0);
2507 ft2232_pid
[i
>> 1] = strtol(args
[i
+ 1], NULL
, 0);
2511 * Explicitly terminate, in case there are multiples instances of
2514 ft2232_vid
[i
>> 1] = ft2232_pid
[i
>> 1] = 0;
2520 static int ft2232_handle_latency_command(struct command_context_s
* cmd_ctx
, char* cmd
, char** args
, int argc
)
2524 ft2232_latency
= atoi(args
[0]);
2528 LOG_ERROR("expected exactly one argument to ft2232_latency <ms>");
2535 static int ft2232_stableclocks(int num_cycles
, jtag_command_t
* cmd
)
2539 /* 7 bits of either ones or zeros. */
2540 u8 tms
= (tap_get_state() == TAP_RESET
? 0x7F : 0x00);
2542 while (num_cycles
> 0)
2544 /* the command 0x4b, "Clock Data to TMS/CS Pin (no Read)" handles
2545 * at most 7 bits per invocation. Here we invoke it potentially
2548 int bitcount_per_command
= (num_cycles
> 7) ? 7 : num_cycles
;
2550 if (ft2232_buffer_size
+ 3 >= FT2232_BUFFER_SIZE
)
2552 if (ft2232_send_and_recv(first_unsent
, cmd
) != ERROR_OK
)
2553 retval
= ERROR_JTAG_QUEUE_FAILED
;
2558 /* command "Clock Data to TMS/CS Pin (no Read)" */
2562 BUFFER_ADD
= bitcount_per_command
- 1;
2564 /* TMS data bits are either all zeros or ones to stay in the current stable state */
2569 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)