PDA

View Full Version : How to add change CDC Descriptor serial number string



barak
25th May 2014, 15:54
Can some please explain how to add or change a serial number string in the CDC Descriptor file so that the device will have a serial number and retain the COM port number if moved to a different USB port?

Tim
25th May 2014, 22:08
Are you trying to do it on the fly? Eg after its been programmed?

I do it all the time with HID

barak
26th May 2014, 01:50
Not on the fly. At this point, I don't care if they are all the same number. I just want to have serial number so I don't have to change com port numbers if I plug to another USB port on the PC. Once I figure it out I may do something via the E2PROM so each device has a unique SN

towlerg
26th May 2014, 02:22
Not a direct answer but the forum at http://janaxelson.com/forum/ is a great USB resource.

George

barak
26th May 2014, 14:32
Not a direct answer but the forum at http://janaxelson.com/forum/ is a great USB resource.

George

Thanks, I aware of Axelson but I'm pressed for time and wanted a "direct answer" from someone who already added/changed the serial number in Proton's CDC Descriptor

towlerg
27th May 2014, 00:48
Point taken. I thought it might be useful to confirm that what you are trying to do is possible. I wonder what Proteus makes of that situation? George

towlerg
27th May 2014, 01:22
Sorry I realized that I had misunderstood the question. To add a serial number you need to make "Device serial number string index" non 0 in "Desc_DeviceDescriptor:" and add a string to Desc_Strings: . But I'm sure you already knew that. What I find odd is that I can't find an example of a CDC descriptor that has a serial number? George

towlerg
27th May 2014, 01:49
I found a CDC descriptor with a serial in a Swordfish example. As its not Proton code perhaps if you want it I can pm it to you.

George

BTW The reason for 3 replies is the silly 20 minute edit restriction.

barak
27th May 2014, 15:49
Yes, sure please PM

barak
27th May 2014, 16:13
Sorry I realized that I had misunderstood the question. To add a serial number you need to make "Device serial number string index" non 0 in "Desc_DeviceDescriptor:" and add a string to Desc_Strings: . But I'm sure you already knew that. What I find odd is that I can't find an example of a CDC descriptor that has a serial number? George
George, I'm assuming you would change the serial number index here:

Desc_DeviceDescriptor: Dt (Desc_EndDeviceDescriptor - Desc_DeviceDescriptor) / 2 ' Size of this descriptor (in bytes)
Dt cUSB_DESCRIPTOR_DEVICE ' Device descriptor type
Dt 0x10, 0x01 ' USB Spec Release Number in BCD format - 1.10 (low byte, high byte)
Dt cCDC_DEVICE ' Class Code
Dt 0x00 ' Subclass code
Dt 0x00 ' Protocol code
Dt cUSB_EP0_BUFF_SIZE ' Max packet size for EP0
Dt Low(cVID), High(cVID) ' Vendor ID - 0x04D8 is Microchip Vendor ID (low byte, high byte)
Dt Low(cPID), High(cPID) ' Product ID: CDC RS - 232 Emulation Demo (low byte, high byte)
Dt 0x01, 0x00 ' Device release number in BCD format (low byte, high byte)
Dt 0x01 ' Manufacturer string index
Dt 0x02 ' Product string index
Dt 0x00 ' Device serial number string index
Dt cUSB_NUM_CONFIGS ' Number of possible configurations
Desc_EndDeviceDescriptor:
But I don't understand where (which table?) and how to add the the serial number string.

hadv215
27th May 2014, 16:59
It's not that hard.
When you look at the three entries above 'Dt cUSB_NUM_CONFIGS' you'll see
Dt 0x01 : this is the manufacturer
Dt 0x02 : product
Dt 0x00 : serial

Since the last of the three is 0 there is no serial string
Change that one to read 'Dt 0x03'
Now look at the last lines in the .inc, they read

'
' Product string descriptor
'
Desc_String2:-
dt (_DescriptorMain_ - Desc_String2) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
CData As Dword "CDC RS-232 Emulation Demo"

_DescriptorMain_:
$endif ' _CDC_DESC_INC_

Change this to

'
' Product string descriptor
'
Desc_String2:-
dt (Desc_String3 - Desc_String2) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
CData As Dword "CDC RS-232 Emulation Demo"

'
' Serial number string descriptor
'
Desc_String3:-
dt (_DescriptorMain_ - Desc_String3) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
CData As Dword "1234"

_DescriptorMain_:
$endif ' _CDC_DESC_INC_

Done

