<?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>Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87109/problems-writing-reading-struct-to-nvs</link><description>I&amp;#39;ve been slowly adding NVS functionality to my code. Has been working fine, up until today when I attempted to write a struct I have for storing historical data to flash. 
 This is the struct: 
 
 I then have an array of this struct. At this point, MAX_STRIKE_RECORDS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 22 Jul 2022 10:08:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87109/problems-writing-reading-struct-to-nvs" /><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/378254?ContentTypeID=1</link><pubDate>Fri, 22 Jul 2022 10:08:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e61d6fa3-e424-4506-870f-7c59b8cbf37b</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Earlier you said that&amp;nbsp;&lt;span&gt;CONFIG_PARTITION_MANAGER_ENABLED&amp;nbsp;was set, which means that all the flash partitions in DTS are ignored, including the &lt;em&gt;storage_partition&lt;/em&gt; you&amp;#39;ve attached in the previous reply.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Have you disabled the Partition Manager since then? Could you&amp;nbsp;upload your build folder, so I can check if the partition manager is enabled or not?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/376865?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2022 04:54:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18915318-fb3f-49d6-9093-36cbc96d6af3</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;OK, think I&amp;#39;ve answered a few of my questions:&lt;/p&gt;
&lt;p&gt;1. &amp;quot;storage&amp;quot; is defined in the .dts as&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;storage_partition: partition@7a000 {
			label = &amp;quot;storage&amp;quot;;
			reg = &amp;lt;0x0007a000 0x00006000&amp;gt;;
		};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The 0x80000 limit obviously corresponds to the offset of 0x7a000 and size of 0x6000.&amp;nbsp; I&amp;#39;m assuming I can&amp;#39;t modify that to increase the storage area, as I&amp;#39;ll run into issues with available flash?&lt;/p&gt;
