<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF5340 - runtime change of iSerialNumber</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90475/nrf5340---runtime-change-of-iserialnumber</link><description>Hi, I wanted to change at runtime the iSerialNumber exposed by USB descriptor. As Kenneth suggested ( link ), the solution has been to override the weak function in usb_descriptor.c 
 weak uint8_t *usb_update_sn_string_descriptor(void) { snprintk(usb_serial_str</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Aug 2022 14:28:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90475/nrf5340---runtime-change-of-iserialnumber" /><item><title>RE: nRF5340 - runtime change of iSerialNumber</title><link>https://devzone.nordicsemi.com/thread/381816?ContentTypeID=1</link><pubDate>Tue, 16 Aug 2022 14:28:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c299d5b8-2671-44b8-843d-4ba49e258a9f</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Hello Susheel,&lt;br /&gt;I&amp;#39;ve overridden the &lt;em&gt;usb_update_sn_string_descriptor&lt;/em&gt; function for returning the actual serial number retrieved from settings subsystem, this way&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint8_t sn[sizeof(CONFIG_USB_DEVICE_SN) + 1];
uint8_t *usb_update_sn_string_descriptor(void)
{
	int rc;
	uint32_t val = COSMED_SN_DEFAULT;

	memset(sn, 0, sizeof(sn));

	rc = settings_subsys_init();
	if (rc) {
		LOG_ERR(&amp;quot;error initializing settings subsys [%d]&amp;quot;, rc);
	} else {
		rc = load_immediate_value(&amp;quot;id/sn&amp;quot;, &amp;amp;val, sizeof(val));
		if (rc == -ENOENT) {
			val = COSMED_SN_DEFAULT;
		} else if (rc == 0) { 
			printk(&amp;quot;&amp;lt;id/sn&amp;gt; = %u\n&amp;quot;, val);
		} else {
			LOG_ERR(&amp;quot;error loading sn from settings [%d]&amp;quot;, rc);
		}
	}

	LOG_WRN(&amp;quot;TODO: manage to store sn in settings from user input&amp;quot;);
	//rc = settings_save_one(&amp;quot;id/sn&amp;quot;, (const void *)&amp;amp;val, sizeof(val));

	snprintk(sn, sizeof(sn), &amp;quot;%u&amp;quot;, val);

	return sn;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The very first print out of console is &lt;strong&gt;&amp;quot;error initializing settings subsys [-19]&amp;quot;&lt;/strong&gt;.&lt;br /&gt;This is a ENODEV return of &lt;em&gt;settings_subsys_init()&lt;/em&gt;.&lt;br /&gt;For some reason the settings subsystem cannot be initialized at such an early stage of start up.&lt;/p&gt;
&lt;p&gt;By the way, calling &lt;em&gt;settings_subsys_init()&lt;/em&gt; at the beginning of &lt;em&gt;main()&lt;/em&gt; doesn&amp;#39;t rise this exception.&lt;/p&gt;
&lt;p&gt;A hand needed. Thanks in advance&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - runtime change of iSerialNumber</title><link>https://devzone.nordicsemi.com/thread/380079?ContentTypeID=1</link><pubDate>Thu, 04 Aug 2022 10:19:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e01a213b-b3f7-4acc-a0b2-b2459c0f13ac</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;If you want to persistently store the serial number in flash, then store it at know address (or key/value) location.&lt;/p&gt;
&lt;p&gt;inside&amp;nbsp;&lt;span&gt;usb_update_sn_string_descriptor, you can load the value in that address location&amp;nbsp;to see if there is any data saved. If there is none, save the serial number and use that instead of sn_recovered_from_littlefs.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]What&amp;#39;s the storage location of the iSerialNumber &amp;quot;D0766E074450A9F0&amp;quot; the nRF5340 uses if untouched ?[/quote]
&lt;p&gt;Right now, it seems it lives in the .bss section allocated by the compiler. Unless you created a linker script to save&amp;nbsp;string_descr (in&amp;nbsp;zephyr\subsys\usb\device\usb_descriptor.c)&amp;nbsp; at a specified location, you do not have control on where that is saved.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - runtime change of iSerialNumber</title><link>https://devzone.nordicsemi.com/thread/379592?ContentTypeID=1</link><pubDate>Mon, 01 Aug 2022 15:46:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08570ad9-7a9f-4b85-9d7f-0c115f3fecd5</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Hi Susheel&lt;/p&gt;
&lt;p&gt;Could you please&amp;nbsp;expand a bit more&amp;nbsp;your idea ?&lt;/p&gt;
&lt;p&gt;Consider that each board&amp;nbsp;has a serial number, which is uniquely assigned at some stage of manufacturing. This serial number shall be persistently stored in flash, and assigned to iSerialNumber.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - runtime change of iSerialNumber</title><link>https://devzone.nordicsemi.com/thread/379127?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 12:40:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb087f1a-8af7-4c9e-a5af-bbfc3982e8ca</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;It seems to be kept in global memory space which means it is different for different application. You can probably attempt to write a linker file to create a memory section and keep this structure defined in&amp;nbsp;zephyr\subsys\usb\device\usb_descriptor.c&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>