From 31865800dffc58f2db3ae06a7bbba61bb279b265 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Wed, 21 Apr 2021 12:43:34 -0700 Subject: [PATCH] Don't set EEPROM serial when it's not used. This makes a difference in USB enumeration -- if serial is missing, its string is not present in string descriptor list. --- src/ftdi.c | 25 +++++++++++++------------ 1 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index 2f77ac3..92c5fae 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -2606,7 +2606,7 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, const char * manufacture ftdi_error_return(-3, "No connected device or device not yet opened"); eeprom->vendor_id = 0x0403; - eeprom->use_serial = 1; + eeprom->use_serial = (serial != NULL); if ((ftdi->type == TYPE_AM) || (ftdi->type == TYPE_BM) || (ftdi->type == TYPE_R)) eeprom->product_id = 0x6001; @@ -3101,15 +3101,18 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) } output[0x11] = product_size*2 + 2; - // Addr 12: Offset of the serial string + 0x80, calculated later - // Addr 13: Length of serial string - output[0x12] = i | 0x80; // calculate offset - output[i & eeprom_size_mask] = serial_size*2 + 2, i++; - output[i & eeprom_size_mask] = 0x03, i++; - for (j = 0; j < serial_size; j++) - { - output[i & eeprom_size_mask] = eeprom->serial[j], i++; - output[i & eeprom_size_mask] = 0x00, i++; + if (eeprom->use_serial) { + // Addr 12: Offset of the serial string + 0x80, calculated later + // Addr 13: Length of serial string + output[0x12] = i | 0x80; // calculate offset + output[i & eeprom_size_mask] = serial_size*2 + 2, i++; + output[i & eeprom_size_mask] = 0x03, i++; + for (j = 0; j < serial_size; j++) + { + output[i & eeprom_size_mask] = eeprom->serial[j], i++; + output[i & eeprom_size_mask] = 0x00, i++; + } + output[0x13] = serial_size*2 + 2; } // Legacy port name and PnP fields for FT2232 and newer chips @@ -3124,8 +3127,6 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi) i++; } - output[0x13] = serial_size*2 + 2; - if (ftdi->type > TYPE_AM) /* use_serial not used in AM devices */ { if (eeprom->use_serial) -- 1.7.1