<?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>Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92440/settings-subsystem-init-fails-nvs-backend</link><description>Hi, Working with nRF5340 in NCS 1.9.2, I&amp;#39;ve overridden weak usb_update_sn_string_descriptor function to set iSerialNumber at runtime. I wanted to read the actual serial number from settings subsystem, backend-ed in internal flash (NVS). Code looks like</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Oct 2022 11:38:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92440/settings-subsystem-init-fails-nvs-backend" /><item><title>RE: Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/thread/390246?ContentTypeID=1</link><pubDate>Tue, 11 Oct 2022 11:38:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53b2a28a-6174-4e6d-88ec-71d278683ed6</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;br /&gt;the suggested change works fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/thread/389922?ContentTypeID=1</link><pubDate>Mon, 10 Oct 2022 05:34:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4c221be-63ee-4e84-9550-31ae7a24a601</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;OK, I overlooked at the problem, sorry it was my bad.&lt;/p&gt;
&lt;p&gt;The function you have modified (usb_update_sn_string_descriptor) is called from usb_device_init which in turn is called in the early stage of device bootup as shown in the usb_device.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;SYS_INIT(usb_device_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is initialized with the &lt;a href="https://docs.zephyrproject.org/3.1.0/kernel/drivers/index.html#c.SYS_INIT"&gt;SYS_INIT&lt;/a&gt;&amp;nbsp;POST_KERNEL level, and I do not think that the device tree macros are available at this level.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So now use the original code you posted (not using work queues) and try to change the usb_device.c last line to below to use APPLICATION level initialization.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;SYS_INIT(usb_device_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/thread/389604?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 11:41:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f311bef9-d66f-439f-b726-7597fb1db27f</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;br /&gt;this is the exemplified code&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];
static uint32_t val = 0;
static struct k_work_delayable pending_work;
static void mywork(struct k_work *work)
{
    if (IS_ENABLED(CONFIG_SETTINGS)) {
        ...
        val = 123456789;
    }
}

uint8_t *usb_update_sn_string_descriptor(void)
{
    k_work_init_delayable(&amp;amp;pending_work, mywork);
    k_work_schedule(&amp;amp;pending_work, K_MSEC(3000));

    snprintk(sn, sizeof(sn), &amp;quot;%u&amp;quot;, val);
    return sn;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Actually &lt;em&gt;mywork()&lt;/em&gt; execution happens 3 s after &lt;em&gt;usb_update_sn_string_descriptor()&lt;/em&gt;.&lt;br /&gt;The problem is that &lt;em&gt;usb_update_sn_string_descriptor()&lt;/em&gt; will not return the desired (&lt;em&gt;val&lt;/em&gt;) value set by &lt;em&gt;mywork()&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;How to solve this ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/thread/389172?ContentTypeID=1</link><pubDate>Tue, 04 Oct 2022 10:57:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25339a3c-44b7-4922-ae4a-44987986371b</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;yes, that is what I was thinking. to schedule a work item in your work queue and process&amp;nbsp;&lt;span&gt; &lt;/span&gt;if (IS_ENABLED(CONFIG_SETTINGS)) in that. Try it out to see if your device tree macro resolves to non NULL pointers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/thread/389057?ContentTypeID=1</link><pubDate>Mon, 03 Oct 2022 16:18:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94e52fd4-98d5-49bf-86fd-52a4d0007b01</guid><dc:creator>Gabriele</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;do you mean&lt;/p&gt;
&lt;p&gt;static struct k_work_delayable pending_work;&lt;br /&gt;static void mywork(struct k_work *work)&lt;br /&gt;{&lt;br /&gt; //do something&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;If yes, can you please help me to figure out where the&lt;/p&gt;
&lt;p&gt;k_work_schedule(&amp;amp;pending_work, mywork, K_MSEC(3000));&lt;/p&gt;
&lt;p&gt;has to be called ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Settings subsystem init fails (NVS backend)</title><link>https://devzone.nordicsemi.com/thread/388730?ContentTypeID=1</link><pubDate>Fri, 30 Sep 2022 10:37:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09bce7b0-1190-4105-b80f-e980a77b6288</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I think&amp;nbsp;usb_update_sn_string_descriptor is being called in the very early stage of kernel boot and hence that part of the device binding part is not ready yet?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;maybe you can create a work_queue item to push the execution of the whole if statement&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;	if (IS_ENABLED(CONFIG_SETT&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;onto a lower priority context (work_queue).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>