<?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 data in flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75060/writing-data-in-flash</link><description>Hello, 
 I am working in NCS and I am trying to save some data in flash before the SoC turns off. 
 I am starting by using the code below. 
 
 If I use this code in the main() I can see the data written in flash. Instead, if I write the same code either</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 May 2021 13:20:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75060/writing-data-in-flash" /><item><title>RE: Writing data in flash</title><link>https://devzone.nordicsemi.com/thread/310771?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 13:20:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ea94f4d-d619-4a13-a0e9-14c5a9193625</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;A customer faced a similar issue recently:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/support-private/support/269399#permalink=659970"&gt;https://devzone.nordicsemi.com/support-private/support/269399#permalink=659970&lt;/a&gt;&amp;nbsp;Could you test the solution proposed there?&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: Writing data in flash</title><link>https://devzone.nordicsemi.com/thread/310645?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 09:01:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ebb18f4-cd98-4987-94a4-86c19b8d37df</guid><dc:creator>Crescenzo Dassi</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Your code works. However it starts breaking if you add some Bluetooth features.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For instance, if in your project, in prj.conf you add the following configurations to enable the bonding&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Enable bonding
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and in the main you add:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        bt_enable(NULL);

     
	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The SoC goes in hard fault when attempts to write the flash in the thread.&lt;/p&gt;
&lt;p&gt;I noticed that everything works fine if you remove&amp;nbsp;CONFIG_NVS=y from prj.conf.&lt;/p&gt;
&lt;p&gt;However, even without&amp;nbsp;&lt;span&gt;CONFIG_NVS,&lt;/span&gt; &amp;nbsp;if in the main you add a command to start the advertising, like below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
			     ARRAY_SIZE(sd));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The SoC goes in hard fault again when trying to write in flash...&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand the correlation between Bluetooth Stack and Memory Controller, but something happens when you try to handle both in the same code.&lt;/p&gt;
&lt;p&gt;I attach the prj.cnf file I am working with.&lt;/p&gt;
&lt;p&gt;.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/myprj.conf"&gt;devzone.nordicsemi.com/.../myprj.conf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Crescenzo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing data in flash</title><link>https://devzone.nordicsemi.com/thread/310225?ContentTypeID=1</link><pubDate>Tue, 18 May 2021 15:23:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01225635-14fc-4a69-85a8-3f85987f129e</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I was not able to reproduce the hard fault. I ran&amp;nbsp;your snippet from a thread and did not get any hard faults. I wrote&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;0x0000009AUL to address&amp;nbsp;&lt;/span&gt;&lt;/span&gt;0x0005A000 and confirmed that it was sucessfully exectuted:&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;C:\Users\Simon&amp;gt;nrfjprog --memrd 0x00059FF0 --n 0x30
0x00059FF0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
0x0005A000: 0000009A FFFFFFFF FFFFFFFF FFFFFFFF   |................|
0x0005A010: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Could you test the same code and see if you get it to work:&lt;/div&gt;
&lt;div&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/threads_5F00_raw_5F00_flash.7z"&gt;devzone.nordicsemi.com/.../threads_5F00_raw_5F00_flash.7z&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;Best regards,&lt;/div&gt;
&lt;div&gt;Simon&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>