libftdi-git Archives

Subject: A library to talk to FTDI chips branch, master, updated. v0.17-321-g2e48e9f

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sat, 7 Jul 2012 14:45:59 +0200 (CEST)
The branch, master has been updated
       via  2e48e9fd12c105a31787c42052f5c6654b73d92b (commit)
       via  ad7ced1c966f47cfafc84201bb13ac6d438e0e25 (commit)
       via  faa85774b7122c5907de44ec7e7afef2a526bf22 (commit)
      from  ac5790a7af9ffb45c00bde056b308643cd52537e (commit)


- Log -----------------------------------------------------------------
commit 2e48e9fd12c105a31787c42052f5c6654b73d92b
Author: Anders Larsen <al@xxxxxxxxxxx>
Date:   Tue Jul 3 23:24:07 2012 +0200

    ftdi_eeprom: reset the device after flashing the eeprom
    
    If we change e.g. the product-id the change will take effect immediately
    without having to unplug/replug the device.
    
    Signed-off-by: Anders Larsen <al@xxxxxxxxxxx>

commit ad7ced1c966f47cfafc84201bb13ac6d438e0e25
Author: Anders Larsen <al@xxxxxxxxxxx>
Date:   Tue Jul 3 23:24:06 2012 +0200

    Document the FT245R EEPROM weirdness
    
    The FT232R and the FT245R share the same USB id (0x0403, 0x6001) and are
    only distinguished by bit 00.0 in the (internal) EEPROM.
    
    ftdi_eeprom currently can't handle this and will turn an FT245R chip
    into an FT232R; document the fact.
    
    Signed-off-by: Anders Larsen <al@xxxxxxxxxxx>

commit faa85774b7122c5907de44ec7e7afef2a526bf22
Author: Anders Larsen <al@xxxxxxxxxxx>
Date:   Tue Jul 3 23:24:05 2012 +0200

    ftdi_eeprom: Added config value "eeprom_type"
    
    The default eeprom size is 128 bytes - if we have a larger one, we need
    a way to specify the fact.
    Using ftdi_read_eeprom() / ftdi_eeprom_decode() to get the actual eeprom 
type
    is not an option as ftdi_eeprom_decode() would overwrite the values set
    by ftdi_eeprom_initdefaults()
    
    Signed-off-by: Anders Larsen <al@xxxxxxxxxxx>

-----------------------------------------------------------------------

Summary of changes:
 doc/EEPROM-structure |    3 ++-
 ftdi_eeprom/main.c   |   27 ++++++++++++++++++++-------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/doc/EEPROM-structure b/doc/EEPROM-structure
index a1e9b02..08abe62 100644
--- a/doc/EEPROM-structure
+++ b/doc/EEPROM-structure
@@ -9,7 +9,7 @@ Type   |  Use extra EEPROM space
 FT2XXB |  No
 
 Byte.BIT| TYPE_AM TYPE_BM   TYPE_2232C       TYPE_R          TYPE_2232H       
TYPE_4232H
-00.0    |      0       0   channel_a_type                    channel_a_type   0
+00.0    |      0       0   channel_a_type   232R/245R        channel_a_type   0
 00.1    |      0       0   channel_a_type                    channel_a_type   0
 00.2    |      0       0   channel_a_type   high_current     channel_a_type   0
 00.3    |      0       0   channel_a_driver channel_a_driver channel_a_driver 
channel_a_driver
@@ -18,6 +18,7 @@ Byte.BIT| TYPE_AM TYPE_BM   TYPE_2232C       TYPE_R          
TYPE_2232H       TY
 00.6    |      0       0   0                0                0                0
 00.7    |      0       0   0                0                SUSPEND_DBUS7    
channel_c_driver
 
+On TYPE_R 00.0 is set for the FT245R and cleared for the FT232R
 On TYPE_R 00.3 set mean D2XX, on other devices VCP
 
 01.0    |      0       0   channel_b_type                    channel_b_type   0
diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c
index ad7de93..4eb0f5e 100644
--- a/ftdi_eeprom/main.c
+++ b/ftdi_eeprom/main.c
@@ -16,7 +16,6 @@
 
 /*
  TODO:
-    - Remove 128 bytes limit
     - Merge Uwe's eeprom tool. Current features:
         - Init eeprom defaults based upon eeprom type
         - Read -> Already there
@@ -38,6 +37,7 @@
 #include <string.h>
 
 #include <confuse.h>
+#include <libusb.h>
 #include <ftdi.h>
 #include <ftdi_eeprom_version.h>
 
@@ -118,6 +118,7 @@ int main(int argc, char *argv[])
         CFG_STR("manufacturer", "Acme Inc.", 0),
         CFG_STR("product", "USB Serial Converter", 0),
         CFG_STR("serial", "08-15", 0),
+        CFG_INT("eeprom_type", 0x00, 0),
         CFG_STR("filename", "", 0),
         CFG_BOOL("flash_raw", cfg_false, 0),
         CFG_BOOL("high_current", cfg_false, 0),
@@ -143,6 +144,7 @@ int main(int argc, char *argv[])
     */
     int _read = 0, _erase = 0, _flash = 0;
 
+    const int max_eeprom_size = 256;
     int my_eeprom_size = 0;
     unsigned char *eeprom_buf = NULL;
     char *filename;
@@ -231,12 +233,11 @@ int main(int argc, char *argv[])
     ftdi_eeprom_initdefaults (ftdi, cfg_getstr(cfg, "manufacturer"), 
                               cfg_getstr(cfg, "product"), 
                               cfg_getstr(cfg, "serial"));
-    
+
     printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(ftdi));
     eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
-    // TODO: Do we know the eeprom size already?
     printf("EEPROM size: %d\n", my_eeprom_size);
-    
+
     if (_read > 0)
     {
         ftdi_eeprom_decode(ftdi, 0 /* debug: 1 */);
@@ -278,7 +279,7 @@ int main(int argc, char *argv[])
     eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial"));
     eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg, 
"change_usb_version"));
     eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version"));
-
+    eeprom_set_value(ftdi, CHIP_TYPE, cfg_getint(cfg, "eeprom_type"));
 
     eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current"));
     eeprom_set_value(ftdi, CBUS_FUNCTION_0, str_to_cbus(cfg_getstr(cfg, 
"cbus0"), 13));
@@ -312,6 +313,7 @@ int main(int argc, char *argv[])
     }
 
     size_check = ftdi_eeprom_build(ftdi);
+    eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
 
     if (size_check == -1)
     {
@@ -332,15 +334,26 @@ int main(int argc, char *argv[])
         {
             if (filename != NULL && strlen(filename) > 0)
             {
-                eeprom_buf = malloc(my_eeprom_size);
+                eeprom_buf = malloc(max_eeprom_size);
                 FILE *fp = fopen(filename, "rb");
-                fread(eeprom_buf, 1, my_eeprom_size, fp);
+                if (fp == NULL)
+                {
+                    printf ("Can't open eeprom file %s.\n", filename);
+                    exit (-1);
+                }
+                my_eeprom_size = fread(eeprom_buf, 1, max_eeprom_size, fp);
                 fclose(fp);
+                if (my_eeprom_size < 128)
+                {
+                    printf ("Can't read eeprom file %s.\n", filename);
+                    exit (-1);
+                }
 
                 ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
             }
         }
         printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi));
+        libusb_reset_device(ftdi->usb_dev);
     }
 
     // Write to file?


hooks/post-receive
-- 
A library to talk to FTDI chips

--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • A library to talk to FTDI chips branch, master, updated. v0.17-321-g2e48e9f, libftdi-git <=