<?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>How to place constants at know address?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20736/how-to-place-constants-at-know-address</link><description>Hello, 
 when I was working on MSP430 I used to place the firmware version constant at a known address in flash so that it can be verified which firmware version is flashed without running the application, just by reading the flash with a programmer</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 May 2017 01:00:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20736/how-to-place-constants-at-know-address" /><item><title>RE: How to place constants at know address?</title><link>https://devzone.nordicsemi.com/thread/80923?ContentTypeID=1</link><pubDate>Wed, 03 May 2017 01:00:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6ad4ab6-2471-4f69-be77-0de733585d87</guid><dc:creator>pmeilleur</dc:creator><description>&lt;p&gt;Same here, and I went to conclusion that it is not quite simple when you do not want to use Flash Write / FDS (Flash Data Storage) module, nor the UICR registers (limited to 128B, not really scalable)&lt;/p&gt;
&lt;p&gt;In my case, I want to store data once at production time with a production jig, at a fixed and predetermined location that will not be overwritten during DFU / by the bootloader process. It seems that the Flash Data Storage will use the UPPER region right below the bootloader, which is located in my case at &lt;code&gt;0x73000&lt;/code&gt;. Since the &lt;strong&gt;FDS will use the same/share APP_DATA region&lt;/strong&gt; and that FDS &lt;strong&gt;is used by the peer_manager&lt;/strong&gt; which I do not have control on it, I want to make sure that my app_data &lt;strong&gt;will never be corrupted nor overwritten.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When the number of pages (3) are the same, there is no room left for &amp;quot;real&amp;quot; app_data (hard written at production time), typically&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# define DFU_APP_DATA_RESERVED CODE_PAGE_SIZE  *  3

# define FDS_VIRTUAL_PAGES   3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then I figured to allow (at least) one more APP_DATA page (4 | &lt;code&gt;0x4000&lt;/code&gt;) than what is allowed for the FDS (3 | &lt;code&gt;0x3000&lt;/code&gt;), and created the following macros:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define FDS_TOTAL_SIZE         (FDS_VIRTUAL_PAGES*FDS_VIRTUAL_PAGE_SIZE*4)
#define APP_DATA_TOTAL_SIZE    (DFU_APP_DATA_RESERVED-FDS_TOTAL_SIZE)
#define FS_PAGE_START_ADDR     ((uint32_t)FS_PAGE_END_ADDR - FDS_TOTAL_SIZE)

