<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/2284" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2009-02-26T19:14:09+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/2284</id>

		<entry>
		<author><name><![CDATA[opcode]]></name></author>
		<updated>2009-02-26T19:14:09+02:00</updated>

		<published>2009-02-26T19:14:09+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8127#p8127</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8127#p8127"/>
		<title type="html"><![CDATA[Dynamic Serial Number at runtime]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8127#p8127"><![CDATA[
Thanks Grendel That was enough additional info to get it working <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /><br /><br />in usbconfig.h<br /><br /><div class="codebox"><p>Code: </p><pre><code>#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    &#40;USB_PROP_IS_DYNAMIC | USB_PROP_IS_RAM&#41;</code></pre></div><br /><br /><br />in main.c<br /><div class="codebox"><p>Code: </p><pre><code>#define SERIAL_NUMBER_LENGTH 6 // the number of characters required for your serial number<br /><br />static int  serialNumberDescriptor&#91;SERIAL_NUMBER_LENGTH + 1&#93;;<br /><br />uchar usbFunctionDescriptor&#40;usbRequest_t *rq&#41;<br />&#123;<br />   uchar len = 0;<br />   usbMsgPtr = 0;<br />   if &#40;rq-&gt;wValue.bytes&#91;1&#93; == USBDESCR_STRING &amp;&amp; rq-&gt;wValue.bytes&#91;0&#93; == 3&#41; // 3 is the type of string descriptor, in this case the device serial number<br />   &#123;<br />      usbMsgPtr = &#40;uchar*&#41;serialNumberDescriptor;<br />      len = sizeof&#40;serialNumberDescriptor&#41;;<br />   &#125;<br />   return len;<br />&#125;<br /><br /><br />static void SetSerial&#40;void&#41;<br />&#123;<br />   serialNumberDescriptor&#91;0&#93; = USB_STRING_DESCRIPTOR_HEADER&#40;SERIAL_NUMBER_LENGTH&#41;;<br />   serialNumberDescriptor&#91;1&#93; = 'S';<br />   serialNumberDescriptor&#91;2&#93; = 'e';<br />   serialNumberDescriptor&#91;3&#93; = 'r';<br />   serialNumberDescriptor&#91;4&#93; = 'i';<br />   serialNumberDescriptor&#91;5&#93; = 'a';<br />   serialNumberDescriptor&#91;6&#93; = 'l';<br />&#125;</code></pre></div><br /><br /><br />You must call SetSerial() before the USB is initialized to generate the serial number!<br /><br />Bob.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1841">opcode</a> — Thu Feb 26, 2009 7:14 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-02-26T03:52:42+02:00</updated>

		<published>2009-02-26T03:52:42+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8110#p8110</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8110#p8110"/>
		<title type="html"><![CDATA[Dynamic Serial Number at runtime]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8110#p8110"><![CDATA[
I didn't use a dynamic serial no. in my project but various other dynamic descriptors -- try something like this:<br /><br /><div class="codebox"><p>Code: </p><pre><code>uchar usbFunctionDescriptor&#40;usbRequest_t *rq&#41;<br />&#123;<br />   uchar *p = 0, len = 0;<br />   if&#40;rq-&gt;wValue.bytes&#91;1&#93; == USBDESCR_STRING &amp;&amp;<br />      rq-&gt;wValue.bytes&#91;0&#93; == &#91;your serial no. str index&#93;&#41;<br />   &#123;<br />     &#91;build your serial no. str descr. here, have p point to it&#93;<br /><br />     usbMsgPtr = p;<br />     len = &#91;your serial no. str descr. len&#93;<br />   &#125; <br />   return len; <br />&#125;</code></pre></div><br /><br />Note that if you build the descriptor in RAM USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER needs to be defined as (USB_PROP_IS_DYNAMIC | USB_PROP_IS_RAM). If you have predefined descriptors in FLASH, USB_PROP_IS_DYNAMIC will do.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Thu Feb 26, 2009 3:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[opcode]]></name></author>
		<updated>2009-02-25T20:19:50+02:00</updated>

		<published>2009-02-25T20:19:50+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8105#p8105</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8105#p8105"/>
		<title type="html"><![CDATA[Dynamic Serial Number at runtime]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=2284&amp;p=8105#p8105"><![CDATA[
I have spent quite some time trying to implement a dynamic serial number or device id or any other method of being able to select any one of several identical usb devices without success <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /><br />The Idea is to have several identical devices eg powerswitches, running identical firmware but be individually addressable by means of setting the serial number or device ID at runtime (or even at boot time) via jumper or dipswitch.<br /><br />I understand that you must define in usbconfig.h:<br /><div class="codebox"><p>Code: </p><pre><code>#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER USB_PROP_IS_DYNAMIC</code></pre></div><br /><br />and also implement in main.c:<br /><div class="codebox"><p>Code: </p><pre><code>uchar usbFunctionDescriptor&#40;usbRequest_t *rq&#41;<br />&#123;<br />   uchar *p = 0, len = 0;<br />   if&#40;rq-&gt;wValue.bytes&#91;1&#93; == ????????&#41;<br />   &#123;<br />   ???????     <br />   &#125;<br />   usbMsgPtr = p;<br />   return len;<br />&#125;</code></pre></div><br /><br />Does anyone have any working example or information on how to do this ?<br /><br />Thanks.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1841">opcode</a> — Wed Feb 25, 2009 8:19 pm</p><hr />
]]></content>
	</entry>
	</feed>
