This additional output was helpful when debugging a FTDI device with a broken EEPROM. I was expecting to connect to a cable with a particular description, but the device was not found. This error message would helps quickly identify
the connection failure.

-Karl
>From 69c031d9c515d9f82f5fd6054d980f7b484c759f Mon Sep 17 00:00:00 2001
From: Karl Kurbjun <[email protected]>
Date: Sun, 2 Oct 2011 11:28:11 -0600
Subject: [PATCH 3/3] FT2232: Add additional debug information with libftdi when cable connection
         fails.

This additional output was helpful when debugging a FTDI device with a broken
EEPROM.  I was expecting to connect to a cable with a particular description,
but the device was not found.  This error message would helps quickly identify
the connection failure.
---
 src/jtag/drivers/ft2232.c |   56 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/src/jtag/drivers/ft2232.c b/src/jtag/drivers/ft2232.c
index 3cca26d..e248f55 100644
--- a/src/jtag/drivers/ft2232.c
+++ b/src/jtag/drivers/ft2232.c
@@ -2348,7 +2348,7 @@ static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_mo
 	}
 
 	LOG_DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
-			layout->name, vid, pid);
+				layout->name, vid, pid);
 
 	if (ftdi_init(&ftdic) < 0)
 		return ERROR_JTAG_INIT_FAILED;
@@ -2362,16 +2362,70 @@ static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_mo
 		return ERROR_JTAG_INIT_FAILED;
 	}
 
+	LOG_DEBUG("Attempting to open FTDI device with the following parameters "
+				"from cfg:\n"
+				"   VID: %04x, PID: %04x, Description: %s",
+				vid, pid, ft2232_device_desc); 
+
 	/* context, vendor id, product id */
 	if (ftdi_usb_open_desc(&ftdic, vid, pid, ft2232_device_desc,
 				ft2232_serial) < 0)
 	{
+		struct ftdi_device_list *device_list, *curdev;
+		int ret;
+
 		if (more)
+		{
 			LOG_WARNING("unable to open ftdi device (trying more): %s",
 					ftdic.error_str);
+		}
 		else
+		{
 			LOG_ERROR("unable to open ftdi device: %s", ftdic.error_str);
+		}
+
 		*try_more = 1;
+
+
+		/* We were unable to open the device, so list some useful information
+		 * about what we found.  This section of code is based on the find_all.c
+		 * example in libftdi.
+		 */
+		if((ret = ftdi_usb_find_all(&ftdic, &device_list, vid, pid)) < 0)
+		{
+			LOG_ERROR("ftdi_usb_find_all failed: %d (%s)",
+					ret, ftdi_get_error_string(&ftdic));
+			goto device_fail;
+		}
+
+		LOG_ERROR("Found %d ftdi device(s) with VID: %04x, PID: %04x:",
+				ret, vid, pid);
+
+		for (curdev = device_list; curdev != NULL; curdev = curdev->next)
+		{
+			/* Limit the scope of these variables */
+			char manufacturer[128], description[128];
+			int i = 0;
+
+			i++;
+
+			/* Try reading strings from the found device */
+			if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 
+				128, description, 128, NULL, 0)) < 0)
+			{
+				LOG_ERROR("ftdi_usb_get_strings failed: %d (%s)\n",
+					ret, ftdi_get_error_string(&ftdic));
+				goto device_fail;
+			}
+
+			/* Show the device description */
+			LOG_ERROR("   Device %d Description: %s", i, description);
+
+		}
+
+	/* Cleanup the device list and exit */
+	device_fail:
+		ftdi_list_free(&device_list);
 		return ERROR_JTAG_INIT_FAILED;
 	}
 
-- 
1.7.4.1

_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to