&lt;p&gt;2. By moving the offset of user_storage to 0x7a000, I can get the extra space I would need, without running into issues with having to reduce the amount of settings_storage (which I think might be the cause of my BLE advertising issues, but I can&amp;#39;t be sure).&lt;/p&gt;
&lt;p&gt;The question of why I run into storage issues when I appear to have plenty of space left is still baffling me though.&amp;nbsp; I&amp;#39;m assuming that the API&amp;#39;s take care of things so that if I have 2000 bytes of data, I only need to consume 2000 bytes (or thereabouts) of flash.&amp;nbsp; I know when I was using the Cypress chips, their flash was arranged in blocks, and if I wanted to write one byte to flash, I actually needed to use up an entire row (up to 256 bytes depending upon the size of flash in the chip), unless I was able to shoe-horn all my data into a 256 byte array and then write it all to the one row.&amp;nbsp; Just thinking if the reason I get the -28 error when I&amp;#39;ve got more than 195 strike records has something to do with how the API&amp;#39;s are arranging that data in flash&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/376854?ContentTypeID=1</link><pubDate>Wed, 13 Jul 2022 21:24:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b3fe7e1-c1a7-491e-af8b-26180259de0d</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;OK, thanks for all that info.&amp;nbsp; Gotta say, you&amp;#39;re up there with Carl on your ability to stick with a problem!! :-)&lt;/p&gt;
&lt;p&gt;I put in a call to that calculate free space API to see what was going on.&amp;nbsp; I put this in at the initialisation (prior to actually storing anything in flash) and then again each time I did a write to flash.&lt;/p&gt;
&lt;p&gt;With MAX_STRIKE_RECORDS set to 195, I&amp;#39;m expecting to see flash useage of 2036 bytes (this includes the 8 byte allowance for ate_size, for 1 byte for ID and 8 bytes for meta data for each thing I&amp;#39;m writing to flash and the actual data I&amp;#39;m trying to store)&lt;/p&gt;
&lt;p&gt;After initialisation, its telling me I have total user storage of 8192 (2 sectors at 4096 per sector).&amp;nbsp; Obviously I really only have one of these available to me, so 4096.&amp;nbsp; The&amp;nbsp;nvs_calc_free_space(&amp;amp;fs) API is saying I have 4088, so there is a little bit of overhead I&amp;#39;ve not accounted for, but its only 6 bytes.&amp;nbsp; On track so far.&lt;/p&gt;
&lt;p&gt;When I do a write of all my various info to flash, as mentioned above I&amp;#39;m expecting to see 2036 bytes consumed, so my free space should drop down to 4088 - 8 - 2036&amp;nbsp; = 2044.&amp;nbsp; The figure I get is 2044.&amp;nbsp; So, things seem OK.&amp;nbsp; And my code is working, storing things in flash.&lt;/p&gt;
&lt;p&gt;Now, if I bump the value of MAX_STRIKE_RECORDS up to 200, I am expecting that the memory I will need will increase to 2089, and my free memory will drop down to 1991 (4088 - 8 - 2089 = 1991).&amp;nbsp; I&amp;#39;m actually seeing a result of 1996 from that API.&amp;nbsp; So close, but not exact.&lt;/p&gt;
&lt;p&gt;But the problem is now, that my return value from&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;val = nvs_write(&amp;amp;fs, &lt;/span&gt;&lt;span&gt;LOG_DATA_ID&lt;/span&gt;&lt;span&gt;, &amp;amp;lsr_strike_log, &lt;/span&gt;&lt;span&gt;sizeof&lt;/span&gt;&lt;span&gt;(lsr_strike_log));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;is now giving me the value -28, which corresponds to no space left on device.&amp;nbsp; So, even though I have ~ 1900 bytes of space available, its bombing out thinking there isn&amp;#39;t enough space.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;I then tried increasing my sector count to 3 (currently 2).&amp;nbsp; This means I need 3 x 4096 = 12,288 bytes of user storage (0x3000).&amp;nbsp; So, I change my fixed partitions as follows:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;user_storage:
  address: 0x7c000
  size: 0x3000
  placement:
    before: 
    - settings_storage
  region: flash_primary
settings_storage:
  address: 0x7f000
  size: 0x2000
  placement:
    before:
    - end
  region: flash_primary&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;That causes by build to crash with the following error:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;-- Found partition manager static configuration: C:/Nordic/Development/LSR-MAX/LSR-MAX_V0_09/pm_static.yml
Partition &amp;#39;settings_storage&amp;#39; is not included in the dynamic resolving since it is statically defined.
Partition manager failed: Incorrect amount of gaps found in static configuration. There must be exactly one gap in the static configuration to support placing the dynamic partitions (such as &amp;#39;app&amp;#39;). Gaps found (2):0x0-0x7c000 0x81000-0x80000 The most common solution to this problem is to fill the smallest of these gaps with statically defined partition(s) until there is only one gap left. Alternatively re-order the already defined static partitions so that only one gap remains.
Failed to partition region flash_primary, size of region: 524288
Partition Configuration:
mcuboot:
  placement:
    before:
    - mcuboot_primary
  size: 49152
mcuboot_pad:
  placement:
    align:
      start: 4096
    before:
    - mcuboot_primary_app
  size: 512
settings_storage:
  placement:
    before:
    - end
  size: 8192
user_storage:
  placement:
    before:
    - settings_storage
  size: 12288&lt;/pre&gt;Which seems to suggest I&amp;#39;m not allowed to go past memory location 0x80000.&amp;nbsp; Is that correct?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Anyway, if I peg back my settings_storage to compensate, so my fixed partitions now look like this:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;user_storage:
  address: 0x7c000
  size: 0x3000
  placement:
    before: 
    - settings_storage
  region: flash_primary
settings_storage:
  address: 0x7f000
  size: 0x1000
  placement:
    before:
    - end
  region: flash_primary&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Everything builds OK.&amp;nbsp; And I can now see I have 8176 bytes of flash just after its all initialised, and then after my first write to flash (I&amp;#39;ve got MAX_STRIKE_RECORDS set to 200 here), I see I have 6084 bytes free.&amp;nbsp; Seems pretty close to 8176 - 2089 = 6087.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;BUT, and this is the bit I don&amp;#39;t understand, now my Bluetooth advertising won&amp;#39;t work.&amp;nbsp; The call to&lt;/span&gt;&lt;/span&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;err = bt_le_adv_update_data(ad, &lt;/span&gt;&lt;span&gt;ARRAY_SIZE&lt;/span&gt;&lt;span&gt;(ad), sd, &lt;/span&gt;&lt;span&gt;ARRAY_SIZE&lt;/span&gt;&lt;span&gt;(sd)); returns an error of -11.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span&gt;Maybe its got something to do with me reducing the settings_storage to much, I&amp;#39;m not sure.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;So, I&amp;#39;m a bit stuck.&amp;nbsp; I can&amp;#39;t work out why my flash write bombs out when I&amp;#39;ve still got plenty of space, and I can&amp;#39;t work out how to increase the available space to fix this, without impacting on something else!&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Cheers,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Mike&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/376829?ContentTypeID=1</link><pubDate>Wed, 13 Jul 2022 16:31:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfbe8270-a097-4863-83f3-92cf915ce08f</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I didn&amp;#39;t get time to look to deeply into this today, but I&amp;#39;ll just leave one comment. If I remember correctly,&amp;nbsp;&lt;span&gt;one sector almost always free - it is used during garbage-collection procedrue. So I think you have to subtract one sector, and that is the available area you can use.&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Down below I&amp;#39;ve copied in a reply I made more than a year ago in another ticket:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you look at the start of the sample&amp;nbsp;zephyr\samples\subsys\nvs\src\main.c,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/d5a653348eeab5a3bd6305e4f1cd2d6dcf56774a/samples/subsys/nvs/src/main.c#L91-L94"&gt;the sector size and sector count is fed into nvs_init()&lt;/a&gt;. The sector size and sector count decides how much memory is allocetd for NVS and the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/d5a653348eeab5a3bd6305e4f1cd2d6dcf56774a/samples/subsys/nvs/src/main.c#L85"&gt;offset&lt;/a&gt;&amp;nbsp;decides where in flash to place the NVS partition. Other flash procedures will not (and should not) touch the NVS area.&lt;/p&gt;
&lt;p&gt;The available memory for the sample&amp;nbsp;&lt;span&gt;&amp;nbsp;zephyr\samples\subsys\nvs can be calculated in the following manner&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ate_size = 8, sector_size = 4096 (check&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://devzone.nordicsemi.com/support-private/support/266415#permalink=646475"&gt;this reply&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;for an explanation of these numbers (I used the 52840 during testing as well))&lt;/code&gt;&lt;br /&gt;&lt;code&gt;sector_count = 3 (it&amp;#39;s set&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/d5a653348eeab5a3bd6305e4f1cd2d6dcf56774a/samples/subsys/nvs/src/main.c#L92"&gt;here&lt;/a&gt;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;available_sectors = sector count - 1 (subtract 1, since one sector is free and used for garbage collection procedure)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;available NVS memory = sector_size * available_sectors - ate_size * available_sectors (read&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://devzone.nordicsemi.com/support-private/support/266415#permalink=646475"&gt;this reply&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to understnd why we need to subtract ate_size*av. sectors)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;available NVS memory = 4096 * 2 - 8 * 2 = 8176&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I tested this out, by adding the following code to the sample&amp;nbsp;&lt;span&gt;zephyr\samples\subsys\nvs:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;	rc = nvs_init(&amp;amp;fs, flash_dev-&amp;gt;name);
	if (rc) {
		printk(&amp;quot;Flash Init failed\n&amp;quot;);
		return;
	}
	ssize_t free_space = nvs_calc_free_space(&amp;amp;fs);
	printk(&amp;quot;Free space: %d (should be %d)\n&amp;quot;, free_space, fs.sector_size*(fs.sector_count-1)-(8*2));
	strcpy(buf, &amp;quot;abcdefghijklmnopqstuvwxyzabcdefghijklmnopqstuvwxyabcdefghijklmnopqstuvwxyzabcdefghijklmnopqstuvwxyz&amp;quot;);
	printk(&amp;quot;Write %d bytes\n&amp;quot;, strlen(buf)+1);
	(void)nvs_write(&amp;amp;fs, ADDRESS_ID, &amp;amp;buf, strlen(buf)+1);
	free_space = nvs_calc_free_space(&amp;amp;fs);
	printk(&amp;quot;Free space: %d\n&amp;quot;, free_space);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I then got the following output:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;Free space: 8176 (should be 8176)&lt;br /&gt;Write 100 bytes&lt;br /&gt;Free space: 8068&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, the output corresponds to the calculations.&lt;/p&gt;
&lt;p&gt;The free space after writing is not&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;8176-100=8076&lt;/code&gt;, but 8068, which is because each stored record requires 8 bytes of metadata in addition (as mentioned in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.8.0/zephyr/reference/storage/nvs/nvs.html#non-volatile-storage-nvs"&gt;NVS documentation&lt;/a&gt;), which gives&amp;nbsp;&lt;code&gt;&lt;span&gt;8176 - 100 - 8 = 8068&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/376692?ContentTypeID=1</link><pubDate>Wed, 13 Jul 2022 03:48:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db0cfced-3af5-490f-b52b-e54ea3726f39</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Thanks for sticking with me on this!&lt;/p&gt;
&lt;p&gt;OK, I&amp;#39;m getting things working, but I&amp;#39;m still coming unstuck when I try and push the size of my data logging array up towards the size I want it.&amp;nbsp; I&amp;#39;m clearly not understanding how the flash is arranged/configured. Or there is something else at play&lt;/p&gt;
&lt;p&gt;At the moment, I have the static partitions configured as follows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;user_storage:
  address: 0x7c000
  size: 0x2000
  placement:
    before: 
    - settings_storage
  region: flash_primary
settings_storage:
  address: 0x7e000
  size: 0x2000
  placement:
    before:
    - end
  region: flash_primary&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m outputting my flash and user info data via UART so I can check everything is OK.&amp;nbsp; This is what I get with the above configuration, and with the number of sectors set to 2.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Sector size = 4096
Sector count = 2
Sector size*count = 8192
User storage = 8192&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now, what I&amp;#39;m writing to flash consists of the following:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;	(void)nvs_write(&amp;amp;fs, TOTAL_STRIKE_COUNT_ID, &amp;amp;strike_count_total, sizeof(strike_count_total));
	(void)nvs_write(&amp;amp;fs, STRIKE_SML_ID, &amp;amp;strike_count_sml, sizeof(strike_count_sml));
	(void)nvs_write(&amp;amp;fs, STRIKE_MED_ID, &amp;amp;strike_count_med, sizeof(strike_count_med));
	(void)nvs_write(&amp;amp;fs, STRIKE_LRG_ID, &amp;amp;strike_count_lrg, sizeof(strike_count_lrg));
	(void)nvs_write(&amp;amp;fs, LOG_DATA_ID, &amp;amp;lsr_strike_log, sizeof(lsr_strike_log));&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;These are defined as:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define MAX_STRIKE_RECORDS 150

uint16_t strike_count_total = 0;
uint16_t strike_count_sml = 0;
uint16_t strike_count_med = 0;
uint16_t strike_count_lrg = 0;

struct log_data {
	uint8_t	strike_level;  // SML = 1, MED = 2 or LRG = 4
	uint16_t year;
	uint8_t month;
	uint8_t day;
	uint8_t hours;
	uint8_t minutes;
	uint8_t seconds;
};

struct log_data lsr_strike_log[MAX_STRIKE_RECORDS];
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What I&amp;#39;m trying to do is make enough flash space available to be able to store all that, but with MAX_STRIKE_RECORDS = 250.&amp;nbsp; At the moment, things go pear shaped with MAX_STRIKE_RECORDS &amp;gt; 195.&amp;nbsp; And I&amp;#39;m not sure why, nor what to do about it.&amp;nbsp; By my reckoning, I have more than enough space, but it almost seems like what I&amp;#39;m trying to store is consuming twice what I think it is.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;From here:&amp;nbsp;&lt;a id="" href="https://docs.zephyrproject.org/latest/services/storage/nvs/nvs.html"&gt;https://docs.zephyrproject.org/latest/services/storage/nvs/nvs.html&lt;/a&gt;&amp;nbsp;it looks like each of the elements being stored in flash needs:&lt;/p&gt;
&lt;p&gt;8 bytes of meta-data + 1 byte of id + sizeof(data).&lt;/p&gt;
&lt;p&gt;I have 8 elements in total (key, batch, serial, total, sml, med, lrg and log)&lt;/p&gt;
&lt;p&gt;Each one of my lsr_strike_log array elements seems to use up 10 bytes of data.&lt;/p&gt;
&lt;p&gt;So, by my calcs, the total amount of flash storage for 250 records is:&lt;/p&gt;
&lt;p&gt;key = 8 + 1 + 3 = 12&lt;/p&gt;
&lt;p&gt;batch = 8 + 1 + 4 = 13&lt;/p&gt;
&lt;p&gt;serial = 8 + 1 + 2 = 11&lt;/p&gt;
&lt;p&gt;total = 8 + 1 + 2 = 11&lt;/p&gt;
&lt;p&gt;sml = 8 + 1 + 2 = 11&lt;/p&gt;
&lt;p&gt;med = 8 + 1 + 2 = 11&lt;/p&gt;
&lt;p&gt;lrg = 8 + 1 + 2 = 11&lt;/p&gt;
&lt;p&gt;log = 8 + 1 + 250x10 = 2509&lt;/p&gt;
&lt;p&gt;Which gives me 2589 bytes.&amp;nbsp; I have 4096 in each sector, which seems ample to me.&amp;nbsp; But things bomb out when I go past MAX_STRIKE_RECORDS = 195.&amp;nbsp; This requires 2039 bytes in total.&amp;nbsp; Which is almost exactly half the size of one sector (4096 bytes).&lt;/p&gt;
&lt;p&gt;If I set MAX_STRIKE_RECORDS &amp;gt; 195, then when I try and write the log data to flash via:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;val = nvs_write(&amp;amp;fs, LOG_DATA_ID, &amp;amp;lsr_strike_log, sizeof(lsr_strike_log));
if (val &amp;lt; 0)
{
	printk(&amp;quot;Return val on log data write  = %d\n&amp;quot;, val);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I get a return value of -28, which equates to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ENOSPC 28       /**&amp;lt; No space left on device */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So, my questions are:&lt;/p&gt;
&lt;p&gt;1. Why, when it looks like I&amp;#39;ve got more than enough user storage allocated, do I run out of room?&lt;/p&gt;
&lt;p&gt;2. How can I increase my user storage so I have enough room for 250 log array elements?&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/376447?ContentTypeID=1</link><pubDate>Mon, 11 Jul 2022 13:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fdd5c8b-6b01-4e26-ab20-7b315789c6f1</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I played around with the NVS sample and made it use the Partition Manager (PM) instead of DTS (did this by setting CONFIG_BOOTLOADER_MCUBOOT=y, since PM will be used when child images are added).&lt;/p&gt;
&lt;p&gt;I was able to make it work with nrf52dk_nrf52832 and NCS v2.0.0&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/nvs_5F00_prt_5F00_mngr.zip"&gt;devzone.nordicsemi.com/.../nvs_5F00_prt_5F00_mngr.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If the PM is enabled the macros used&amp;nbsp;(&lt;code&gt;FLASH_AREA_OFFSET()&lt;/code&gt; for example), will get info from PM instead of DTS. See&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/include/zephyr/storage/flash_map.h#L259-L261"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/include/zephyr/storage/flash_map.h#L259-L261&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/include/flash_map_pm.h#L37-L38"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.0.0/include/flash_map_pm.h#L37-L38&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One thing you should be aware of, don&amp;#39;t let NVS use the area outside the custom partition. Make sure (sector size)*(sector count) is smaller than&amp;nbsp;user_storage.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/376093?ContentTypeID=1</link><pubDate>Thu, 07 Jul 2022 23:59:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6c59012-aa61-47b8-b121-864c8a28b9dc</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Did a bit more digging.&amp;nbsp; The issue is in fact when I try and get the flash page info.&amp;nbsp; I think the BLE thing is a side issue.&lt;/p&gt;
&lt;p&gt;I trawled through the DevZone and found this, which seems to be along similar lines to what I&amp;#39;m doing:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/80581/issue-with-flash-partitions-in-ncs-1-7-0-on-nrf9160"&gt;Issue with flash partitions in NCS 1.7.0 on nRF9160&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is what my flash initialisation function now looks like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int16_t flash_initialise(void)
{
    int16_t rc;

	//flash_dev = DEVICE_DT_GET(FLASH_NODE);
	flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
	if (!device_is_ready(flash_dev)) {
		#ifdef DEBUG_NVS
			printk(&amp;quot;Flash device %s is not ready\n&amp;quot;, flash_dev-&amp;gt;name);
		#endif
		return -EINVAL;
	}
	
	#ifdef DEBUG_NVS
		printk(&amp;quot;Flash device %s is ready\n&amp;quot;,flash_dev-&amp;gt;name);
	#endif

	fs.offset = FLASH_AREA_OFFSET(storage);
	rc = flash_get_page_info_by_offs(flash_dev, fs.offset, &amp;amp;info);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS		
			printk(&amp;quot;Unable to get page info\n&amp;quot;);
		#endif
		return rc;
	}
	#ifdef DEBUG_NVS
		printk(&amp;quot;Page info OK\n&amp;quot;);
	#endif
	fs.sector_size = info.size;
	fs.sector_count = NVS_SECTOR_COUNT;

	rc = nvs_init(&amp;amp;fs, flash_dev-&amp;gt;name);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS
			printk(&amp;quot;Flash Init failed\n&amp;quot;);
		#endif
		return rc;
	}
	#ifdef DEBUG_NVS
		printk(&amp;quot;Flash initialised OK\n&amp;quot;);
	#endif

	// Check if data is stored in flash
	rc = check_for_nvs_key();
	return rc;
	
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So, I&amp;#39;m now getting the device via:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And that appears to be working.&amp;nbsp; But when I then attempt to get the offset for my NVS file system struct, via:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	fs.offset = FLASH_AREA_OFFSET(user_storage);
	rc = flash_get_page_info_by_offs(flash_dev, fs.offset, &amp;amp;info);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS		
			printk(&amp;quot;Unable to get page info\n&amp;quot;);
		#endif
		return rc;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still not successfully getting the page info, as I get the error message &amp;quot;Unable to get page info&amp;quot;&lt;/p&gt;
&lt;p&gt;Clearly, I&amp;#39;m not really understanding how, with the static partitions definition as opposed to those defined in the .DTS, I should be initialising my flash device.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/375911?ContentTypeID=1</link><pubDate>Thu, 07 Jul 2022 04:59:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2655a31-619b-43b3-9727-6f5e928ef2a9</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m definitely entering unchartered waters here now!&lt;/p&gt;
&lt;p&gt;OK, so this is what my partitions.yml file looked like before:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;mcuboot_primary_app:
  address: 0xc200
  end_address: 0x45000
  orig_span: &amp;amp;id002
  - app
  region: flash_primary
  size: 0x38e00
  span: *id002
mcuboot_secondary:
  address: 0x45000
  end_address: 0x7e000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_primary
  size: 0x39000
settings_storage:
  address: 0x7e000
  end_address: 0x80000
  placement:
    align:
      start: 0x1000
    before:
    - end
  region: flash_primary
  size: 0x2000
sram_primary:
  address: 0x20000000
  end_address: 0x20010000
  region: sram_primary
  size: 0x10000&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So, I created a pm_static.yml file as you suggested.&amp;nbsp; A simple copy and paste of the one Vidar listed threw up some errors associated with gaps in the memory (or something).&amp;nbsp; So, I made my pm_static.yml look like this so that the gaps in memory, as I saw it, were &amp;quot;plugged&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;user_storage:
  address: 0x80000
  size: 0x2000
  end_address: 0x82000
  placement:
    before: 
    - settings_storage
  region: flash_primary
settings_storage:
  address: 0x82000
  size: 0x2000
  end_address: 0x84000
  placement:
    before:
    - end
  region: flash_primary&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is giving me 0x2000 of settings_storage and an additional 0x2000 of user_storage, which in theory should be enough.&lt;/p&gt;
&lt;p&gt;Then, where I define my flash device, I have:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define STORAGE_NODE_LABEL user_storage
const struct device *flash_dev;
static struct nvs_fs fs;

// Initialise NVS and check for NVS key
// Presence of key means there is valid data stored in NVS
int16_t flash_initialise(void)
{
    int16_t rc;

	flash_dev = FLASH_AREA_DEVICE(STORAGE_NODE_LABEL);
	if (!device_is_ready(flash_dev)) {
		#ifdef DEBUG_NVS
			printk(&amp;quot;Flash device %s is not ready\n&amp;quot;, flash_dev-&amp;gt;name);
		#endif
		return -EINVAL;
	}
	
	#ifdef DEBUG_NVS
		printk(&amp;quot;Flash device %s is ready\n&amp;quot;,flash_dev-&amp;gt;name);
	#endif

	fs.offset = FLASH_AREA_OFFSET(STORAGE_NODE_LABEL);
	rc = flash_get_page_info_by_offs(flash_dev, fs.offset, &amp;amp;info);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS		
			printk(&amp;quot;Unable to get page info\n&amp;quot;);
		#endif
		return rc;
	}
	#ifdef DEBUG_NVS
		printk(&amp;quot;Page info OK\n&amp;quot;);
	#endif
	fs.sector_size = info.size;
	fs.sector_count = NVS_SECTOR_COUNT;

	rc = nvs_init(&amp;amp;fs, flash_dev-&amp;gt;name);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS
			printk(&amp;quot;Flash Init failed\n&amp;quot;);
		#endif
		return rc;
	}
	#ifdef DEBUG_NVS
		printk(&amp;quot;Flash initialised OK\n&amp;quot;);
	#endif

	// Check if data is stored in flash
	rc = check_for_nvs_key();
	return rc;
	
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I use my function flash_initialise to set up my storage*&lt;/p&gt;
&lt;p&gt;That all builds OK, and I can flash it to my DK.&amp;nbsp; Problem is, when my code fires up BLE advertising, the advertising fails to start, and I get error code &amp;quot;-EAGAIN&amp;quot; from the call to bt_le_adv_start_legacy(), which gets called as part of bt_le_adv_start().&lt;/p&gt;
&lt;p&gt;So, I&amp;#39;m doing something wrong, as when I go back to the dynamic memory allocation using the DTS, the problem goes away.&lt;/p&gt;
&lt;p&gt;Can you see anything obvious that I&amp;#39;m doing that would affect the BLE functionality?&lt;/p&gt;
&lt;p&gt;* As an aside, the nvs_init() that I call in flash_initialise() shows as deprecated when I build, but my code crashes when I replace that with the suggested alternative nvs_mount().&amp;nbsp; Not sure why.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/375757?ContentTypeID=1</link><pubDate>Wed, 06 Jul 2022 11:28:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47356ac7-6fad-4a9f-b38f-b63d196a4c81</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Ah, okay.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Check the note in the documentation about the&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/nrf/scripts/partition_manager/partition_manager.html#partition-manager"&gt;Partition Manager&lt;/a&gt;:&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;&amp;quot;When you build a multi-image application using the Partition Manager, the Device Tree Source flash partitions are ignored.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So you should create the storage partition through a pm_static.yml file&lt;/p&gt;
&lt;p&gt;Vidar provided one example how to go about this in this reply:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/77781/problem-to-read-back-flash-with-nvs-when-concurrent-use-with-bluetooth/331284"&gt;RE: Problem to read back flash with NVS when concurrent use with Bluetooth&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then you should be able to access the size and address of the user storage from your application (generated defines will be located in &amp;lt;sample&amp;gt;\build\zephyr\include\generated\pm_config.h I believe), which you can use to set up NVS to store custom data.&lt;/p&gt;
&lt;p&gt;By the way, Bluetooth bonding uses NVS as well (settings_storage), so that may interfere with your custom NVS data, in the ticket above that was resolved by creating a separate partition (user_storage).&lt;/p&gt;
&lt;p&gt;However, I think it should be possible to use the same partition for both cases, see&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/89470/concurrent-usage-of-nv-and-settings-on-the-same-partition"&gt;Concurrent usage of NV and settings on the same partition&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/375656?ContentTypeID=1</link><pubDate>Wed, 06 Jul 2022 05:13:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edb39622-d628-4fc5-a513-fd52729b920a</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Yes, I have partition manager enabled via:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;# Partition Manager&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;#&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_PARTITION_MANAGER_ENABLED=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_FLASH_MAP_CUSTOM=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_SRAM_SIZE=64&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_SRAM_BASE_ADDRESS=0x20000000&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Cheers,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Mike&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/375300?ContentTypeID=1</link><pubDate>Mon, 04 Jul 2022 11:59:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7222ddb-e2d3-4a69-a8b6-4f867aad4e75</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Sorry for the delay, I was gone on Friday.&lt;/p&gt;
&lt;p&gt;Could you check if the partition manager is enabled?&lt;/p&gt;
&lt;p&gt;You can do that by searching for&amp;nbsp;CONFIG_PARTITION_MANAGER_ENABLED in &amp;lt;sample&amp;gt;build/zephyr/.config and see if it&amp;#39;s set to &amp;#39;y&amp;#39;.&lt;/p&gt;
&lt;p&gt;Partition Manager is enabled when you&amp;#39;re including child images (like mcuboot) and the dts partitions will be ignored.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/374806?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 21:04:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4cca0498-7fd1-4464-8c79-d06a64274370</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;I seem to have this working now.&amp;nbsp; Only problem is, I&amp;#39;m not able to get everything I want stored in NVS as I am running out of room.&amp;nbsp; And I&amp;#39;m not sure how to make more space, or indeed if I can.&lt;/p&gt;
&lt;p&gt;My struct takes up 12 bytes per array element, and&amp;nbsp;I am trying to have capacity for up to 250 array elements.&amp;nbsp; At the moment, I hit a wall around 167.&amp;nbsp; I&amp;#39;ve got a few other bytes of info I store in NVS that are separate to this array - they take up about 15 bytes in total.&lt;/p&gt;
&lt;p&gt;This is how&amp;nbsp;the flash is allocated in my .dts file (this is the default for the nRF52-DK)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;flash0 {

	partitions {
		compatible = &amp;quot;fixed-partitions&amp;quot;;
		#address-cells = &amp;lt;1&amp;gt;;
		#size-cells = &amp;lt;1&amp;gt;;

		boot_partition: partition@0 {
			label = &amp;quot;mcuboot&amp;quot;;
			reg = &amp;lt;0x00000000 0xc000&amp;gt;;
		};
		slot0_partition: partition@c000 {
			label = &amp;quot;image-0&amp;quot;;
			reg = &amp;lt;0x0000C000 0x32000&amp;gt;;
		};
		slot1_partition: partition@3e000 {
			label = &amp;quot;image-1&amp;quot;;
			reg = &amp;lt;0x0003E000 0x32000&amp;gt;;
		};
		scratch_partition: partition@70000 {
			label = &amp;quot;image-scratch&amp;quot;;
			reg = &amp;lt;0x00070000 0xa000&amp;gt;;
		};
		storage_partition: partition@7a000 {
			label = &amp;quot;storage&amp;quot;;
			reg = &amp;lt;0x0007a000 0x00006000&amp;gt;;
		};
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And this is how I have my flash device set up in my code (based on the example code)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int16_t flash_initialise(void)
{
    int16_t rc;

	flash_dev = FLASH_AREA_DEVICE(STORAGE_NODE_LABEL);
	if (!device_is_ready(flash_dev)) {
		#ifdef DEBUG_NVS
			printk(&amp;quot;Flash device %s is not ready\n&amp;quot;, flash_dev-&amp;gt;name);
		#endif
		return -EINVAL;
	}
	printk(&amp;quot;Flash device %s is ready\n&amp;quot;,flash_dev-&amp;gt;name);

	fs.offset = FLASH_AREA_OFFSET(storage);
	rc = flash_get_page_info_by_offs(flash_dev, fs.offset, &amp;amp;info);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS		
			printk(&amp;quot;Unable to get page info\n&amp;quot;);
		#endif
		return rc;
	}
	#ifdef DEBUG_NVS
		printk(&amp;quot;Page info OK\n&amp;quot;);
	#endif
	fs.sector_size = info.size;
	fs.sector_count = 2U;

	rc = nvs_init(&amp;amp;fs, flash_dev-&amp;gt;name);
	if (rc !=0) 
	{
		#ifdef DEBUG_NVS
			printk(&amp;quot;Flash Init failed\n&amp;quot;);
		#endif
		return rc;
	}
	#ifdef DEBUG_NVS
		printk(&amp;quot;Flash initialised OK\n&amp;quot;);
	#endif

	// Check if data is stored in flash
	rc = check_for_nvs_key();
	return rc;
	
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As I understand it, the available flash storage size is 0x6000, which is about 24kB.&amp;nbsp; And I have allocated two sectors, each of 4096 bytes.&lt;/p&gt;
&lt;p&gt;So, I&amp;#39;m not sure why I&amp;#39;m running into storage problems.&lt;/p&gt;
&lt;p&gt;Sorry if this sounds like a pretty basic question, but I can&amp;#39;t seem to find any info that would help me understand why I&amp;#39;m running out of storage space and how to increase it&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/374206?ContentTypeID=1</link><pubDate>Fri, 24 Jun 2022 16:36:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96f5672b-0e09-4b2d-a907-232e2c4a3639</guid><dc:creator>Simon</dc:creator><description>[quote user="Mike Austin (LPI)"]I’ll update this thread in a week or so when I’ve had a chance to do some more testing[/quote]
&lt;p&gt;Sounds good&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f44d.svg" title="Thumbsup"&gt;&amp;#x1f44d;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/374028?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 19:30:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:602d74cd-c5aa-4a62-847a-625fb946cf65</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m just about to get back into this part of it after struggling with issues around GPIO/System OFF/MCUBoot for nearly a month.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll update this thread in a week or so when I&amp;rsquo;ve had a chance to do some more testing&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/373991?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 14:34:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:132dca95-bc5e-4fb3-a14c-e0be90f96e18</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hello Mike,&lt;/p&gt;
&lt;p&gt;What is the current state on this issue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/364043?ContentTypeID=1</link><pubDate>Wed, 20 Apr 2022 22:48:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3759ca1a-6ab0-4fba-abf5-887a27fa5d74</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Thanks Haakonsh.&lt;/p&gt;
&lt;p&gt;If I simplify what I&amp;#39;m trying to write to NVS, it seems to work OK.&amp;nbsp; I changed my data structure to just a simple array:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint16_t lsr_strike_log[9];&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And if I write/read this to NVS, I can see that the data is being stored.&amp;nbsp; I&amp;#39;m still getting weird values for the return value from nvs_write() and nvs_read() though.&lt;/p&gt;
&lt;p&gt;This is the log info I see when writing the simple array:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1650494870009v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;If I try and write my struct to NVS in the form I ultimately want to, I crash my DK and it keeps rebooting.&lt;/p&gt;
&lt;p&gt;In my code I initialse NVS before I initialise anything to do with BLE, so not sure if the BLE initialisation then changes what I&amp;#39;ve done when setting up NVS?&lt;/p&gt;
&lt;p&gt;Thanks and regards,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems writing/reading struct to NVS</title><link>https://devzone.nordicsemi.com/thread/363989?ContentTypeID=1</link><pubDate>Wed, 20 Apr 2022 14:20:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e7c45ec-9155-4b83-adbf-01e9467d415a</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I think NVS might already be initialized by the bluetooth stack, it uses it to store certain settings. I&amp;#39;ll do some digging and see what I can find.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>