<?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>Flash addresses and erasing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74841/flash-addresses-and-erasing</link><description>Hi, I&amp;#39;m working with flash, I&amp;#39;ve started with the example code from flash_storage, as I will need to use flash while using a SoftDevice. 
 I use NRF52 Dongle and SDK17.0.2 + S340. 
 I have fundamental problems I think, understanding how this is supposed</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 07 May 2021 10:10:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74841/flash-addresses-and-erasing" /><item><title>RE: Flash addresses and erasing</title><link>https://devzone.nordicsemi.com/thread/308697?ContentTypeID=1</link><pubDate>Fri, 07 May 2021 10:10:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15639739-6998-4c09-aafa-b2609988472d</guid><dc:creator>dragilla</dc:creator><description>&lt;p&gt;This is perfect. Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash addresses and erasing</title><link>https://devzone.nordicsemi.com/thread/308693?ContentTypeID=1</link><pubDate>Fri, 07 May 2021 09:56:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64187265-5f30-4fbd-ad1f-fa6704cdd9a2</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Lukasz,&lt;/p&gt;
&lt;p&gt;It is typically possible to get the flash size build time from the linker, but the exact method depends on the toolchain (see for instance &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/6784/get-maximal-free-flash-size-at-runtime"&gt;this thread&lt;/a&gt;). However,&amp;nbsp;it would typically be more usefull to make the memory map yourself and decide to use a specific set of pages for your data storage, and then instead modify the linker script / project file for your app so that you get a linker error if it becomes too large.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash addresses and erasing</title><link>https://devzone.nordicsemi.com/thread/308690?ContentTypeID=1</link><pubDate>Fri, 07 May 2021 09:49:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f27a454-59a7-40dd-b4d8-ce6bea4aa1b7</guid><dc:creator>dragilla</dc:creator><description>&lt;p&gt;Ok. Thank you very much for your answer. It confirms what I thought I understood. My prblem was - I forgot that I have a bootloader and was trying to write to flash in its location.&lt;/p&gt;
&lt;p&gt;Anyway. I still have one more question. Is there a was to check from inside of the application, whre is the lower limit of available flash memory? The upper limit being my bootloader, the lower being the end of my application. I know I can check it even in th nrf connect programmer, but can I check from within the application?&lt;/p&gt;
&lt;p&gt;Thanks and best regards,&lt;/p&gt;
&lt;p&gt;Lukasz&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash addresses and erasing</title><link>https://devzone.nordicsemi.com/thread/308687?ContentTypeID=1</link><pubDate>Fri, 07 May 2021 09:40:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e9b353b-5a66-4e02-8214-d4fcd4871cf7</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]1) Once I call&amp;nbsp;nrf5_flash_end_addr_get and see the end address and the bootloader address =&amp;nbsp;0xFFFFFFFF. does it mean the last page is&amp;nbsp;NRF_FICR-&amp;gt;CODEPAGESIZE * (NRF_FICR-&amp;gt;CODESIZE - 1)?[/quote]
&lt;p&gt;This code checks if a bootloader is present (in that case&amp;nbsp;BOOTLOADER_ADDRESS which is a pointer to a word in the UICR or MBR page depending on SDK version will be set to something other than 0xFFFFFFFF). If it is, the last flag page that is used by the example is the last page before the bootloader. If not, the last page that is used is the last physical page and therefor the&amp;nbsp;nrf5_flash_end_addr_get() returns the end accordingly.&lt;/p&gt;
&lt;p&gt;Specifically answering your question, when a&amp;nbsp; bootloader is not present,&amp;nbsp;NRF_FICR-&amp;gt;CODEPAGESIZE * (NRF_FICR-&amp;gt;CODESIZE - 1) gives you the start address of the last page. And if you want the address of the last word (which is 4 byte), that would be&amp;nbsp;NRF_FICR-&amp;gt;CODEPAGESIZE&amp;nbsp; * NRF_FICR-&amp;gt;CODESIZE - 4.&lt;/p&gt;
[quote user=""]2) does this mean, than if&amp;nbsp;&lt;span&gt;NRF_FICR-&amp;gt;CODESIZE&amp;nbsp;is 256 then I can use all of them? say I can write 1 byt to address&amp;nbsp;NRF_FICR-&amp;gt;CODEPAGESIZE * (NRF_FICR-&amp;gt;CODESIZE - 1) and 1 byte to address&amp;nbsp;NRF_FICR-&amp;gt;CODEPAGESIZE * (NRF_FICR-&amp;gt;CODESIZE - 256)? In other words,&amp;nbsp;is all flash area available to me and can write to address 0?&lt;/span&gt;[/quote]
&lt;p&gt;No, that depends on what else you have in your flash. You need to keep track of your memory layout. In this example there is only application code in the beginning of flash, and possibly a bootloader in the end. There could also be other things in your app. You can certainly not write to address 0, as that will contain either the MBR if using a SoftDevice or bootloader, or it will contain your interrupt vector etc. Again, if you want to use low level flash access like this you must understand your flash layout.&lt;/p&gt;
[quote user=""]3) Do I always have to do nrf_fstorage_erase before nrf_fstorage_write and when don&amp;#39;t I? Why don&amp;#39;t you do&amp;nbsp;nrf_fstorage_erase&amp;nbsp;in the&amp;nbsp;flash_storage example?[/quote]
&lt;p&gt;The nature of flash memory is so that writing can only change &amp;#39;1&amp;#39; to &amp;#39;0&amp;#39;, and not the other way around. To change &amp;#39;0&amp;#39; to &amp;#39;1&amp;#39; can only be done with a page erase, where all bits in a full page are set to &amp;#39;1&amp;#39; again.&lt;/p&gt;
[quote user=""]4) On my device When try to erase the page&amp;nbsp;NRF_FICR-&amp;gt;CODEPAGESIZE * (NRF_FICR-&amp;gt;CODESIZE - 1) my program freezes. Before, like 2 days ago, it worked. What could have happened? Erasing the device doesn&amp;#39;t help. The same code works on the address from the example:&amp;nbsp;0x3e000[/quote]
&lt;p&gt;I cannot say without knowing more. What have you changed, and what do you find when you debug?&lt;/p&gt;
&lt;p&gt;Note that if you want something more like a file system that will handle the low level details for you, then perhaps using &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_fds.html"&gt;FDS&lt;/a&gt; is more suitable. You can refer to the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/fds_example.html"&gt;FDS example&lt;/a&gt; in that case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>