<?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>Little FS mount issues</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105600/little-fs-mount-issues</link><description>Hi, 
 We had the UICR used to store our persistent data relevant for a coap client. Recently I saw a hard fault occurring sometimes when we try to access UICR. Further research to this showed its not advisable to use UICR as accessing UICR will halt the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 13 Nov 2023 14:16:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105600/little-fs-mount-issues" /><item><title>RE: Little FS mount issues</title><link>https://devzone.nordicsemi.com/thread/455328?ContentTypeID=1</link><pubDate>Mon, 13 Nov 2023 14:16:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c425efa-ff4e-4f40-b4a9-88336d5b1aa2</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Kaushalya&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve had a &lt;em&gt;&lt;strong&gt;very quick&lt;/strong&gt;&lt;/em&gt; look at the code and I can&amp;#39;t see any issues with it. However I recommend that you run tests and set up some routine to catch edge cases so you can verify in your own environment that the code works as you&amp;#39;ve designed it to do&lt;/p&gt;
&lt;p&gt;We also have the settings sample that you can base your application on and have a look at:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/settings/README.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/settings/README.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Little FS mount issues</title><link>https://devzone.nordicsemi.com/thread/455208?ContentTypeID=1</link><pubDate>Sun, 12 Nov 2023 09:28:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e0185c7-cb68-4909-b5b1-a4069ba69dba</guid><dc:creator>kaushalyasat</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think I managed to fix it by dropping the liitleFS mount and just using settings subsystem.&lt;/p&gt;
&lt;p&gt;My current prj.conf is as follows. (just the part relevant for Settings subsystem)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_NVS=y
CONFIG_SETTINGS_NVS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y

CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y

# CONFIG_FLASH=y
# CONFIG_FLASH_PAGE_LAYOUT=y
# CONFIG_FLASH_MAP=y
# CONFIG_FILE_SYSTEM=y
# CONFIG_FILE_SYSTEM_LITTLEFS=y
# CONFIG_SETTINGS_FS=y
# CONFIG_SETTINGS_FS_FILE=&amp;quot;/lfs/settings&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;Then I added the following code for direct access (without a handler as I am not 100% clear about it)&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct direct_immediate_value {
	size_t len;
	void *dest;
	uint8_t fetched;
};

static int direct_loader_immediate_value(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg, void *param) {
	const char *next;
	size_t name_len;
	int rc;
	struct direct_immediate_value *one_value = (struct direct_immediate_value *)param;

	name_len = settings_name_next(name, &amp;amp;next);

	if (name_len == 0) {
		if (len == one_value-&amp;gt;len) {
			rc = read_cb(cb_arg, one_value-&amp;gt;dest, len);
			if (rc &amp;gt;= 0) {
				one_value-&amp;gt;fetched = 1;
				return 0;
			}

			LOG_ERR(&amp;quot;load fail %d&amp;quot;, rc);
			return rc;
		}
		return -EINVAL;
	}

	/* other keys aren&amp;#39;t served by the callback
	 * Return success in order to skip them
	 * and keep storage processing.
	 */
	return 0;
}

int load_immediate_value(const char *name, void *dest, size_t len)
{
	int rc;
	struct direct_immediate_value dov;

	dov.fetched = 0;
	dov.len = len;
	dov.dest = dest;

	rc = settings_load_subtree_direct(name, direct_loader_immediate_value, (void *)&amp;amp;dov);
	if (rc == 0) {
		if (!dov.fetched) {
			rc = -ENOENT;
		}
	}

	return rc;
}

void settings_initiallization (void) {
	int rc;

#if IS_ENABLED(CONFIG_FILE_SYSTEM_LITTLEFS)
	FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);

	/* mounting info */
	static struct fs_mount_t littlefs_mnt = {
		.type = FS_LITTLEFS,
		.fs_data = &amp;amp;storage,
		.storage_dev = (void *)FLASH_AREA_ID (storage),
		.mnt_point = &amp;quot;/lfs&amp;quot;
	};

	rc = fs_mount(&amp;amp;littlefs_mnt);

	if (rc != 0) {
		LOG_ERR (&amp;quot;mounting littlefs error: [%d]\n&amp;quot;, rc);
	} else {

		rc = fs_unlink(CONFIG_SETTINGS_FS_FILE);

		if ((rc != 0) &amp;amp;&amp;amp; (rc != -ENOENT)) {
			LOG_ERR (&amp;quot;can&amp;#39;t delete config file%d&amp;quot;, rc);
		} else {
			LOG_INF (&amp;quot;FS initialized: OK&amp;quot;);
		}
	}
#endif

	rc = settings_subsys_init();
	if (rc) {
		LOG_ERR (&amp;quot;settings subsys initialization: fail (err %d)&amp;quot;, rc);
		return;
	}

	LOG_INF (&amp;quot;settings subsys initialization: OK&amp;quot;);
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then the read / write code is as follows.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int eraseIPV6inFlash () {
	int rc;
	uint32_t flag = 0x00000000;
	uint32_t hostIP = 0x00000000;
	uint16_t hostFWver = 0x0000;

	rc = settings_save_one (&amp;quot;flag&amp;quot;, (const void *)&amp;amp;flag, sizeof(flag));	// erase flag
	if (rc != 0) {
		LOG_ERR (&amp;quot;unexpected error eraseing flag&amp;quot;, rc);
	}
	rc = settings_save_one (&amp;quot;hostIP&amp;quot;, (const void *)&amp;amp;hostIP, sizeof(hostIP));	// erase host IP
	if (rc != 0) {
		LOG_ERR (&amp;quot;unexpected error erasing host IP&amp;quot;, rc);
	}
	rc = settings_save_one (&amp;quot;hostFWver&amp;quot;, (const void *)&amp;amp;hostFWver, sizeof(hostFWver));	// erase host fw ver
	if (rc != 0) {
		LOG_ERR (&amp;quot;unexpected error host FW ver&amp;quot;, rc);
	}
	
	return rc;
}

void restoreIPV6fromFlash (uint32_t *myExtAddr) {
	int rc;
	uint32_t hostIP[4];

	rc = load_immediate_value(&amp;quot;hostIP&amp;quot;, &amp;amp;hostIP, sizeof(hostIP));
	if (rc == -ENOENT) {
		LOG_ERR (&amp;quot;host IP value not found!!&amp;quot;);
	} 
	else if (rc == 0) {		// valid host IP value read
		LOG_INF (&amp;quot;Restore host IP %x&amp;quot;, *myExtAddr);

	} else 
		LOG_ERR (&amp;quot;unexpected error %d&amp;quot;, rc);

	*myExtAddr = hostIP [0];
	*(myExtAddr+1) = hostIP [1];
	*(myExtAddr+2) = hostIP [2];
	*(myExtAddr+3) = hostIP [3];
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please let me know what I have done is correct.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Kaushalya&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>