<?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>Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74789/hard-fault-when-using-nvs-with-zephyr-on-nrf52</link><description>I&amp;#39;m attempting to write to flash memory on our custom board using the nRF52840 using the NVS library in Zephyr 1.5.0. I&amp;#39;ve ported over the example code from samples/subsys/nvs and nvs successfully initializes: 
 
 The storage file system structure is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 07 Jan 2022 07:43:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74789/hard-fault-when-using-nvs-with-zephyr-on-nrf52" /><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/346601?ContentTypeID=1</link><pubDate>Fri, 07 Jan 2022 07:43:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:579ae320-7432-4e90-a6db-4365389876fd</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Could you open a new case and explain your problem there? Then it will get a assigned to an engineer that will take care of it&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: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/346549?ContentTypeID=1</link><pubDate>Thu, 06 Jan 2022 16:45:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89430e4e-38d1-4886-91a3-cf53b774d600</guid><dc:creator>DaWaN</dc:creator><description>&lt;p&gt;I further checked my MPU fault and the MMFAR address was pointing at the stack and remarkable close to the edge of it.&lt;br /&gt;Changed my main stack size to 2048 (CONFIG_MAIN_STACK_SIZE=2048) and this fixed the issue for my board config.&lt;br /&gt;Not sure what inside my board config lead to the higher stack usage, but this solved my problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/346307?ContentTypeID=1</link><pubDate>Wed, 05 Jan 2022 20:38:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ee6d750-ac3c-4031-8398-43b02a7675ee</guid><dc:creator>DaWaN</dc:creator><description>&lt;p&gt;I am suffering from the same issue, getting Hard Faults on the MPU when using NVS.&lt;br /&gt;I am using an NRF52DK board with nRF52832. I am using the nRF Connect SDK V1.8.0&lt;br /&gt;When I build the NVS samples they work when using the nRF52DK board config, but they do not work with my own board config.&lt;br /&gt;The issue occurs within the function nvs_write when it starts requesting the MPSL timeslot. The program counter also matches the MPSL library when checking the map file. So the issue seems MPSL related.&lt;br /&gt;I have been digging through the config files, comparing the different board configs and almost everything seems identical. I noticed only one warning and I think it is related to the issue. The warning I am seeing is this:&amp;nbsp;# CONFIG_TEMP_NRF5_MPSL is not set&lt;br /&gt;&lt;br /&gt;This is the logging I get when the issue gets triggered:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;err&amp;gt; os: ***** HARD FAULT *****
