| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| zlittell 
 
 
 Joined: 08 Feb 2012
 Posts: 13
 
 
 
			      
 
 | 
			
				| Using serial numbers with USB |  
				|  Posted: Mon Mar 12, 2012 12:25 pm |   |  
				| 
 |  
				| So I am working on using Serial Numbers with my USB device.  Has anyone done this? 
 I have it working if I set the serial number in the USB descriptor but obviously that isn't an option because I will have to recompile with a new serial every time I program a new board.
 
 I tried to point to values in the eeprom but that did not return successful since the descriptor expects constants since its computed at compilation.
 
 I currently have two ideas (ones more of a failsafe).
 (1) if I can figure out how CCSload formats its serial number, I can have it write to the program directly where the usb serial is.  That is, if it is formatted the same way :/
 
 (2) figure out where the serial is held when it is programmed in the descriptor, then use a batch file to make a menu allowing people to program the units easily.  Then this menu will hexedit a new serial in the file then program that hex all from command line.
 
 Unless there is some easier way to do this that I don't know about.  I really think there should be.  How was CCS not when implementing USB.  If I make a device it really should have a serial number.  What if I have two devices, how would you determine between the two.
 
 -zack-
 |  |  
		|  |  
		| temtronic 
 
 
 Joined: 01 Jul 2010
 Posts: 9588
 Location: Greensville,Ontario
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 12, 2012 2:52 pm |   |  
				| 
 |  
				| WHAT USB device ?? A PIC with USB like the 18F4550, a PIC16C84 with an FTDI ttl<->USB chip?
 
 We need more information. It's basic PIC102 to embed any PIC that has EEPROM a serial number, simpler yet if using the FTDI products!
 
 Also what do you consider to be a 'serial number'? Only decimal digits ? How many 3,4,10,20 ? Is Hex allowable? How many devices?
 
 If you need other people to encode a serial number, you'll have to maintain an accurate database of what's used, what's available. Unless it's all done at one location,it can be 'fun' to maintain! BTDT!!
 |  |  
		|  |  
		| Humberto 
 
 
 Joined: 08 Sep 2003
 Posts: 1215
 Location: Buenos Aires, La Reina del Plata
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 12, 2012 6:50 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | (2)figure out where the serial is held when it is programmed in the descriptor, then use a batch file to make a menu allowing people to program the units easily.
 
 | 
 
 Not all manufacturers comply with the USB spec and mostly they leave the iSerialNumber value blank, which will interfering with another product  that uses the iSerialNumber
 to identify different USB flash drives when plugged in. I guess that there is no sense putting a serial number on a USB device descriptor that does already have one and
 there is no way for you to change one that already has a number assigned.
 You can find good info related to this issue here:
 http://blogs.msdn.com/b/usbcoreblog/archive/2009/10/31/how-does-usb-stack-enumerate-a-device.aspx
 
 Humberto
 |  |  
		|  |  
		| Humberto 
 
 
 Joined: 08 Sep 2003
 Posts: 1215
 Location: Buenos Aires, La Reina del Plata
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 15, 2012 8:00 am |   |  
				| 
 |  
				| I didn't try it yet, but there are a new device MCP2210 USB-SPI Protocol Converter, you can download software drivers and DLL, along with a configuration tool for PC, eliminating the need for huge knowledge of USB and it facilitate the addition of USB (HID clase) connectivity your designs based on SPI.
 
 Regards.
 |  |  
		|  |  
		| RTdch 
 
 
 Joined: 19 Mar 2012
 Posts: 2
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 19, 2012 1:38 pm |   |  
				| 
 |  
				| I'm not sure if this is what you're looking for, I save my S# in an EEPROM and on startup copy that into the USB_STRING_DESC as follows: 
 
  	  | Code: |  	  | char iSerialNumber[6];
 DevSerialNumber = make16(ReadMem24xx32(EEPROM,0x0001),ReadMem24xx32(EEPROM,0x0000));   // Retrieve Logger Serial Number from EEPROM
 
 sprintf(iSerialNumber,"%Lu",DevSerialNumber);
 USB_STRING_DESC[62] = iSerialNumber[0];                  // Copies the Logger Serial # into the USB iSerialNumber descriptior
 USB_STRING_DESC[64] = iSerialNumber[1];
 USB_STRING_DESC[66] = iSerialNumber[2];
 USB_STRING_DESC[68] = iSerialNumber[3];
 USB_STRING_DESC[70] = iSerialNumber[4];
 | 
 |  |  
		|  |  
		| zlittell 
 
 
 Joined: 08 Feb 2012
 Posts: 13
 
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Apr 21, 2012 6:16 pm |   |  
				| 
 |  
				| I am using an 18F4550.  and RTdch has the right idea.  my program on the pc looks at vids and pids when it finds a match it stores the usb serial number and devicepath.  the user then chooses a device according to its serial. 
 therefore having unique serials in the USB descriptor is important.  I have tried your code RTdch and a thousand variants and I have not had any luck.
 
 I have tried storing the descriptor string in a specific location using #org then overwriting the locations used write_program_memory but it does not correctly write the new data.
 
 Also I have tried your way but when I try to set the specific indexes of USB_STRING_DESC[] it gives an error 49 when compiling "Expecting LVALUE such as a variable name or *expression"
 
 How are you not getting this error?
 
 -zack-
 |  |  
		|  |  
		| RTdch 
 
 
 Joined: 19 Mar 2012
 Posts: 2
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon May 14, 2012 12:14 pm |   |  
				| 
 |  
				| zlittell, maybe you've already figured this out, if not, try compiling the following, I don't get any errors using PCH v4.130 
 
  	  | Code: |  	  | #include <18F66J50.h> #include <math.h>
 
 #fuses NOWDT,WDT128,PROTECT,HSPLL,PLL5
 #use delay(clock=48000000)
 
 #include <pic18_usb.h>
 #include <usb_desc_RTS.h>
 #include <usb.c>
 
 void main(){
 int16 DevSerialNumber;
 char iSerialNumber[6];
 DevSerialNumber = 0x1111;   // Retrieve Logger Serial Number from EEPROM
 
 sprintf(iSerialNumber,"%Lu",DevSerialNumber);
 USB_STRING_DESC[62] = iSerialNumber[0];                  // Copies the Logger Serial # into the USB iSerialNumber descriptior
 USB_STRING_DESC[64] = iSerialNumber[1];
 USB_STRING_DESC[66] = iSerialNumber[2];
 USB_STRING_DESC[68] = iSerialNumber[3];
 USB_STRING_DESC[70] = iSerialNumber[4];
 }
 | 
 
 Note: usb_desc_RTS.h is just a modified version of usb_desc_scope.h.  You also need to add 'string 3' for the serial number (see clip below).  Then figure out the location where the serial number will start.  For my modified version the serial number 'string 3' starts at location 62, so the above code overwrites '19190' with 0x1111
 
 
  	  | Code: |  	  | char USB_STRING_DESC[]={
 //string 0
 4, //length of string index
 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
 0x09,0x04,   //Microsoft Defined for US-English
 //string 1
 8, //length of string index
 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
 'X',0,
 'Y',0,
 'Z',0,
 //string 2
 48, //length of string index ((lines + 1) x 2)
 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
 'D',0,
 'e',0,
 's',0,
 'c',0,
 'r',0,
 'i',0,
 'p',0,
 't',0,
 'i',0,
 'o',0,
 'n',0,
 ' ',0,
 'H',0,
 'e',0,
 'r',0,
 'e',0,
 ' ',0,
 '.',0,
 '.',0,
 '.',0,
 '.',0
 '.',0,
 '.',0,
 //string 3
 12, //length of string index
 USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
 '1',0,
 '9',0,
 '1',0,
 '9',0,
 '0',0
 };
 | 
 |  |  
		|  |  
		| ChristianE 
 
 
 Joined: 28 Apr 2009
 Posts: 1
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed May 30, 2012 9:46 am |   |  
				| 
 |  
				| The catch regarding the "Expecting LVALUE such as a variable name or *expression" error is that the USB_STRING_DESC is declared as a CONST in the default descriptor files.  remove the CONST and everything should work. 
 Christian
 |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |