<?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>Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340</link><description>Hello, 
 I am trying to use part of the code from this example https://github.com/zephyrproject-rtos/zephyr/blob/master/samples/subsys/nvs 
 to write to and read from flash on nRF5340 SoC. However, I am getting the following linking error when building</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Apr 2021 11:21:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340" /><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304488?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 11:21:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:076a995e-6395-4f61-871c-728c1e57f046</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;My pleasure! Glad I could help.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304483?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 11:00:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39374254-7a1b-4d39-a718-efd107e228a0</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Thank you Carl.&lt;/p&gt;
&lt;p&gt;It is all making sense now.&amp;nbsp;Thank you for your help.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304444?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 09:16:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dba1e531-fec1-4e5d-8659-2228c47ec5c0</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;/p&gt;
[quote user="Learner"]So, does this mean all 3 sectors were full? if this was the case then NVS should overwrite old information shouldn&amp;#39;t it?[/quote]
&lt;p&gt;So it seems. My understanding is that NVS won&amp;#39;t overwrite information that&amp;#39;s not a part of the NVS file system, thus avoiding disruption of any other potential flash operations. I suggest that you use the flash API to erase the affected memory if this situation occurs.&lt;br /&gt;&lt;br /&gt;The sample should be configured correctly, but as you are using a custom board there may be some additional modifications required. Could you try with your original application and overlay again to see if the messages are printed correctly there?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304432?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 08:27:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55e5f051-a282-4836-95f0-9e5e97fc1bf5</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Good morning Carl,&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/304413#304413"]If the board was used for something else earlier it&amp;#39;s likely that there were some information left in the flash.[/quote]
&lt;p&gt;So, does this mean all 3 sectors were full? if this was the case then NVS should overwrite old information shouldn&amp;#39;t it?&lt;/p&gt;
&lt;p&gt;Also, if this happens again, how can it be overcome from within the application?&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/304413#304413"]Is printk over serial enabled in the application?[/quote]
&lt;p&gt;I usually do this in an overlay file but&amp;nbsp;this sample project did not have one. I would have expected since the sample uses printk then the environment in the&amp;nbsp;sample project would have already been setup for it to work.&lt;/p&gt;
&lt;p&gt;How can I enable printk over serial in the application?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304413?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 06:51:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cfc645d-57b3-4a89-a6d6-3a5805398949</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&amp;nbsp;&lt;br /&gt;&lt;br /&gt;This means that the device weren&amp;#39;t properly erased before programming. I guess this is caused by how Segger Embedded Studio erases and flashes the device. If the board was used for something else earlier it&amp;#39;s likely that there were some information left in the flash.&lt;br /&gt;&lt;br /&gt;The output you are seeing are (correct) log messages from the NVS subsystem. Is printk over serial enabled in the application?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304345?ContentTypeID=1</link><pubDate>Mon, 12 Apr 2021 15:14:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b581a5c-f2a0-4301-9276-0902af4d5004</guid><dc:creator>Learner</dc:creator><description>[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/304322#304322"]nrfjprog --recover[/quote]
&lt;p&gt;With this command&amp;nbsp;nvs_startup() is not returning an error and neither is nvs_init().&lt;/p&gt;
&lt;p&gt;Why is this?&lt;/p&gt;
&lt;p&gt;However, I am not seeing the output I expected to see. This is what I am seeing in the Debug Terminal.&lt;/p&gt;
&lt;p&gt;Note, I have reduced the number of reboots to only 3.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;[00:00:15.247,161] inf&amp;gt; fs_nvs: 3 Sectors of 4096 bytes&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;[00:00:15.247,161] inf&amp;gt; fs_nvs: alloc wra: 0, d08&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;[00:00:15.247,161] inf&amp;gt; fs_nvs: data wra: 0, 1fc&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Any reason why I am not seeing the other print messages?&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304322?ContentTypeID=1</link><pubDate>Mon, 12 Apr 2021 14:14:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee759abd-5a5f-415d-a095-bc311d3bde4b</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Thanks. Have you tried to run &amp;quot;nrfjprog --recover&amp;quot; on the custom board before flashing the application to ensure that the flash is properly erased?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304315?ContentTypeID=1</link><pubDate>Mon, 12 Apr 2021 13:54:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3e0ef60-b8b2-4134-a589-608d5d5c51a5</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;I am programming all boards the same way namely, using Segger Embedded Studio and the nRF52833DK (or nRF5340PDK in case of nRF5340) connected to a USB port.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304267?ContentTypeID=1</link><pubDate>Mon, 12 Apr 2021 12:15:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11f8c36d-f77b-428e-b828-5ae0f0bb76ba</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;How are you programming the custom board, versus the DK and the nRF5340 proprietary board? What interface, and what program are you using?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304262?ContentTypeID=1</link><pubDate>Mon, 12 Apr 2021 12:08:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd94f430-b97c-4a3a-8f42-e4d9124f6f3f</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/304218#304218"]What were your results from testing with the&amp;nbsp;&lt;strong&gt;zephyr/samples/subsys/nvs&amp;nbsp;&lt;/strong&gt;sample?[/quote]
&lt;p&gt;Similar results.&lt;/p&gt;
&lt;p&gt;nvs_init() calls nvs_startup() and the error&lt;strong&gt; -EDEADLK&lt;/strong&gt; occurs in nvs_startup(). Subsequent calls to nvs_read() all return error -13. Finally, I see the following error messages on the Debug Terminal.&lt;/p&gt;
&lt;p&gt;[00:03:13.789,031] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:05:15.822,875] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:05:17.330,871] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:05:40.749,084] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:05:45.632,781] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:05:53.766,357] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:05:55.903,686] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:06:07.351,074] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:06:11.763,427] err&amp;gt; fs_nvs: NVS not initialized&lt;br /&gt;[00:06:32.238,983] err&amp;gt; fs_nvs: NVS not initialized&lt;/p&gt;
&lt;p&gt;I have not tried the sample with the nRF52833DK but I am pretty sure it will work.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304218?ContentTypeID=1</link><pubDate>Mon, 12 Apr 2021 09:44:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ac3b49e-7bad-4de1-b745-69bdfd4a48e3</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Thank you for the information. I&amp;#39;m asking the developers to see if they have any input. What were your results from testing with the&amp;nbsp;&lt;strong&gt;zephyr/samples/subsys/nvs&amp;nbsp;&lt;/strong&gt;sample?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304074?ContentTypeID=1</link><pubDate>Fri, 09 Apr 2021 15:30:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8972a1da-c051-4f12-8ad8-3d85b43e016d</guid><dc:creator>Learner</dc:creator><description>[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/304072#304072"]Can you confirm that the exact same code (except for the overlay) works with the nRF52833DK and the custom nRF5340 board?[/quote]
&lt;p&gt;The exact same code including the same overlay works fine on the nRF52833DK.&lt;/p&gt;
&lt;p&gt;Also the same code but with a different overlay file works fine on the nRF5340PDK and nRF5340 proprietary board.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304072?ContentTypeID=1</link><pubDate>Fri, 09 Apr 2021 15:22:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3b5f6a4-41f8-43de-8628-5c93800c31f2</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;I agree that nothing in the overlay file should affect the flash, so that&amp;#39;s probably not the culprit. Just wanted to make sure, but if it&amp;#39;s not possible that&amp;#39;s okay!&lt;br /&gt;&lt;br /&gt;Can you confirm that the exact same code (except for the overlay) works with the nRF52833DK and the custom nRF5340 board? Could you test the standard &lt;strong&gt;zephyr/samples/subsys/nvs&lt;/strong&gt; sample on the board and see if the behavior is similar?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304046?ContentTypeID=1</link><pubDate>Fri, 09 Apr 2021 13:52:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6b8b428-07ad-491f-a6e7-afed0324e9f7</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;I cannot build without the overlay file. I don&amp;#39;t think it has anything to do with&amp;nbsp;it. I am attaching the overlay file just in case you may spot something.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/nrf52833dk_5F00_nrf52833.overlay"&gt;devzone.nordicsemi.com/.../nrf52833dk_5F00_nrf52833.overlay&lt;/a&gt;&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/304019#304019"]What happens before you call flash_init?[/quote]
&lt;p&gt;I call nvs_init() from within my function flash_init() that gets called from the main() function. Note, the failure occurs in nvs_startup() which is called from nvs_init().&lt;/p&gt;
&lt;p&gt;static struct nvs_fs fs;&lt;/p&gt;
&lt;p&gt;void main( void )&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;initialise();&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void initialise( void )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;// Setup a2d channels&lt;br /&gt;&amp;nbsp; &amp;nbsp;adc_device_setup();&lt;br /&gt;&amp;nbsp; &amp;nbsp;k_sleep( K_MSEC(1000) );&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;// Setup SPI devices&lt;br /&gt;&amp;nbsp; &amp;nbsp;radio_spi_setup();&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;//spi_init();&lt;br /&gt;&amp;nbsp; &amp;nbsp;k_sleep( K_MSEC(1000) );&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;// Configure LR1110&lt;br /&gt;&amp;nbsp; &amp;nbsp;radio_gfsk_modem_config();&lt;br /&gt;&amp;nbsp; &amp;nbsp;k_sleep( K_MSEC(1000) );&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;// Setup and Initialise timers&lt;br /&gt;&amp;nbsp; &amp;nbsp;timer_init();&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;// Start timers&lt;br /&gt;&amp;nbsp; &amp;nbsp;timer_start();&lt;/p&gt;
&lt;p&gt;&amp;nbsp; // Initialise Flash&lt;br /&gt;&amp;nbsp; &amp;nbsp;flash_init();&amp;nbsp;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void flash_init( void )&lt;br /&gt;{&lt;br /&gt; int32_t rc = 0;&lt;br /&gt; struct flash_pages_info info;&lt;/p&gt;
&lt;p&gt;/* define the nvs file system by settings with:&lt;br /&gt; * sector_size equal to the pagesize,&lt;br /&gt; * 3 sectors&lt;br /&gt; * starting at FLASH_AREA_OFFSET(storage)&lt;br /&gt; */&lt;br /&gt; fs.offset = &lt;strong&gt;FLASH_AREA_OFFSET&lt;/strong&gt;( storage );&lt;br /&gt;&lt;br /&gt;rc = &lt;strong&gt;flash_get_page_info_by_offs&lt;/strong&gt;( &lt;strong&gt;device_get_binding&lt;/strong&gt;( DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL ),&lt;br /&gt; fs.offset, &amp;amp;info );&lt;br /&gt; if ( rc )&lt;br /&gt; {&lt;br /&gt; printk( &amp;quot;Unable to get page info&amp;quot; );&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;fs.sector_size = info.size;&lt;br /&gt; fs.sector_count = 3U;&lt;/p&gt;
&lt;p&gt;rc = &lt;span style="color:#ff0000;"&gt;&lt;strong&gt;nvs_init&lt;/strong&gt;&lt;/span&gt;( &amp;amp;fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL );&lt;br /&gt; if ( &lt;span style="color:#ff0000;"&gt;&lt;strong&gt;rc&lt;/strong&gt;&lt;/span&gt; )&lt;br /&gt; {&lt;br /&gt; &lt;span style="color:#ff0000;"&gt;&lt;strong&gt;printk( &amp;quot;Flash Init failed\n&amp;quot; );&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;// Initialise static data flash area&lt;br /&gt; flash_init_static();&lt;/p&gt;
&lt;p&gt;// Initialise dynamic data flash area&lt;br /&gt; flash_init_dynamic();&lt;/p&gt;
&lt;p&gt;#if NDEBUG&lt;br /&gt; /* Finally, lock the flash */&lt;br /&gt;//TBD!!! flash_SetLockByte(0x80U);&lt;br /&gt;#endif&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;}//flash_init()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/304019?ContentTypeID=1</link><pubDate>Fri, 09 Apr 2021 12:52:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c651091-db20-4996-a33e-d7c8250663a4</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;What happens before you call flash_init? If possible, please share your main function or main.c.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;In addition, could you try to build without the overlay, so that we can rule out any potential issues there?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303670?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 08:25:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f73c8898-d3c3-4e03-ae22-cf2c4d334cbe</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/303648#303648"]Are you using a custom board definition for the proprietary&amp;nbsp;nRF52833 board?[/quote]
&lt;p&gt;As far as I can tell I am not, I am using the generic nRF52833DK board definition.&lt;/p&gt;
&lt;p&gt;This is an extract of&amp;nbsp;&lt;strong&gt;...\build_nrf52833dk_nrf52833\zephyr\zephyr.dts&lt;/strong&gt;,&lt;/p&gt;
&lt;p&gt;/dts-v1/;&lt;/p&gt;
&lt;p&gt;/ {&lt;br /&gt; #address-cells = &amp;lt; 0x1 &amp;gt;;&lt;br /&gt; #size-cells = &amp;lt; 0x1 &amp;gt;;&lt;br /&gt; model = &amp;quot;Nordic nRF52833 DK NRF52833&amp;quot;;&lt;br /&gt; compatible = &amp;quot;nordic,nrf52833-dk-nrf52833&amp;quot;;&lt;br /&gt; chosen {&lt;br /&gt; zephyr,entropy = &amp;amp;rng;&lt;br /&gt; zephyr,flash-controller = &amp;amp;flash_controller;&lt;br /&gt; zephyr,console = &amp;amp;uart0;&lt;br /&gt; zephyr,shell-uart = &amp;amp;uart0;&lt;br /&gt; zephyr,uart-mcumgr = &amp;amp;uart0;&lt;br /&gt; zephyr,bt-mon-uart = &amp;amp;uart0;&lt;br /&gt; zephyr,bt-c2h-uart = &amp;amp;uart0;&lt;br /&gt; zephyr,sram = &amp;amp;sram0;&lt;br /&gt; zephyr,flash = &amp;amp;flash0;&lt;br /&gt; zephyr,code-partition = &amp;amp;slot0_partition;&lt;br /&gt; };&lt;br /&gt; aliases {&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;....&lt;/p&gt;
&lt;p&gt;My overlay file is called &lt;strong&gt;nrf52833dk_nrf52833.overlay&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I am attaching the device tree file zephyr.dts and yaml file sample.yaml.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note, This project was started by a colleague and I am adding the NVS flash functionality to it.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5684.zephyr.dts"&gt;devzone.nordicsemi.com/.../5684.zephyr.dts&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/sample.yaml"&gt;devzone.nordicsemi.com/.../sample.yaml&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303648?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 07:24:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79c3e5cf-1a88-494a-8944-a85002e9f343</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;You&amp;#39;re getting the&amp;nbsp;&lt;span&gt;EDEADLK error,&amp;nbsp;caused by&amp;nbsp;all sectors&amp;nbsp;being&amp;nbsp;closed and unavailable to NVS. Are you using a custom board definition for the proprietary&amp;nbsp;nRF52833 board?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303568?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 14:59:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26b1f503-99c1-486f-abc8-8913de3426ef</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Thank you Carl.&lt;/p&gt;
&lt;p&gt;I tried your suggestion but the problem is still there.&lt;/p&gt;
&lt;p&gt;I tracked it down in the debugger and it seems the problem is occurring when nvs_startup() is called from nvs_init() it returns rc = -45 (0xffffffd3).&lt;/p&gt;
&lt;p&gt;rc = &lt;strong&gt;nvs_startup&lt;/strong&gt;(fs);&lt;br /&gt; if (rc) {&lt;br /&gt; return rc;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;Digging even deeper in the API call tree, in &lt;strong&gt;nvs_startup&lt;/strong&gt;(), I could see that the line of code&amp;nbsp; &lt;span style="color:#0000ff;"&gt;&lt;strong&gt;&lt;span style="background-color:#99cc00;"&gt;closed_sectors++&lt;/span&gt;&amp;nbsp; &lt;/strong&gt;&lt;span style="color:#000000;"&gt;gets executed three times&amp;nbsp;so, closed_sectors = 3 although the SES debugger did not allow me to set a watch on this variable. I also set two breakpoints at the two lines highlighted in yellow. The first breakpoint was reached but not the second one. This confirms that&amp;nbsp;&lt;span&gt;closed_sectors == fs-&amp;gt;sector_count hence the jump to &lt;strong&gt;end:&lt;/strong&gt;. So, it looks like all 3 sectors are closed and therefore there is no sector available NVS can write to. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="color:#000000;"&gt;&lt;span&gt;Why is this problem seen with nRF52833 (proprietary board) but not&amp;nbsp;on nRF2833DK or on nRF5340 (another proprietary board)?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;static int &lt;strong&gt;nvs_startup(&lt;/strong&gt;struct nvs_fs *fs)&lt;br /&gt;{&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;/* step through the sectors to find a open sector following&lt;br /&gt; * a closed sector, this is where NVS can to write.&lt;br /&gt; */&lt;br /&gt; for (i = 0; i &amp;lt; fs-&amp;gt;sector_count; i++) {&lt;br /&gt; addr = (i &amp;lt;&amp;lt; ADDR_SECT_SHIFT) +&lt;br /&gt; (uint16_t)(fs-&amp;gt;sector_size - ate_size);&lt;br /&gt; rc = nvs_flash_cmp_const(fs, addr, erase_value,&lt;br /&gt; sizeof(struct nvs_ate));&lt;br /&gt; if (rc) {&lt;br /&gt; /* closed sector */&lt;br /&gt; &lt;span style="background-color:#99cc00;color:#0000ff;"&gt;&lt;strong&gt;closed_sectors++;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt; nvs_sector_advance(fs, &amp;amp;addr);&lt;br /&gt; rc = nvs_flash_cmp_const(fs, addr, erase_value,&lt;br /&gt; sizeof(struct nvs_ate));&lt;br /&gt; if (!rc) {&lt;br /&gt; /* open sector */&lt;br /&gt; break;&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; /* all sectors are closed, this is not a nvs fs */&lt;br /&gt;&lt;span style="background-color:#ffff00;"&gt;if (closed_sectors == fs-&amp;gt;sector_count) {&amp;nbsp; &amp;nbsp; &amp;nbsp; // This breakpoint is reached&lt;/span&gt;&lt;br /&gt; rc = -EDEADLK;&lt;br /&gt; goto end;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffff00;"&gt; if (i == fs-&amp;gt;sector_count) {&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;// &lt;span style="color:#ff0000;"&gt;&lt;strong&gt;This breakpoint is NOT reached&lt;/strong&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; /* none of the sectors where closed, in most cases we can set&lt;br /&gt; * the address to the first sector, except when there are only&lt;br /&gt; * two sectors. Then we can only set it to the first sector if&lt;br /&gt; * the last sector contains no ate&amp;#39;s. So we check this first&lt;br /&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;end:&lt;br /&gt; k_mutex_unlock(&amp;amp;fs-&amp;gt;nvs_lock);&lt;br /&gt; &lt;span style="background-color:#ffff00;"&gt;return rc;&amp;nbsp; &amp;nbsp;// rc = -45&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;}//end of &lt;strong&gt;nvs_startup&lt;/strong&gt;()&lt;/p&gt;
&lt;p&gt;Also, in&amp;nbsp;&lt;strong&gt;C:\Zypher\v1.5.0-rc1\zephyr\include\devicetree\zephyr.h&lt;/strong&gt; I see where the macro &lt;span&gt;DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL is defined &lt;/span&gt;but it is greyed out meaning it is disabled.&lt;/p&gt;
&lt;p&gt;#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_flash_controller), label)&lt;br /&gt;#define DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL \&lt;br /&gt; DT_LABEL(DT_CHOSEN(zephyr_flash_controller))&lt;br /&gt;#endif&lt;/p&gt;
&lt;p&gt;Thank you for your help.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303492?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 12:21:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf82d6e6-252b-4ee0-964f-f23f8c15c452</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;I think this might be caused by the flash controller already being bound to &amp;quot;flash_dev&amp;quot;. NVS binds the flash controller as well and will likely fail if the device is already bound. Could you try to do as in the NVS sample, where they get the page info by referencing&amp;nbsp;&lt;span&gt;DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL&amp;nbsp;directly? This ensures that it&amp;#39;s released before nvs_init is called. See the code below.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int rc = 0,
struct flash_pages_info info;

/* define the nvs file system by settings with:
 *	sector_size equal to the pagesize,
 *	3 sectors
 *	starting at FLASH_AREA_OFFSET(storage)
 */
fs.offset = FLASH_AREA_OFFSET(storage);
rc = flash_get_page_info_by_offs(
	device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL),
	fs.offset, &amp;amp;info);
if (rc) {
	printk(&amp;quot;Unable to get page info&amp;quot;);
}
fs.sector_size = info.size;
fs.sector_count = 3U;

rc = nvs_init(&amp;amp;fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
if (rc) {
	printk(&amp;quot;Flash Init failed\n&amp;quot;);
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303437?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 10:31:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7a3dbd0-a41c-4a10-a2eb-3fc7bcac19a2</guid><dc:creator>Learner</dc:creator><description>[quote userid="92434" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/303415#303415"]&amp;lt;error&amp;gt; fs_nvs: NVS not initialized[/quote]
&lt;p&gt;This message is probably returned in response to subsequent NVS function calls. Although I am calling the function &lt;span&gt;flash_get_page_count&lt;/span&gt;&lt;span&gt;() after nvs_init() and it is returning page_count = 128 which looks like a valid value.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303434?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 10:23:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:322bc428-bfa5-4b28-aeff-daac49283ec4</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;My NVS initialisation code looks like this and I am seeing the message in red below &amp;quot;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Flash Init failed&lt;/span&gt;&amp;quot;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I think the returned value &lt;strong&gt;rc = 0xffffffd3&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;void flash_init( void )&lt;br /&gt;{&lt;br /&gt; uint32_t rc = 0;&lt;br /&gt; struct flash_pages_info info;&lt;/p&gt;
&lt;p&gt;/* define the nvs file system by settings with:&lt;br /&gt; * sector_size equal to the pagesize,&lt;br /&gt; * 3 sectors&lt;br /&gt; * starting at FLASH_AREA_OFFSET(storage)&lt;br /&gt; */&lt;br /&gt; fs.offset = FLASH_AREA_OFFSET( storage );&lt;br /&gt; flash_dev = device_get_binding( DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL );&lt;br /&gt; if ( flash_dev == NULL )&lt;br /&gt; {&lt;br /&gt; printk( &amp;quot;Flash device not bound!\n&amp;quot; );&lt;br /&gt; return;&lt;br /&gt; }&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt; rc = flash_get_page_info_by_offs( flash_dev, fs.offset, &amp;amp;info );&lt;br /&gt;if ( rc )&lt;br /&gt; {&lt;br /&gt; printk( &amp;quot;Unable to get page info&amp;quot; );&lt;br /&gt; }&lt;br /&gt; fs.sector_size = info.size;&lt;br /&gt; fs.sector_count = 3U;&lt;/p&gt;
&lt;p&gt;rc = nvs_init( &amp;amp;fs, DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL );&lt;br /&gt; if ( rc )&lt;br /&gt; {&lt;br /&gt; &lt;span style="color:#ff0000;"&gt;&lt;strong&gt;printk( &amp;quot;Flash Init failed\n&amp;quot; );&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;size_t page_count = flash_get_page_count(flash_dev);&lt;br /&gt; printk( &amp;quot;Flash contains %d pages of 4kB each\n&amp;quot;, page_count );&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303429?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 10:03:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa4d64cd-bdd0-4bb9-ac70-d65311292e08</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi!&lt;br /&gt;&lt;br /&gt;That error should not be possible to get from nvs_init(...). Have you made sure that nvs_init is called before any other NVS functions? A complete log might help me identify the issue. I also suggest debugging the code to see where it fails.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303415?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 09:26:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15984237-cc85-437c-ab4a-9e4c9414ce84</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve recently ported the code developed for the nRF5340 to the nRF52833 SoC and I am seeing this error when I call nvs_init(),&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;&amp;lt;error&amp;gt; fs_nvs: NVS not initialized&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;Any idea what could be causing this?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;Kind regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;Mohamed&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/303408?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 09:09:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9168f543-0878-4242-a26e-a53e2ea83932</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again, Mohamed!&lt;br /&gt;&lt;br /&gt;Thank you for your patience and good to hear that NVS is more understandable now. I&amp;#39;m glad I could help! This is a part of the Zephyr RTOS so I think it&amp;#39;s better if you open an issue for your suggestions in their &lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues"&gt;GitHub issue tracker&lt;/a&gt;, as they likely can provide better help than me on the specifics of the NVS API.&lt;br /&gt;&lt;br /&gt;Good luck on your project!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to and reading from flash on nRF5340</title><link>https://devzone.nordicsemi.com/thread/300993?ContentTypeID=1</link><pubDate>Fri, 19 Mar 2021 15:24:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13e46cda-0a1c-43a2-a0c5-edf0fbbbd407</guid><dc:creator>Learner</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/72772/writing-to-and-reading-from-flash-on-nrf5340/300919#300919"]&lt;blockquote&gt;&lt;p&gt;&lt;span&gt;Elements are appended to a sector until storage space in the sector is exhausted. Then a new sector in the flash area is prepared for use (erased). Before erasing the sector it is checked that identifier - data pairs exist in the sectors in use, if not the id-data pair is copied.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;From this it&amp;#39;s clear that NVS is not wasteful when it comes to using flash, rather the other way around. The historical data will be overwritten over time, and the NVS subsystem will always ensure that the newest version id-data pair is kept.&amp;nbsp;&lt;/p&gt;[/quote]
&lt;p&gt;I have read the documentation again and even after reading it many times I am just about beginning to understand better how NVS works. It is not very easy to read and digest how it all works for someone new to NVS. It would have been much better to complement the worded description with an illustrated example showing for example what happens when the current sector is full and writing to a new sector starts. Also, what happens when all sectors allocated are full.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I would appreciate a great deal if you could do that for me.&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f91d.svg" title="Handshake"&gt;&amp;#x1f91d;&lt;/span&gt;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f637.svg" title="Mask"&gt;&amp;#x1f637;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I am beginning to warm up to NVS much more than I did a day ago thanks to your explanation. I think I am going to stick with NVS and delay my move to flash API.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Mohamed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>