CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USB CDC oddity.....

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

USB CDC oddity.....
PostPosted: Tue May 02, 2017 7:48 am     Reply with quote

Hi All,

I'm experiencing an odd behavior with a couple of USB CDC devices I've got, of course built with the CCS USB code.

These devices work great individually, but when I connect two to my Windows 7 PC I observe something odd about the COM port mapping. Specifically, they seems to swap COM port numbers when both are plugged in. For example, I plug in the 1st device and check the Windows Device Manager and see this device is mapped to 'COM5'. I then plug in the 2nd device and see that a new port (COM6) shows up, so I assume this is the 2nd device. But, when I attempt to communicate with the 2nd device on COM6, the 1st device on COM5 responds, so it seems that the COM port 'mapping' is not preserved.

I assume this may happen also each time the computer is booted with both devices plugged in?

Both USB CDC devices are identical, so how can I make them unique so that this COM port oddity does not occur? I need device 1 to always be COMx, and device 2 to always be COMy.

Thanks,

Jack
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue May 02, 2017 8:36 am     Reply with quote

If the devices are identical, you won't.

They need to have unique serial numbers. In the descriptor, there is an unused (0) entry for the serial number string descriptor. You need to change this to '3' and add a serial number to the string descriptor. If you look at the hid descriptor, this has a serial number, and shows how it has to be done.
With this done (different numbers in the two devices), if you then use the advanced option in device manager for the com port, for the first device and set it to a specific port number, then this will become associated to this device's serial number. Do the same for the second port.
With the different serial numbers, Windows can tell the devices apart. Without this, the port numbers will be assigned on 'first come first served' basis, and will change with the order the devices are plugged in, what USB ports they are on, etc. ect..
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

PostPosted: Tue May 02, 2017 11:55 am     Reply with quote

Hi Ttelmah,

Yes, your description is pretty much what I was assuming was going on. I checked and it doesn't seem too difficult to add the unique serial number to my device. The HID descriptor provides a handy road map for this!

Thanks!

Jack
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

PostPosted: Wed May 03, 2017 1:20 pm     Reply with quote

Hi Again,

Well, I have not been able to get this working in spite of it seeming to be pretty straight-forward.

I did the following additions to usb_desc_cdc.h:

Code:

        #if defined(USE_USB_SERIAL_NUMBER)
         0x03, //index of string descriptor of serial number  ==16
        #else
         0x00,
        #endif
 


to the device descriptor, and:

Code:

   // string 3 - serial number (this is optional, but we specified it's use in the device descriptor)
          18, //length of string index
          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
          '1', 0,
          '2', 0,
          '3', 0,
          '4', 0,
          '5', 0,
          '6', 0,
          '7', 0,
          '8', 0


to the string descriptor.

I also added a flag to my program above the include for usb_cdc as follows:

Code:

#define USE_USB_SERIAL_NUMBER TRUE
#include <usb_cdc.h>


Have I missed anything obvious?

So, the code won't compile, with all the errors occurring in the modified usb_desc_cdc.h file. Of course, the errors reference line numbers in the file, but I'm not sure how that relates to actual lines in an external source file? This is a new one for me.....

Jack
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu May 04, 2017 12:34 am     Reply with quote

I'd guess you have probably left the comma out on the line before:

Code:

         'U',0,
         'A',0,
         'R',0,
         'T',0,
   // string 3 - serial number (this is optional, but we specified it's use in the device descriptor)
          18, //length of string index
          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
          '1', 0,
          '2', 0,
          '3', 0,
          '4', 0,
          '5', 0,
          '6', 0,
          '7', 0,
          '8', 0         
};


Note the comma after the 'T',0 entry.

The last element in the array always has no comma. Since you are extending the array, a comma has to be added.

I have just built the ex_usb_serial example, with these mods, and Windows happily recognises the com port, and in device manager, shows it having a serial number correctly.
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

PostPosted: Thu May 04, 2017 7:45 am     Reply with quote

Hi Ttelmah,

Argh! Yes, that was it, a simple missing comma Shocked !

Thanks,

Jack
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu May 04, 2017 7:50 am     Reply with quote

I was trying to work out what to call this.
A 'virtual' second set of eyes?.

Spotting the missing comma, when it wasn't even posted!...

Has to rate quite highly as a good guess. Smile
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

PostPosted: Thu May 04, 2017 7:58 am     Reply with quote

Ttelmah wrote:

Spotting the missing comma, when it wasn't even posted!...

Has to rate quite highly as a good guess. Smile


Absolutely no argument there! I'm glad your crystal ball wasn't out for service this week! Laughing

Jack
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group