93 #if (BUILD_FT2232_FTD2XX == 1 && BUILD_FT2232_LIBFTDI == 1)
94 #error "BUILD_FT2232_FTD2XX && BUILD_FT2232_LIBFTDI are mutually exclusive"
95 #elif (BUILD_FT2232_FTD2XX != 1 && BUILD_FT2232_LIBFTDI != 1)
96 #error "BUILD_FT2232_FTD2XX || BUILD_FT2232_LIBFTDI must be chosen"
100 #if BUILD_FT2232_FTD2XX == 1
112 #elif BUILD_FT2232_LIBFTDI == 1
117 #define FTDI_x232H_MAX_TCK 30000
119 #define FTDI_2232C_MAX_TCK 6000
121 #define RTCK_SPEED -1
132 #define LIBFTDI_READ_RETRY_COUNT 2000
134 #ifndef BUILD_FT2232_HIGHSPEED
135 #if BUILD_FT2232_FTD2XX == 1
136 enum { FT_DEVICE_2232H = 6, FT_DEVICE_4232H, FT_DEVICE_232H };
137 #elif BUILD_FT2232_LIBFTDI == 1
138 enum ftdi_chip_type { TYPE_2232H = 4, TYPE_4232H = 5, TYPE_232H = 6 };
161 #define MAX_USB_IDS 8
241 { .name =
"jtagkey_prototype_v1",
245 { .name =
"oocdlink",
249 { .name =
"signalyzer",
253 { .name =
"evb_lm3s811",
257 { .name =
"luminary_icdi",
261 { .name =
"olimex-jtag",
266 { .name =
"flyswatter",
271 { .name =
"flyswatter2",
276 { .name =
"minimodule",
280 { .name =
"turtelizer2",
285 { .name =
"comstick",
289 { .name =
"stm32stick",
293 { .name =
"axm0432_jtag",
297 { .name =
"sheevaplug",
309 { .name =
"signalyzer-h",
319 { .name =
"redbee-econotag",
323 { .name =
"redbee-usb",
326 .channel = INTERFACE_B,
332 .channel = INTERFACE_B,
334 { .name =
"flossjtag",
339 { .name =
"xds100v2",
343 { .name =
"digilent-hs1",
346 .channel = INTERFACE_A,
373 #if BUILD_FT2232_FTD2XX == 1
374 static FT_HANDLE ftdih;
375 static FT_DEVICE ftdi_device;
376 #elif BUILD_FT2232_LIBFTDI == 1
377 static struct ftdi_context ftdic;
397 #if BUILD_FT2232_FTD2XX == 1
398 #define FT2232_BUFFER_READ_QUEUE_SIZE (64*64)
400 #define FT2232_BUFFER_READ_QUEUE_SIZE (64*4)
403 #define FT2232_BUFFER_SIZE 131072
450 static void clock_tms(uint8_t mpsse_cmd,
int tms_bits,
int tms_count,
bool tdi_bit)
456 assert(tms_count > 0);
458 DEBUG_JTAG_IO(
"mpsse cmd=%02x, tms_bits = 0x%08x, bit_count=%d",
459 mpsse_cmd, tms_bits, tms_count);
461 for (tms_byte = tms_ndx = i = 0; i < tms_count; ++i, tms_bits >>= 1) {
462 bool bit = tms_bits & 1;
465 tms_byte |= (1 << tms_ndx);
475 if (tms_ndx == 7 || i == tms_count-1) {
494 return ((bit_count + 6)/7) * 3;
522 static int ft2232_write(uint8_t *buf,
int size, uint32_t *bytes_written)
524 #if BUILD_FT2232_FTD2XX == 1
526 DWORD dw_bytes_written = 0;
527 status = FT_Write(ftdih, buf, size, &dw_bytes_written);
528 if (status != FT_OK) {
529 *bytes_written = dw_bytes_written;
530 LOG_ERROR(
"FT_Write returned: %s", ftd2xx_status_string(status));
533 *bytes_written = dw_bytes_written;
535 #elif BUILD_FT2232_LIBFTDI == 1
536 int retval = ftdi_write_data(&ftdic, buf, size);
539 LOG_ERROR(
"ftdi_write_data: %s", ftdi_get_error_string(&ftdic));
542 *bytes_written = retval;
546 if (*bytes_written != (uint32_t)size)
552 static int ft2232_read(uint8_t *buf, uint32_t size, uint32_t *bytes_read)
554 #if BUILD_FT2232_FTD2XX == 1
560 while ((*bytes_read < size) && timeout--) {
561 status = FT_Read(ftdih, buf + *bytes_read, size -
562 *bytes_read, &dw_bytes_read);
563 if (status != FT_OK) {
565 LOG_ERROR(
"FT_Read returned: %s", ftd2xx_status_string(status));
568 *bytes_read += dw_bytes_read;
571 #elif BUILD_FT2232_LIBFTDI == 1
576 while ((*bytes_read < size) && timeout--) {
577 retval = ftdi_read_data(&ftdic, buf + *bytes_read, size - *bytes_read);
580 LOG_ERROR(
"ftdi_read_data: %s", ftdi_get_error_string(&ftdic));
583 *bytes_read += retval;
588 if (*bytes_read < size) {
589 LOG_ERROR(
"couldn't read enough bytes from "
590 "FT2232 device (%i < %i)",
591 (
unsigned)*bytes_read,
601 #if BUILD_FT2232_FTD2XX == 1
602 return (ftdi_device == FT_DEVICE_2232H) || (ftdi_device == FT_DEVICE_4232H)
603 #ifdef HAS_ENUM_FT232H
604 || (ftdi_device == FT_DEVICE_232H)
607 #elif BUILD_FT2232_LIBFTDI == 1
608 return (ftdi_device == TYPE_2232H || ftdi_device == TYPE_4232H
609 #ifdef HAS_ENUM_FT232H
610 || ftdi_device == TYPE_232H
624 uint8_t buf = enable ? 0x96 : 0x97;
627 uint32_t bytes_written;
630 retval =
ft2232_write(&buf,
sizeof(buf), &bytes_written);
632 LOG_ERROR(
"couldn't write command to %s adaptive clocking"
633 , enable ?
"enable" :
"disable");
647 uint32_t bytes_written;
648 uint8_t buf = enable ? 0x8b : 0x8a;
651 LOG_ERROR(
"couldn't write command to %s clk divide by 5"
652 , enable ?
"enable" :
"disable");
665 uint32_t bytes_written;
671 else if (enable_adaptive_clocking) {
672 LOG_ERROR(
"ft2232 device %lu does not support RTCK"
673 , (
long unsigned int)ftdi_device);
677 if ((enable_adaptive_clocking) || (
ERROR_OK != retval))
681 buf[1] = speed & 0xff;
682 buf[2] = (speed >> 8) & 0xff;
684 LOG_DEBUG(
"%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
685 retval =
ft2232_write(buf,
sizeof(buf), &bytes_written);
687 LOG_ERROR(
"couldn't set FT2232 TCK speed");
732 *jtag_speed = *jtag_speed / 10;
739 if (*jtag_speed > 0xFFFF)
740 *jtag_speed = 0xFFFF;
757 int num_bytes = (scan_size + 7) / 8;
758 int bits_left = scan_size;
761 while (num_bytes-- > 1) {
766 buffer[cur_byte] = 0x0;
775 buffer[cur_byte] = (buffer[cur_byte] | (((
buffer_read()) << 1) & 0x80)) >> (8 - bits_left);
785 line_p += snprintf(line_p,
786 sizeof(line) - (line_p - line),
806 uint32_t bytes_written = 0;
807 uint32_t bytes_read = 0;
809 #ifdef _DEBUG_USB_IO_
810 struct timeval start, inter, inter2, end;
811 struct timeval d_inter, d_inter2, d_end;
814 #ifdef _DEBUG_USB_COMMS_
819 #ifdef _DEBUG_USB_IO_
825 LOG_ERROR(
"couldn't write MPSSE commands to FT2232");
829 #ifdef _DEBUG_USB_IO_
838 #ifdef _DEBUG_USB_IO_
848 #ifdef _DEBUG_USB_IO_
855 LOG_INFO(
"inter: %u.%06u, inter2: %u.%06u end: %u.%06u",
865 "ft2232_buffer_size (%i) "
875 #ifdef _DEBUG_USB_COMMS_
876 LOG_DEBUG(
"read buffer (%i retries): %i bytes",
892 while (cmd != last) {
931 assert((
unsigned) num_states <= 32u);
937 unsigned char tms_byte = 0;
939 int num_states_batch = num_states > 7 ? 7 : num_states;
947 while (num_states_batch--) {
957 "TAP state transition",
975 int num_bytes = (scan_size + 7) / 8;
976 int bits_left = scan_size;
989 while (num_bytes > 1) {
1005 thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
1006 num_bytes -= thisrun_bytes;
1013 while (thisrun_bytes-- > 0) {
1018 bits_left -= 8 * (thisrun_bytes);
1023 last_bit = (buffer[cur_byte] >> (bits_left - 1)) & 0x1;
1028 if (bits_left > 1) {
1088 clock_tms(mpsse_cmd, tms_bits, tms_count, last_bit);
1100 int num_bytes = (scan_size + 7) / 8;
1101 int bits_left = scan_size;
1104 uint8_t *receive_buffer = malloc(
DIV_ROUND_UP(scan_size, 8));
1105 uint8_t *receive_pointer = receive_buffer;
1106 uint32_t bytes_written;
1107 uint32_t bytes_read;
1109 int thisrun_read = 0;
1111 if (!receive_buffer) {
1117 LOG_ERROR(
"BUG: large IR scans are not supported");
1126 LOG_ERROR(
"couldn't write MPSSE commands to FT2232");
1129 LOG_DEBUG(
"ft2232_buffer_size: %i, bytes_written: %i",
1134 while (num_bytes > 1) {
1151 thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
1152 thisrun_read = thisrun_bytes;
1153 num_bytes -= thisrun_bytes;
1159 while (thisrun_bytes-- > 0) {
1165 bits_left -= 8 * (thisrun_bytes);
1169 LOG_ERROR(
"couldn't write MPSSE commands to FT2232");
1172 LOG_DEBUG(
"ft2232_buffer_size: %i, bytes_written: %i",
1174 (
int)bytes_written);
1178 retval =
ft2232_read(receive_pointer, thisrun_read, &bytes_read);
1183 LOG_DEBUG(
"thisrun_read: %i, bytes_read: %i",
1186 receive_pointer += bytes_read;
1194 last_bit = (buffer[cur_byte] >> (bits_left - 1)) & 0x1;
1199 if (bits_left > 1) {
1254 clock_tms(mpsse_cmd, tms_bits, tms_count, last_bit);
1262 LOG_ERROR(
"couldn't write MPSSE commands to FT2232");
1265 LOG_DEBUG(
"ft2232_buffer_size: %i, bytes_written: %i",
1267 (
int)bytes_written);
1271 retval =
ft2232_read(receive_pointer, thisrun_read, &bytes_read);
1276 LOG_DEBUG(
"thisrun_read: %i, bytes_read: %i",
1281 free(receive_buffer);
1288 int predicted_size = 3;
1289 int num_bytes = (scan_size - 1) / 8;
1300 predicted_size += ((scan_size - 1) % 8) ? 2 : 0;
1303 predicted_size += num_bytes +
DIV_ROUND_UP(num_bytes, 65536) * 3;
1306 predicted_size += ((scan_size - 1) % 8) ? 3 : 0;
1309 return predicted_size;
1314 int predicted_size = 0;
1322 predicted_size += ((scan_size - 1) % 8) ? 1 : 0;
1325 predicted_size += 1;
1330 return predicted_size;
1342 }
else if (trst == 0) {
1355 }
else if (srst == 0) {
1376 }
else if (trst == 0) {
1388 }
else if (srst == 0) {
1399 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
1414 }
else if (trst == 0) {
1430 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
1442 }
else if (trst == 0)
1454 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
1477 LOG_DEBUG(
"trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
1505 LOG_DEBUG(
"trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
1515 LOG_ERROR(
"Can't assert TRST: the adapter lacks this signal");
1526 LOG_DEBUG(
"srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
1548 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
1576 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
1599 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
1611 }
else if (trst == 0)
1623 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, "
1624 "high_direction: 0x%2.2x", trst, srst,
high_output,
1633 }
else if (trst == 0)
1645 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, "
1646 "high_direction: 0x%2.2x", trst, srst,
high_output,
1654 int predicted_size = 0;
1664 predicted_size += 3;
1667 predicted_size += 3;
1669 predicted_size += 3;
1693 i -= (i > 7) ? 7 : i;
1711 int predicted_size = 0;
1781 if (num_bits <= 6) {
1796 count = (num_bits > 4) ? 4 : num_bits;
1812 int predicted_size = 0;
1818 DEBUG_JTAG_IO(
"pathmove: %i states, current: %s end: %s", num_states,
1842 int predicted_size = 0;
1853 LOG_DEBUG(
"oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
1855 if (first_unsent != cmd)
1863 first_unsent = cmd->
next;
1869 "ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
1894 int predicted_size = 0;
1930 first_unsent = cmd->
next;
1958 switch (cmd->
type) {
1984 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
2024 LOG_DEBUG(
"read buffer size looks too high %d/%d",
2040 #if BUILD_FT2232_FTD2XX == 1
2041 static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid,
int more,
int *try_more)
2045 char SerialNumber[16];
2046 char Description[64];
2047 DWORD openex_flags = 0;
2048 char *openex_string =
NULL;
2049 uint8_t latency_timer;
2051 if (layout ==
NULL) {
2056 LOG_DEBUG(
"'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)",
2057 layout->
name, vid, pid);
2061 status = FT_SetVIDPID(vid, pid);
2062 if (status != FT_OK)
2063 LOG_WARNING(
"couldn't add %4.4x:%4.4x", vid, pid);
2069 "can't open by device description and serial number, giving precedence to serial");
2075 openex_flags = FT_OPEN_BY_DESCRIPTION;
2078 openex_flags = FT_OPEN_BY_SERIAL_NUMBER;
2080 LOG_ERROR(
"neither device description nor serial number specified");
2082 "please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
2087 status = FT_OpenEx(openex_string, openex_flags, &ftdih);
2088 if (status != FT_OK) {
2095 status = FT_OpenEx(openex_string, openex_flags, &ftdih);
2096 if (status == FT_OK) {
2101 LOG_WARNING(
"Unable to open FTDI Device tried: '%s' and '%s'",
2108 if (status != FT_OK) {
2112 LOG_WARNING(
"unable to open ftdi device (trying more): %s",
2113 ftd2xx_status_string(status));
2117 LOG_ERROR(
"unable to open ftdi device: %s",
2118 ftd2xx_status_string(status));
2119 status = FT_ListDevices(&num_devices,
NULL, FT_LIST_NUMBER_ONLY);
2120 if (status == FT_OK) {
2121 char **desc_array = malloc(
sizeof(
char *) * (num_devices + 1));
2124 for (i = 0; i < num_devices; i++)
2125 desc_array[i] = malloc(64);
2127 desc_array[num_devices] =
NULL;
2129 status = FT_ListDevices(desc_array, &num_devices, FT_LIST_ALL | openex_flags);
2131 if (status == FT_OK) {
2132 LOG_ERROR(
"ListDevices: %" PRIu32, (uint32_t)num_devices);
2133 for (i = 0; i < num_devices; i++)
2134 LOG_ERROR(
"%" PRIu32
": \"%s\"", i, desc_array[i]);
2137 for (i = 0; i < num_devices; i++)
2138 free(desc_array[i]);
2147 if (status != FT_OK) {
2148 LOG_ERROR(
"unable to set latency timer: %s",
2149 ftd2xx_status_string(status));
2153 status = FT_GetLatencyTimer(ftdih, &latency_timer);
2154 if (status != FT_OK) {
2159 status = FT_GetDriverVersion(ftdih, &dw_version);
2160 LOG_ERROR(
"unable to get latency timer: %s",
2161 ftd2xx_status_string(status));
2163 if ((status == FT_OK) && (dw_version == 0x10004)) {
2164 LOG_ERROR(
"ftd2xx 1.04 detected - this has known issues " \
2165 "with FT_GetLatencyTimer, upgrade to a newer version");
2169 LOG_DEBUG(
"current latency timer: %i", latency_timer);
2171 status = FT_SetTimeouts(ftdih, 5000, 5000);
2172 if (status != FT_OK) {
2174 ftd2xx_status_string(status));
2178 status = FT_SetBitMode(ftdih, 0x0b, 2);
2179 if (status != FT_OK) {
2180 LOG_ERROR(
"unable to enable bit i/o mode: %s",
2181 ftd2xx_status_string(status));
2185 status = FT_GetDeviceInfo(ftdih, &ftdi_device, &deviceID,
2186 SerialNumber, Description,
NULL);
2187 if (status != FT_OK) {
2188 LOG_ERROR(
"unable to get FT_GetDeviceInfo: %s",
2189 ftd2xx_status_string(status));
2192 static const char *type_str[] = {
2193 "BM",
"AM",
"100AX",
"UNKNOWN",
"2232C",
"232R",
"2232H",
"4232H",
"232H"
2195 unsigned no_of_known_types =
ARRAY_SIZE(type_str) - 1;
2196 unsigned type_index = ((unsigned)ftdi_device <= no_of_known_types)
2197 ? ftdi_device : FT_DEVICE_UNKNOWN;
2198 LOG_INFO(
"device: %" PRIu32
" \"%s\"", (uint32_t)ftdi_device, type_str[type_index]);
2199 LOG_INFO(
"deviceID: %" PRIu32, (uint32_t)deviceID);
2200 LOG_INFO(
"SerialNumber: %s", SerialNumber);
2201 LOG_INFO(
"Description: %s", Description);
2207 static int ft2232_purge_ftd2xx(
void)
2211 status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX);
2212 if (status != FT_OK) {
2213 LOG_ERROR(
"error purging ftd2xx device: %s",
2214 ftd2xx_status_string(status));
2223 #if BUILD_FT2232_LIBFTDI == 1
2224 static int ft2232_init_libftdi(uint16_t vid, uint16_t pid,
int more,
int *try_more,
int channel)
2226 uint8_t latency_timer;
2228 if (layout ==
NULL) {
2233 LOG_DEBUG(
"'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
2234 layout->
name, vid, pid);
2236 if (ftdi_init(&ftdic) < 0)
2240 if (channel == INTERFACE_ANY)
2241 channel = INTERFACE_A;
2242 if (ftdi_set_interface(&ftdic, channel) < 0) {
2243 LOG_ERROR(
"unable to select FT2232 channel A: %s", ftdic.error_str);
2250 LOG_WARNING(
"unable to open ftdi device (trying more): %s",
2253 LOG_ERROR(
"unable to open ftdi device: %s", ftdic.error_str);
2259 if (ftdi_usb_reset(&ftdic) < 0) {
2260 LOG_ERROR(
"unable to reset ftdi device");
2265 LOG_ERROR(
"unable to set latency timer");
2269 if (ftdi_get_latency_timer(&ftdic, &latency_timer) < 0) {
2270 LOG_ERROR(
"unable to get latency timer");
2273 LOG_DEBUG(
"current latency timer: %i", latency_timer);
2275 ftdi_set_bitmode(&ftdic, 0x0b, 2);
2277 ftdi_device = ftdic.type;
2278 static const char *type_str[] = {
2279 "AM",
"BM",
"2232C",
"R",
"2232H",
"4232H",
"232H",
"Unknown"
2281 unsigned no_of_known_types =
ARRAY_SIZE(type_str) - 1;
2282 unsigned type_index = ((unsigned)ftdi_device < no_of_known_types)
2283 ? ftdi_device : no_of_known_types;
2284 LOG_DEBUG(
"FTDI chip type: %i \"%s\"", (
int)ftdi_device, type_str[type_index]);
2288 static int ft2232_purge_libftdi(
void)
2290 if (ftdi_usb_purge_buffers(&ftdic) < 0) {
2291 LOG_ERROR(
"ftdi_purge_buffers: %s", ftdic.error_str);
2303 uint32_t bytes_written;
2309 LOG_DEBUG(
"%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
2312 LOG_ERROR(
"couldn't initialize data bits low byte");
2322 uint32_t bytes_written;
2328 LOG_DEBUG(
"%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
2331 LOG_ERROR(
"couldn't initialize data bits high byte");
2342 uint32_t bytes_written;
2344 LOG_WARNING(
"Using DEPRECATED interface driver 'ft2232'");
2346 LOG_INFO(
"Consider using the 'ftdi' interface driver, with configuration files in interface/ftdi/...");
2350 LOG_DEBUG(
"ft2232 interface using 7 step jtag state transitions");
2352 LOG_DEBUG(
"ft2232 interface using shortest path jtag state transitions");
2353 if (layout ==
NULL) {
2358 for (
int i = 0; 1; i++) {
2371 #if BUILD_FT2232_FTD2XX == 1
2374 #elif BUILD_FT2232_LIBFTDI == 1
2380 if (!more || !try_more)
2391 #ifndef BUILD_FT2232_HIGHSPEED
2392 #if BUILD_FT2232_FTD2XX == 1
2394 "High Speed device found - You need a newer FTD2XX driver (version 2.04.16 or later)");
2395 #elif BUILD_FT2232_LIBFTDI == 1
2397 "High Speed device found - You need a newer libftdi version (0.16 or later)");
2408 LOG_ERROR(
"couldn't write to FT2232 to disable loopback");
2412 #if BUILD_FT2232_FTD2XX == 1
2413 return ft2232_purge_ftd2xx();
2414 #elif BUILD_FT2232_LIBFTDI == 1
2415 return ft2232_purge_libftdi();
2455 LOG_ERROR(
"couldn't initialize FT2232 DBUS");
2518 #define ICDI_JTAG_EN (1 << 7)
2519 #define ICDI_DBG_ENn (1 << 6)
2520 #define ICDI_SRST (1 << 5)
2524 #define ICDI_SWO_EN (1 << 4)
2525 #define ICDI_TX_SWO (1 << 1)
2526 #define ICDI_VCP_RX (1 << 0)
2558 LOG_ERROR(
"couldn't initialize FT2232 with 'JTAGkey' layout");
2562 if (strcmp(layout->
name,
"axm0432_jtag") == 0) {
2568 LOG_ERROR(
"BUG: axm0432_jtag_init called for non axm0432 layout");
2577 LOG_ERROR(
"can't set nTRSTOE to push-pull on the Dicarlo jtag");
2582 LOG_ERROR(
"can't set nSRST to push-pull on the Dicarlo jtag");
2588 LOG_ERROR(
"couldn't initialize FT2232 with 'Dicarlo' layout");
2602 LOG_ERROR(
"couldn't initialize FT2232 with 'redbee' layout");
2616 LOG_ERROR(
"can't set nTRSTOE to push-pull on redbee");
2621 LOG_ERROR(
"can't set nSRST to push-pull on redbee");
2627 LOG_ERROR(
"couldn't initialize FT2232 with 'redbee' layout");
2641 LOG_ERROR(
"couldn't initialize FT2232 with 'JTAGkey' layout");
2645 if (strcmp(layout->
name,
"jtagkey") == 0) {
2650 }
else if ((strcmp(layout->
name,
"jtagkey_prototype_v1") == 0)
2651 || (strcmp(layout->
name,
"oocdlink") == 0)) {
2657 LOG_ERROR(
"BUG: jtagkey_init called for non jtagkey layout");
2683 LOG_ERROR(
"couldn't initialize FT2232 with 'JTAGkey' layout");
2697 LOG_ERROR(
"couldn't initialize FT2232 with 'Olimex' layout");
2719 LOG_ERROR(
"can't set nSRST to push-pull on the Olimex ARM-USB-OCD");
2728 LOG_ERROR(
"couldn't initialize FT2232 with 'Olimex' layout");
2740 if ((rev < 0) || (rev > 3)) {
2741 LOG_ERROR(
"bogus 'flyswatter' revision supplied (%i)", rev);
2750 LOG_ERROR(
"couldn't initialize FT2232 with 'flyswatter' layout");
2771 LOG_ERROR(
"couldn't initialize FT2232 with 'flyswatter' layout");
2796 LOG_ERROR(
"couldn't initialize FT2232 with 'minimodule' layout");
2811 LOG_ERROR(
"couldn't initialize FT2232 with 'minimodule' layout");
2825 LOG_ERROR(
"couldn't initialize FT2232 with 'turtelizer2' layout");
2836 LOG_ERROR(
"couldn't initialize FT2232 with 'turtelizer2' layout");
2850 LOG_ERROR(
"couldn't initialize FT2232 with 'comstick' layout");
2864 LOG_ERROR(
"couldn't initialize FT2232 with 'comstick' layout");
2878 LOG_ERROR(
"couldn't initialize FT2232 with 'stm32stick' layout");
2892 LOG_ERROR(
"couldn't initialize FT2232 with 'stm32stick' layout");
2906 LOG_ERROR(
"couldn't initialize FT2232 with 'sheevaplug' layout");
2928 LOG_ERROR(
"couldn't initialize FT2232 with 'sheevaplug' layout");
2942 LOG_ERROR(
"couldn't initialize FT2232 with 'cortino' layout");
2956 LOG_ERROR(
"couldn't initialize FT2232 with 'cortino' layout");
2977 LOG_ERROR(
"couldn't initialize FT2232 with 'lisa_l' layout");
2998 LOG_ERROR(
"couldn't initialize FT2232 with 'Floss-JTAG' layout");
3022 #define XDS100_nEMU_EN (1<<5)
3023 #define XDS100_nEMU0 (1<<6)
3025 #define XDS100_PWR_RST (1<<3)
3026 #define XDS100_nEMU1 (1<<4)
3027 #define XDS100_LOOPBACK (1<<6)
3043 LOG_ERROR(
"couldn't initialize FT2232 with 'xds100v2' layout");
3052 LOG_ERROR(
"couldn't put CPLD in to reset with 'xds100v2' layout");
3060 LOG_ERROR(
"couldn't bring CPLD out of reset with 'xds100v2' layout");
3149 #if BUILD_FT2232_FTD2XX == 1
3152 #elif BUILD_FT2232_LIBFTDI == 1
3153 ftdi_usb_close(&ftdic);
3155 ftdi_deinit(&ftdic);
3174 if ((cp[-1] ==
'A') && (cp[-2] ==
' ')) {
3179 cp = strchr(buf, 0);
3189 LOG_ERROR(
"expected exactly one argument to ft2232_device_desc <description>");
3210 LOG_ERROR(
"already specified ft2232_layout %s",
3218 if (strcmp(l->name,
CMD_ARGV[0]) == 0) {
3232 LOG_WARNING(
"ignoring extra IDs in ft2232_vid_pid "
3237 LOG_WARNING(
"incomplete ft2232_vid_pid configuration directive");
3245 for (i = 0; i <
CMD_ARGC; i += 2) {
3273 if (ft2232_channel < 0 || ft2232_channel > 4)
3274 LOG_ERROR(
"ft2232_channel must be in the 0 to 4 range");
3276 LOG_ERROR(
"expected exactly one argument to ft2232_channel <ch>");
3288 while (num_cycles > 0) {
3293 int bitcount_per_command = (num_cycles > 7) ? 7 : num_cycles;
3315 num_cycles -= bitcount_per_command;
3367 LOG_ERROR(
"couldn't initialize FT2232 with 'IceBear' layout (low)");
3376 LOG_ERROR(
"couldn't initialize FT2232 with 'IceBear' layout (high)");
3388 }
else if (trst == 0) {
3406 LOG_DEBUG(
"trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
3425 #if BUILD_FT2232_FTD2XX == 1
3426 static int signalyzer_h_ctrl_read(
int address,
unsigned short *value);
3429 #define SIGNALYZER_COMMAND_ADDR 128
3430 #define SIGNALYZER_DATA_BUFFER_ADDR 129
3432 #define SIGNALYZER_COMMAND_VERSION 0x41
3433 #define SIGNALYZER_COMMAND_RESET 0x42
3434 #define SIGNALYZER_COMMAND_POWERCONTROL_GET 0x50
3435 #define SIGNALYZER_COMMAND_POWERCONTROL_SET 0x51
3436 #define SIGNALYZER_COMMAND_PWM_SET 0x52
3437 #define SIGNALYZER_COMMAND_LED_SET 0x53
3438 #define SIGNALYZER_COMMAND_ADC 0x54
3439 #define SIGNALYZER_COMMAND_GPIO_STATE 0x55
3440 #define SIGNALYZER_COMMAND_GPIO_MODE 0x56
3441 #define SIGNALYZER_COMMAND_GPIO_PORT 0x57
3442 #define SIGNALYZER_COMMAND_I2C 0x58
3444 #define SIGNALYZER_CHAN_A 1
3445 #define SIGNALYZER_CHAN_B 2
3447 #define SIGNALYZER_CHAN_C 4
3449 #define SIGNALYZER_LED_GREEN 1
3450 #define SIGNALYZER_LED_RED 2
3452 #define SIGNALYZER_MODULE_TYPE_EM_LT16_A 0x0301
3453 #define SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG 0x0302
3454 #define SIGNALYZER_MODULE_TYPE_EM_JTAG 0x0303
3455 #define SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P 0x0304
3456 #define SIGNALYZER_MODULE_TYPE_EM_JTAG_P 0x0305
3461 #if BUILD_FT2232_FTD2XX == 1
3462 return FT_WriteEE(ftdih, address, value);
3463 #elif BUILD_FT2232_LIBFTDI == 1
3468 #if BUILD_FT2232_FTD2XX == 1
3469 static int signalyzer_h_ctrl_read(
int address,
unsigned short *value)
3471 return FT_ReadEE(ftdih, address, value);
3476 int on_time_ms,
int off_time_ms,
unsigned char cycles)
3478 unsigned char on_time;
3479 unsigned char off_time;
3481 if (on_time_ms < 0xFFFF)
3482 on_time = (
unsigned char)(on_time_ms / 62);
3486 off_time = (
unsigned char)(off_time_ms / 62);
3488 #if BUILD_FT2232_FTD2XX == 1
3492 ((uint32_t)(channel << 8) | led));
3493 if (status != FT_OK) {
3494 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3495 ftd2xx_status_string(status));
3500 ((uint32_t)(on_time << 8) | off_time));
3501 if (status != FT_OK) {
3502 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3503 ftd2xx_status_string(status));
3508 ((uint32_t)cycles));
3509 if (status != FT_OK) {
3510 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3511 ftd2xx_status_string(status));
3517 if (status != FT_OK) {
3518 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3519 ftd2xx_status_string(status));
3524 #elif BUILD_FT2232_LIBFTDI == 1
3528 ((uint32_t)(channel << 8) | led));
3530 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3531 ftdi_get_error_string(&ftdic));
3536 ((uint32_t)(on_time << 8) | off_time));
3538 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3539 ftdi_get_error_string(&ftdic));
3546 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3547 ftdi_get_error_string(&ftdic));
3554 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3555 ftdi_get_error_string(&ftdic));
3565 #if BUILD_FT2232_FTD2XX == 1
3572 uint16_t read_buf[12] = { 0 };
3576 0xFFFF, 0x00, 0x00);
3585 signalyzer_h_side = *(end_of_desc - 1);
3586 if (signalyzer_h_side ==
'B')
3598 #if BUILD_FT2232_FTD2XX == 1
3602 if (status != FT_OK) {
3603 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3604 ftd2xx_status_string(status));
3608 for (i = 0; i < 10; i++) {
3611 if (status != FT_OK) {
3612 LOG_ERROR(
"signalyzer_h_ctrl_read returned: %s",
3613 ftd2xx_status_string(status));
3618 LOG_INFO(
"Signalyzer: ID info: { %.4x %.4x %.4x %.4x %.4x %.4x %.4x }",
3619 read_buf[0], read_buf[1], read_buf[2], read_buf[3],
3620 read_buf[4], read_buf[5], read_buf[6]);
3624 (uint32_t)(signalyzer_h_side << 8));
3625 if (status != FT_OK) {
3626 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3627 ftd2xx_status_string(status));
3632 if (status != FT_OK) {
3633 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3634 ftd2xx_status_string(status));
3640 if (status != FT_OK) {
3641 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3642 ftd2xx_status_string(status));
3648 ((uint32_t)(signalyzer_h_side << 8) | 0x01));
3649 if (status != FT_OK) {
3650 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3651 ftd2xx_status_string(status));
3657 if (status != FT_OK) {
3658 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3659 ftd2xx_status_string(status));
3665 if (status != FT_OK) {
3666 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3667 ftd2xx_status_string(status));
3673 if (status != FT_OK) {
3674 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3675 ftd2xx_status_string(status));
3682 if (status != FT_OK) {
3683 LOG_ERROR(
"signalyzer_h_ctrl_read returned: %s",
3684 ftd2xx_status_string(status));
3688 if (read_buf[0] != 0x0498)
3689 signalyzer_h_adapter_type = 0x0000;
3691 for (i = 0; i < 4; i++) {
3693 if (status != FT_OK) {
3694 LOG_ERROR(
"signalyzer_h_ctrl_read returned: %s",
3695 ftd2xx_status_string(status));
3700 signalyzer_h_adapter_type = read_buf[0];
3703 #elif BUILD_FT2232_LIBFTDI == 1
3715 LOG_INFO(
"Signalyzer: EM-LT (16-channel level translator) "
3716 "detected. (HW: %2x).", (read_buf[1] >> 8));
3745 #if BUILD_FT2232_FTD2XX == 1
3748 ((uint32_t)(signalyzer_h_side << 8) | 0x01));
3749 if (status != FT_OK) {
3750 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3751 ftd2xx_status_string(status));
3757 if (status != FT_OK) {
3758 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3759 ftd2xx_status_string(status));
3765 (uint32_t)(signalyzer_h_side << 8));
3766 if (status != FT_OK) {
3767 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3768 ftd2xx_status_string(status));
3773 if (status != FT_OK) {
3774 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3775 ftd2xx_status_string(status));
3780 if (status != FT_OK) {
3781 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3782 ftd2xx_status_string(status));
3788 (uint32_t)(signalyzer_h_side << 8));
3789 if (status != FT_OK) {
3790 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3791 ftd2xx_status_string(status));
3796 if (status != FT_OK) {
3797 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3798 ftd2xx_status_string(status));
3804 if (status != FT_OK) {
3805 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3806 ftd2xx_status_string(status));
3816 if (signalyzer_h_adapter_type
3818 LOG_INFO(
"Signalyzer: EM-ARM-JTAG (ARM JTAG) "
3819 "detected. (HW: %2x).", (read_buf[1] >> 8));
3820 else if (signalyzer_h_adapter_type
3822 LOG_INFO(
"Signalyzer: EM-ARM-JTAG_P "
3823 "(ARM JTAG with PSU) detected. (HW: %2x).",
3824 (read_buf[1] >> 8));
3825 else if (signalyzer_h_adapter_type
3827 LOG_INFO(
"Signalyzer: EM-JTAG (Generic JTAG) "
3828 "detected. (HW: %2x).", (read_buf[1] >> 8));
3829 else if (signalyzer_h_adapter_type
3832 "(Generic JTAG with PSU) detected. (HW: %2x).",
3833 (read_buf[1] >> 8));
3862 #if BUILD_FT2232_FTD2XX == 1
3865 ((uint32_t)(signalyzer_h_side << 8) | 0x01));
3866 if (status != FT_OK) {
3867 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3868 ftd2xx_status_string(status));
3874 if (status != FT_OK) {
3875 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3876 ftd2xx_status_string(status));
3884 (uint32_t)(signalyzer_h_side << 8));
3885 if (status != FT_OK) {
3886 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3887 ftd2xx_status_string(status));
3892 if (status != FT_OK) {
3893 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3894 ftd2xx_status_string(status));
3899 if (status != FT_OK) {
3900 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3901 ftd2xx_status_string(status));
3909 (uint32_t)(signalyzer_h_side << 8));
3910 if (status != FT_OK) {
3911 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3912 ftd2xx_status_string(status));
3917 if (status != FT_OK) {
3918 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3919 ftd2xx_status_string(status));
3924 if (status != FT_OK) {
3925 LOG_ERROR(
"signalyzer_h_ctrl_write returned: %s",
3926 ftd2xx_status_string(status));
3930 }
else if (signalyzer_h_adapter_type == 0x0000) {
3931 LOG_INFO(
"Signalyzer: No external modules were detected.");
3960 LOG_ERROR(
"Unknown module type is detected: %.4x",
3961 signalyzer_h_adapter_type);
3967 LOG_ERROR(
"couldn't initialize Signalyzer-H layout");
3971 #if BUILD_FT2232_FTD2XX == 1
3972 if (ftdi_device == FT_DEVICE_2232H) {
3975 LOG_ERROR(
"couldn't initialize Signalyzer-H layout");
3979 #elif BUILD_FT2232_LIBFTDI == 1
3980 if (ftdi_device == TYPE_2232H) {
3983 LOG_ERROR(
"couldn't initialize Signalyzer-H layout");
4004 }
else if (trst == 0) {
4021 }
else if (srst == 0) {
4034 LOG_DEBUG(
"trst: %i, srst: %i, low_output: 0x%2.2x, "
4035 "low_direction: 0x%2.2x",
4048 }
else if (trst == 0) {
4060 }
else if (srst == 0) {
4071 LOG_INFO(
"trst: %i, srst: %i, high_output: 0x%2.2x, "
4072 "high_direction: 0x%2.2x",
4074 }
else if (signalyzer_h_adapter_type == 0x0000) {
4082 }
else if (trst == 0) {
4099 }
else if (srst == 0) {
4112 LOG_DEBUG(
"trst: %i, srst: %i, low_output: 0x%2.2x, "
4113 "low_direction: 0x%2.2x",
4130 uint8_t swd_en = 0x20;
4137 LOG_ERROR(
"couldn't initialize FT2232 with 'ktlink' layout");
4169 LOG_ERROR(
"couldn't initialize FT2232 with 'ktlink' layout");
4185 }
else if (trst == 0) {
4197 }
else if (srst == 0) {
4207 LOG_DEBUG(
"trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
4240 LOG_ERROR(
"couldn't initialize FT2232 with 'digilent_hs1' layout");
4253 .
name =
"ft2232_device_desc",
4254 .handler = &ft2232_handle_device_desc_command,
4256 .help =
"set the USB device description of the FTDI FT2232 device",
4257 .usage =
"description_string",
4260 .name =
"ft2232_serial",
4261 .handler = &ft2232_handle_serial_command,
4263 .help =
"set the serial number of the FTDI FT2232 device",
4264 .usage =
"serial_string",
4267 .name =
"ft2232_layout",
4268 .handler = &ft2232_handle_layout_command,
4270 .help =
"set the layout of the FT2232 GPIO signals used "
4271 "to control output-enables and reset signals",
4272 .usage =
"layout_name",
4275 .name =
"ft2232_vid_pid",
4276 .handler = &ft2232_handle_vid_pid_command,
4278 .help =
"the vendor ID and product ID of the FTDI FT2232 device",
4279 .usage =
"(vid pid)* ",
4282 .name =
"ft2232_latency",
4283 .handler = &ft2232_handle_latency_command,
4285 .help =
"set the FT2232 latency timer to a new value",
4289 .name =
"ft2232_channel",
4290 .handler = &ft2232_handle_channel_command,
4292 .help =
"set the FT2232 channel to a new value",