<?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>Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3686/setting-address-of-variable-in-flash</link><description>Hi, 
 Is it possible to set an address lets say for an array to be in Flash memory on compilation?
So that way I dont need to reserve memory twice - once in my program memory area and once in flash. 
 Thanks!</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 May 2015 08:42:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3686/setting-address-of-variable-in-flash" /><item><title>RE: Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/thread/13390?ContentTypeID=1</link><pubDate>Thu, 21 May 2015 08:42:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89a92ae2-0895-40ae-a768-338e52c5c78b</guid><dc:creator>michaeld</dc:creator><description>&lt;p&gt;This is amazing thank you very much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/thread/13389?ContentTypeID=1</link><pubDate>Sun, 31 Aug 2014 16:44:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e020f071-39a3-489e-abf2-c98c9f6dd829</guid><dc:creator>Sergy</dc:creator><description>&lt;p&gt;Awesome! Thanks so much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/thread/13388?ContentTypeID=1</link><pubDate>Sun, 31 Aug 2014 16:39:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4888ecda-fd9d-452c-aaf9-3556755e93f8</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Yes, you just need to create my_array somewhere in your program with that line and then you can use it as any other array.&lt;/p&gt;
&lt;p&gt;And one more, I edited my answer and added const declaration as it may cause some troubles like &lt;a href="https://devzone.nordicsemi.com/question/12800/flashing-bootloader-and-application-via-j-link/?answer=12930#post-id-12930"&gt;this&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/thread/13387?ContentTypeID=1</link><pubDate>Sun, 31 Aug 2014 16:34:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d0d1acc-5ee0-4863-9044-c2d3be54830d</guid><dc:creator>Sergy</dc:creator><description>&lt;p&gt;fantastic thanks a lot! but i cant define a second one? so basically i need to make just one array and then just work with it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/thread/13386?ContentTypeID=1</link><pubDate>Sun, 31 Aug 2014 16:14:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b048271-a3a7-4764-8970-ab3aeb3061df</guid><dc:creator>Sergy</dc:creator><description>&lt;p&gt;something like this indeed! how can i set it up in Keil?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting address of variable in flash</title><link>https://devzone.nordicsemi.com/thread/13385?ContentTypeID=1</link><pubDate>Sun, 31 Aug 2014 16:10:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f948ab4c-efc7-4ca0-a443-5549b1038722</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You mean something like this?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const uint8_t __attribute__((section (&amp;quot;.my_array_in_flash_sect&amp;quot;))) my_array[my_array_size] __attribute__((used)) = {0};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;gcc_nrf51_s110_xxaa.ld&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)

MEMORY
{
  FLASH (rx) : ORIGIN = 0x14000, LENGTH = 0x13C00 /* 80 kB is taken by S110, 16kB is taken by bootloader,  160 kB available for application in single bank mode or 80 kB in dual bank mode, 1kB for my array */
  my_array_in_flash (rwx) : ORIGIN = 0x27C00, LENGTH = 0x400 /* my array */
  RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */
}
INCLUDE &amp;quot;gcc_nrf51_common.ld&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;gcc_nrf51_common.ld&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SECTIONS
{
    .my_array_in_flash_block 0x00027C00 :
    {
        KEEP(*(.my_array_in_flash_sect))
    } &amp;gt; my_array_in_flash
...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;UPD:&lt;/p&gt;
&lt;p&gt;For Keil it&amp;#39;s like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define MY_ARRAY_ADDRESS     0x28C00
const uint8_t  my_array[my_array_size] __attribute__((at(MY_ARRAY_ADDRESS))) __attribute__((used)) = {0};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Keil-memory-map.png" alt="image description" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>