barak
27th May 2014, 18:22
That is exactly what I wanted. You almost nailed it. For this to work, I also had to change the String pointer table to add a pointer to the new string.
So that it is clear for anyone in the future here is why and what was done:
Adding a serial number to a USB/Serial Device has the advantage that the device will retain the same COM port number on all the USB ports of the PC. Otherwise, when you plug to different USB sockets you will get different COM port numbers. To modify the CDC Descriptor and add a serial number:

Step #1: Under Desc_DeviceDescriptor table change the 13th item to:

Dt 0x03 ' Device serial number string index

Step #2: Modify the String pointer table to add item for index 3:

Desc_USB_SD_Ptr:
Desc_Strings:
CData As Dword Desc_String0, Desc_String1, Desc_String2, Desc_String3

Step #3: under Product string descriptor change to add item for index 3 (the serial number string)

' Product string descriptor
'
Desc_String2:-
dt (Desc_String3 - Desc_String2) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
CData As Dword "CDC RS-232 Emulation Demo"
'
' Serial number string descriptor
'
Desc_String3:-
dt (_DescriptorMain_ - Desc_String3) / 2 ' Size of this descriptor (in bytes)
dt cUSB_DESCRIPTOR_STRING ' String descriptor type
CData As Dword "1234"

_DescriptorMain_:
$endif ' _CDC_DESC_INC_

hadv215
27th May 2014, 18:36
You're right of course, forgot your step #2

towlerg
27th May 2014, 19:32
Have you confirmed that
..... the device will retain the same COM port number on all the USB ports of the PC. is correct?

George

barak
28th May 2014, 01:17
Yes, it works great. I tried on 7 different USB ports and keeps the COM Port it got the first time on all of them

joesaliba
28th May 2014, 17:46
Thank you so much Barak and Had. Very useful information. I am going to `Promote to Article' the Wiki USB section so it does not get lost.

joesaliba
28th May 2014, 17:53
Barak,

I did promote it to an article here (http://www.protonbasic.co.uk/content.php/4413-How-to-add-change-CDC-Descriptor-serial-number-string). Hpe it is ok for you.

hadv215
28th May 2014, 22:32
A small remark on your article.
You refer to 'the 13th item'. I think you should describe the line to be changed by means of its 'neighbours' instead of using an absolute index.

Maybe interesting to know, this works the same way for the HID descriptor.

barak
28th May 2014, 23:17
You are right, 13th item does no sound very lucky.
I never used HID and don't have much experience with USB in general. However, with PDS offering USB solution for dummies, I developed a USB RFID card reader in record time.
The PC (Windows) talks to PIC18F14K50 which controls a PN532 RFID IC via SPI. It is very fast. Before I had an RFID module that used RS232 at 9.6kbps and it was slow enough to show a progress bar on the window. Now it works so fast you can't even see the progress bar.

hadv215
28th May 2014, 23:45
Well, that's USB for you: fast
Most of what I did was HID. Have a 14K50 or 4550 as device and a Windows program to control the device.

I too love the PDS implementation, though some things could be improved.

The first one is the USB version.
The 14K50 and 4550 are USB 2.0 compliant, yet both the CDC and HID inc files limit it to 1.10
Take a look at the line in the device descriptor containing
" Dt 0x10, 0x01 ' USB Spec Release Number in BCD format - 1.10 (low byte, high byte)"
There's a line like that in the HID descriptor too.
If you change it to
"Dt 0x00, 0x02" you'll have a USB 2.0 device.

The second one is the USB_Defs.inc in the 'New Samples' subdirectory (though I doubt if anyone would use these)
Here we see the same version indicator 1.10
The main problem I have with this file is the fact it contains configs for a number of device types running on a 12 MHz clock.
And this file contains a significant error for the 4550 family. It says USBDIV = 1 where it should be USBDIV = 2.

towlerg
29th May 2014, 16:31
Hadv215 could you clarify
If you change it to "Dt 0x00, 0x02" you'll have a USB 2.0 device. are you saying that this will generate a 2.0 USB device or that something in the Proton implementation prevents this.

George

hadv215
29th May 2014, 17:08
Hi George,

The descriptor is used in the enumeration process. All the entries tell the host something about the device connected.
If you want to know the details read one of the fine books by Jan Axelson.

The uC's discussed here are USB 2.0 compliant so why not take advantage.
PDS does not prevent anything in this area, the code is the same (except for these two bytes of course).

The fact that these descriptors still address USB 1.10 probably has a historic reason.
The first PDS example I remember was based on the famous Jan Axelson demo program, but that was developed when 1.10 was the fastest.
If you look at the HID descriptor you'll see the VID being the one of Lakeview Research, Jan's company.

Harm