<?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 can I allocate array in flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95928/how-can-i-allocate-array-in-flash</link><description>hi, 
 can i allocate array in the flash in specific address? 
 i want to save communication time to the flash (I2C) 
 what i need to do to write to flash without spend time for Communication protocol? 
 (i think i can allocate the array in specific adress</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 26 Jan 2023 06:59:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95928/how-can-i-allocate-array-in-flash" /><item><title>RE: how can I allocate array in flash</title><link>https://devzone.nordicsemi.com/thread/406570?ContentTypeID=1</link><pubDate>Thu, 26 Jan 2023 06:59:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a5ed799-1319-4652-8421-73328c242711</guid><dc:creator>Raoul</dc:creator><description>&lt;p&gt;Hi Hadar,&lt;/p&gt;
&lt;p&gt;If I understand you correctly you want to pre-set some i2c communication parameter in flash and so you want to allocate space for an array, at compile time, to a specific absolute memory address. Is that right? Could I ask why you want it stored to a specific address?&lt;/p&gt;
&lt;p&gt;Doing this at compile time would be similar to what someone tried to do in this case: &amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/90846/nrf-connect-sdk--place-variable-in-flash-at-predefined-location"&gt;nRF Connect SDK -place variable in flash at predefined location&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What you would have to do is use &lt;a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes"&gt;GCC attributes&lt;/a&gt; to place your array in a specific linker section, and then create a linker script to place that section at a certain address. I&amp;#39;m not very familiar with this but if you want some more details on the process you could take a look at &lt;a href="https://mcuoneclipse.com/2012/11/01/defining-variables-at-absolute-addresses-with-gcc/"&gt;this article&lt;/a&gt;, or &lt;a href="https://stackoverflow.com/questions/4067811/how-to-place-a-variable-at-a-given-absolute-address-in-memory-with-gcc/4081574#4081574"&gt;this answer&lt;/a&gt; on Stack Overflow, with a &lt;a href="https://stackoverflow.com/questions/4067811/how-to-place-a-variable-at-a-given-absolute-address-in-memory-with-gcc/54128613#54128613"&gt;minimal working example&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To do this within Zephyr&amp;#39;s build system, you would need some Kconfig options allowing the use of custom linker scripts:&lt;/p&gt;
&lt;p&gt;CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y&lt;br /&gt;CONFIG_CUSTOM_LINKER_SCRIPT=&amp;quot;custom_linker_script.ld&amp;quot;&lt;/p&gt;
&lt;p&gt;Please look at Zephyr&amp;#39;s &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/application_development/code_relocation_nocopy/README.html"&gt;code relocation sample&lt;/a&gt; (where I found the kconfig options above) and the documentation page on &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/code-relocation.html"&gt;code and data relocation&lt;/a&gt;. Although, what you&amp;#39;re doing is a bit different, you&amp;#39;re only &amp;quot;moving&amp;quot; a single array instead of everything.&lt;/p&gt;
&lt;p&gt;If you want to store the communication parameters to flash at runtime, (like this customer:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/95882/storage_partition-status-after-firmware-update"&gt;&amp;quot;storage_partition&amp;quot; status after firmware Update&lt;/a&gt;&amp;nbsp; ) then you can use the NVS API, see this sample: &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/nvs/README.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/nvs/README.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Raoul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>