#define APP_DATA_END_ADDR      (FS_PAGE_START_ADDR)
#define APP_DATA_START_ADDR    ((uint32_t)APP_DATA_END_ADDR - APP_DATA_TOTAL_SIZE)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I would have appreciated that this would have been explicitly designed and documented so this I why I took the time to share.&lt;/p&gt;
&lt;p&gt;Be aware that when the bootloader is not present, the macro FS_PAGE_END_ADDR returns the end of the flash (0x80000), not the (not present) bootloader address (0x73000 in my case).&lt;/p&gt;
&lt;p&gt;Here is some useful Iogguing code to validate what is happening at runtime:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    NRF_LOG_DEBUG(&amp;quot;SOFTDEVICE_REGION_START              (0x%08X)\n&amp;quot;, (uint32_t)SOFTDEVICE_REGION_START);
      
    NRF_LOG_DEBUG(&amp;quot;CODE_REGION_1_START                  (0x%08X)\n&amp;quot;, (uint32_t)CODE_REGION_1_START);
    
    NRF_LOG_DEBUG(&amp;quot;BOOTLOADER_START_ADDR                (0x%08X)\n&amp;quot;, (uint32_t)BOOTLOADER_START_ADDR);               // extern uint32_t* Image$$ER_IROM1$$Base
    
    NRF_LOG_DEBUG(&amp;quot;NRF_MBR_PARAMS_PAGE_ADDRESS          (0x%08X)\n&amp;quot;, (uint32_t) NRF_MBR_PARAMS_PAGE_ADDRESS);  //0x7E000
    NRF_LOG_HEXDUMP_INFO((uint32_t*)NRF_MBR_PARAMS_PAGE_ADDRESS, 64);

    NRF_LOG_DEBUG(&amp;quot;BOOTLOADER_SETTINGS_ADDRESS          (0x%08X)\n&amp;quot;, (uint32_t)BOOTLOADER_SETTINGS_ADDRESS);   //0x7F000
    NRF_LOG_HEXDUMP_INFO((uint32_t*)BOOTLOADER_SETTINGS_ADDRESS, 64);

    NRF_LOG_DEBUG(&amp;quot;CODE_PAGE_SIZE                       (0x%08X)\n&amp;quot;, (uint32_t)CODE_PAGE_SIZE);
    NRF_LOG_DEBUG(&amp;quot;DFU_APP_DATA_RESERVED                (0x%08X)\n\n&amp;quot;, (uint32_t)DFU_APP_DATA_RESERVED);

    

    if (APP_DATA_TOTAL_SIZE &amp;lt; CODE_PAGE_SIZE)
    {
        NRF_LOG_WARNING(&amp;quot;DFU_APP_DATA_RESERVED contains only FDS_VIRTUAL_PAGES, APP_DATA WILL BE OVERWRITTEN by FDS (peer_manager)!!!!\n&amp;quot;);
    }
    else
    {
        NRF_LOG_DEBUG(&amp;quot;APP_DATA_START_ADDR                  (0x%08X)\n&amp;quot;, (uint32_t)APP_DATA_START_ADDR);
        NRF_LOG_DEBUG(&amp;quot;APP_DATA_TOTAL_SIZE                  (0x%08X)\n&amp;quot;, (uint32_t)APP_DATA_TOTAL_SIZE);
        NRF_LOG_DEBUG(&amp;quot;APP_DATA_END_ADDR                    (0x%08X)\n&amp;quot;, (uint32_t)APP_DATA_END_ADDR);
        NRF_LOG_HEXDUMP_INFO((uint32_t*)APP_DATA_START_ADDR, APP_DATA_TOTAL_SIZE); 
    }


    NRF_LOG_DEBUG(&amp;quot;FS_PAGE_START_ADDR                   (0x%08X)\n&amp;quot;, (uint32_t)FS_PAGE_START_ADDR);
    NRF_LOG_DEBUG(&amp;quot;FS_TOTAL_SIZE                        (0x%08X)\n&amp;quot;, (uint32_t)FDS_TOTAL_SIZE);
    NRF_LOG_DEBUG(&amp;quot;FS_PAGE_END_ADDR                     (0x%08X)\n&amp;quot;, (uint32_t)FS_PAGE_END_ADDR);        
  //  NRF_LOG_HEXDUMP_INFO((uint32_t*)FS_PAGE_START_ADDR, FDS_TOTAL_SIZE);

    
    NRF_LOG_DEBUG(&amp;quot;NRF_UICR_BOOTLOADER_START_ADDRESS    (0x%08X)\n&amp;quot;, (uint32_t)NRF_UICR_BOOTLOADER_START_ADDRESS);
    NRF_LOG_DEBUG(&amp;quot;NRF_UICR_MBR_PARAMS_PAGE_ADDRESS     (0x%08X)\n\n&amp;quot;, (uint32_t)NRF_UICR_MBR_PARAMS_PAGE_ADDRESS);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, does anybody see any possible catch in my approach for reserving an APP_DATA location? Any feedback would be appreciated!&lt;/p&gt;
&lt;p&gt;With my best regards,&lt;/p&gt;
&lt;p&gt;Philippe Meilleur&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to place constants at know address?</title><link>https://devzone.nordicsemi.com/thread/80922?ContentTypeID=1</link><pubDate>Thu, 23 Mar 2017 10:16:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74364757-f902-48f0-96c4-0a22fa2a0033</guid><dc:creator>Frederik</dc:creator><description>&lt;p&gt;See &lt;a href="http://www.keil.com/support/man/docs/armcc/armcc_chr1359124981140.htm"&gt;www.keil.com/.../armcc_chr1359124981140.htm&lt;/a&gt; (for example) for how to assign addresses to static variables in keil.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to place constants at know address?</title><link>https://devzone.nordicsemi.com/thread/80921?ContentTypeID=1</link><pubDate>Thu, 23 Mar 2017 09:34:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6574e363-a200-4241-b02e-20a8ee6bc650</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can use the method shown in the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/flashwrite_example.html?cp=4_0_1_4_5_9"&gt;Flash Write Example&lt;/a&gt; to write directly to addresses in flash.&lt;/p&gt;
&lt;p&gt;You should also check out the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/uicr.html?cp=2_2_0_13#concept_rnp_grp_xr"&gt;UICR registers&lt;/a&gt;, and the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/uicr_config_example.html?cp=4_0_1_4_5_41"&gt;UICR Config Example&lt;/a&gt; in the SDK, which are intended for storing user specific settings in non-volatile memory.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>