[00:00:01.050,384] &amp;lt;err&amp;gt; os:   Fault escalation (see below)
[00:00:01.050,415] &amp;lt;err&amp;gt; os: ***** MPU FAULT *****
[00:00:01.050,415] &amp;lt;err&amp;gt; os:   Data Access Violation
[00:00:01.050,415] &amp;lt;err&amp;gt; os:   MMFAR Address: 0x20005bd4
[00:00:01.050,415] &amp;lt;err&amp;gt; os: r0/a1:  0x00008672  r1/a2:  0x0000003b  r2/a3:  0x00000000
[00:00:01.050,415] &amp;lt;err&amp;gt; os: r3/a4:  0x00000036 r12/ip:  0x000086ad r14/lr:  0x00000000
[00:00:01.050,445] &amp;lt;err&amp;gt; os:  xpsr:  0x61000000
[00:00:01.050,445] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00000b6a
[00:00:01.050,445] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 0: CPU exception on CPU 0&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Would be nice if someone with more knowledge about the MPSL library can shed some light on this,&amp;nbsp;as I would like to have this problem solved.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/309339?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 22:09:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b0090f6-f4a4-4a5a-acd9-c6aa38968cd0</guid><dc:creator>NathanML</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;That&amp;#39;s good to know, thanks!&lt;/p&gt;
&lt;p&gt;What is the purpose of setting&amp;nbsp;&lt;span&gt;CONFIG_MPU_ALLOW_FLASH_WRITE to n instead of y?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/309193?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 10:58:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6adb4f3-ae80-483b-ac00-ba02a804715d</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Regarding &amp;quot;&lt;span&gt;error: &lt;/span&gt;&lt;span&gt;&lt;em&gt;&amp;lt;err&amp;gt; flash_nrf: not word-aligned&lt;/em&gt;&lt;/span&gt;&amp;quot;, check out this PR:&amp;nbsp;&lt;a title="https://github.com/zephyrproject-rtos/zephyr/pull/34592" href="https://github.com/zephyrproject-rtos/zephyr/pull/34592" rel="noopener noreferrer" target="_blank"&gt;https://github.com/zephyrproject-rtos/zephyr/pull/34592&lt;/a&gt;. You should also set&amp;nbsp;&lt;code&gt;CONFIG_MPU_ALLOW_FLASH_WRITE=n.&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
[quote userid="101674" url="~/f/nordic-q-a/74789/hard-fault-when-using-nvs-with-zephyr-on-nrf52/308815#308815"]. I&amp;#39;m guessing that I didn&amp;#39;t erase the flash prior to migrating from my previous FDS[/quote]
&lt;p&gt;FDS and NVS ar completely different, so there won&amp;#39;t be any compatibility between these.&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: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/309176?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 10:00:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76c9fe29-3e93-427c-a267-741db0a8ef10</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hi Nathan,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m happy you were able to resolve the issue, and thanks for sharing the solution, wich may benefit other people in the future. I will share your feedback with some developers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/308815?ContentTypeID=1</link><pubDate>Fri, 07 May 2021 22:27:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8151e756-ce94-4a7c-940b-9c713543d205</guid><dc:creator>NathanML</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Thanks again for the response. I was able to solve the word alignment issue in the example code by running nvs_clear. I&amp;#39;m guessing that I didn&amp;#39;t erase the flash prior to migrating from my previous FDS usage with the old sdk and for some reason it was trying to initialize writes at an unaligned address.&lt;/p&gt;
&lt;p&gt;I fixed my issue regarding the hard fault with nvs on our custom board with our&amp;nbsp;custom application. When I disabled BT (commented out CONFIG_BT=y) nvs worked. I did some digging and saw that enabling BT changes some flash configuration options. I worked under the assumption that BT was probably using enough flash space to cause issues with the 3 pages I was trying to initialize for NVS.&lt;/p&gt;
&lt;p&gt;I fixed the issue by increasing the amount of space for the storage partition; I added the following line to my prj.conf: CONFIG_PM_PARTITION_SIZE_NVS_STORAGE=0x8000 (the default is 0x6000).&lt;/p&gt;
&lt;p&gt;So, for anyone stumbling across this thread: if you get a word alignment issue, make sure your flash is erased first, or run nvs_clear. If you are experiencing a hard fault/MPU fault and are using the BT module along with NVS, set the config for nvs storage to a larger value (as shown above).&lt;/p&gt;
&lt;p&gt;Something that I think could be helpful for this sort of scenario is documentation outlining dependencies/interferences between modules. I had to do a lot of KConfig digging as well as a diff between my autogenerated configs.c files between our custom application and the sample nvs application to get an idea of what could be going wrong. It&amp;#39;s also possible this sort of issue is documented somewhere and I just couldn&amp;#39;t find out where. Just my two cents. Anyways,&amp;nbsp;I appreciate your help, Simon!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/308696?ContentTypeID=1</link><pubDate>Fri, 07 May 2021 10:09:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3c1e915-9e2c-4aa3-b688-49ed7ad8ff3e</guid><dc:creator>Simon</dc:creator><description>[quote user=""]Also strange is that when running the default nvs code on the dev kit, I get this error:&amp;nbsp;&lt;em&gt;&amp;lt;err&amp;gt; flash_nrf: not word-aligned&lt;/em&gt;, followed by the memory address,&amp;nbsp;for every attempted write.&amp;nbsp;[/quote]
&lt;p&gt;I tested the NVS example (NCS v1.5.1) on an nRF52840 DK and was not able to reproduce this. Could you follow the exact same steps as me and see if it still happens:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Install NCS v1.5.1 through the Toolchain Manager
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#installing-the-toolchain-manager"&gt;Installing the Toolchain manager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#installing-the-ncs"&gt;Installing the nRF Connect SDK&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Open bash as expained in &lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-1-ncs-v1-4-0#h10skagp8wj210662x01aeknqi116jxom"&gt;1.3.2 Build and flash&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Redirect to&amp;nbsp;ncs/v1.5.1/zephyr/samples/subsys/nvs&lt;/li&gt;
&lt;li&gt;Connect the nRF52840 DK to the PC and open Termite&lt;/li&gt;
&lt;li&gt;Run these commands
&lt;ul&gt;
&lt;li&gt;nrfjprog --eraseall&lt;/li&gt;
&lt;li&gt;west build -b nrf52840dk_nrf52840 -d build_52840&lt;/li&gt;
&lt;li&gt;west flash -d build_52840&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then you should see the follwoing output:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.4.99-ncs2  ***
Id: 1, Address: 192.168.1.1
Id: 2, Key: ff fe fd fc fb fa f9 f8 
Id: 3, Reboot_counter: 98
Id: 5, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 
[00:00:00.258,239] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: 3 Sectors of 4096 bytes[1B][0m
[00:00:00.258,270] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: alloc wra: 0, cb0[1B][0m
[00:00:00.258,270] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: data wra: 0, 228[1B][0m
Reboot counter history: ...98...97...96...95...94...93...92...91...90...89...88...87...86...85...84...83...82...81...80...79...78...77...76...75...74...73...72...71...70...69...68...67...66...65...64...63...62...61...60...59...58...57...56...55...54...53...52...51...50...49...48...47...46...45...44...43...42...41...40...39...38...37...36...35...34...33...32...31...30...29...28...27...26...25...24...23...22...21...20...19...18...17...16...15...14...13...12...11...10...9...8...7...6...5...4...3...2...1...0
Oldest reboot counter: 0
Rebooting in ...5...4...3...2...1
*** Booting Zephyr OS build v2.4.99-ncs2  ***
Id: 1, Address: 192.168.1.1
Id: 2, Key: ff fe fd fc fb fa f9 f8 
Id: 3, Reboot_counter: 99
Id: 5, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 
[00:00:00.258,270] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: 3 Sectors of 4096 bytes[1B][0m
[00:00:00.258,300] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: alloc wra: 0, ca8[1B][0m
[00:00:00.258,300] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: data wra: 0, 22c[1B][0m
Reboot counter history: ...99...98...97...96...95...94...93...92...91...90...89...88...87...86...85...84...83...82...81...80...79...78...77...76...75...74...73...72...71...70...69...68...67...66...65...64...63...62...61...60...59...58...57...56...55...54...53...52...51...50...49...48...47...46...45...44...43...42...41...40...39...38...37...36...35...34...33...32...31...30...29...28...27...26...25...24...23...22...21...20...19...18...17...16...15...14...13...12...11...10...9...8...7...6...5...4...3...2...1...0
Oldest reboot counter: 0
Rebooting in ...5...4...3...2...1
*** Booting Zephyr OS build v2.4.99-ncs2  ***
Id: 1, Address: 192.168.1.1
Id: 2, Key: ff fe fd fc fb fa f9 f8 
Id: 3, Reboot_counter: 100
Id: 5, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 
[00:00:00.258,239] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: 3 Sectors of 4096 bytes[1B][0m
[00:00:00.258,239] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: alloc wra: 0, ca0[1B][0m
[00:00:00.258,270] [1B][0m&amp;lt;inf&amp;gt; fs_nvs: data wra: 0, 230[1B][0m
Reboot counter history: ...100...99...98...97...96...95...94...93...92...91...90...89...88...87...86...85...84...83...82...81...80...79...78...77...76...75...74...73...72...71...70...69...68...67...66...65...64...63...62...61...60...59...58...57...56...55...54...53...52...51...50...49...48...47...46...45...44...43...42...41...40...39...38...37...36...35...34...33...32...31...30...29...28...27...26...25...24...23...22...21...20...19...18...17...16...15...14...13...12...11...10...9...8...7...6...5...4...3...2...1...0
Oldest reboot counter: 0
Rebooting in ...5...4...3...2...1
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please test the above and report back what result you got&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: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/308591?ContentTypeID=1</link><pubDate>Thu, 06 May 2021 15:06:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8034b941-c1d5-4632-b7c8-de7482d64573</guid><dc:creator>NathanML</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Thanks for the response!&lt;/p&gt;
&lt;p&gt;As I&amp;#39;m already seeing the full log output, similar to the hard fault example, I ran the addr2line command in my&amp;nbsp;&lt;em&gt;&amp;lt;application&amp;gt;/&amp;lt;build folder&amp;gt;/zephyr&lt;/em&gt; but did not receive a useful response:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;$ addr2line -e zephyr.elf 0x000054d4
:?&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The fault occurs when I call the&amp;nbsp;&lt;em&gt;nvs_write&lt;/em&gt; function. Using breakpoints in nvs.c I see that the underlying function causing the hard fault is&amp;nbsp;&lt;em&gt;flash_write&lt;/em&gt;&amp;nbsp;(as called by&amp;nbsp;&lt;em&gt;nvs_flash_al_wrt&lt;/em&gt;&lt;em&gt;, &lt;/em&gt;which was called by&amp;nbsp;&lt;em&gt;nvs_flash_data_wrt, &lt;/em&gt;which was called by&amp;nbsp;&lt;em&gt;nvs_flash_wrt_entry).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure where to go from here. Based on your tutorial link to hard faults, and note that mentions they are often do to a stack overflow, I increased CONFIG_MAIN_STACK_SIZE to give that a try, but the results were the same.&lt;/p&gt;
&lt;p&gt;Also, could you address the word-alignment error I&amp;#39;m getting with the default nvs sample code on the nRF52840 development kit? I&amp;#39;d like to avoid this error on our custom hardware as well, once we can get flash writes working.&lt;/p&gt;
&lt;p&gt;I appreciate your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hard fault when using NVS with Zephyr on nRF52</title><link>https://devzone.nordicsemi.com/thread/308515?ContentTypeID=1</link><pubDate>Thu, 06 May 2021 10:57:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1a75112-4d30-4e52-b671-d16090c34d40</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-3-ncs-v1-4-0#mcetoc_1f4cg7h4q0"&gt;NCS Tutorial--&amp;gt;Error handling--&amp;gt;Other tools and tips--&amp;gt;Hard faults&lt;/a&gt;&amp;nbsp;may help getting to the bottom of this.&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></channel></rss>