<?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 execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/5966/how-to-execute-code-from-ram-on-nrf51-using-gcc-environment</link><description>How to execute code from RAM on nRF51 using GCC Environment</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 Mar 2015 15:07:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/5966/how-to-execute-code-from-ram-on-nrf51-using-gcc-environment" /><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20814?ContentTypeID=1</link><pubDate>Tue, 31 Mar 2015 15:07:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:752b7133-0a49-45e8-85f9-c49ad8cee53f</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon&lt;/p&gt;
&lt;p&gt;unsigned char *encryptedData;
unsigned int encryptedDataAfterAppendingLength;&lt;/p&gt;
&lt;p&gt;memset(encryptedData, 0, encryptedDataAfterAppendingLength);&lt;/p&gt;
&lt;p&gt;In order to execute this from RAM , how I can rewrite this code using for loop.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20810?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2015 14:40:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d37697d8-538e-4a49-90de-e01db14bfa29</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Anand,&lt;/p&gt;
&lt;p&gt;You&amp;#39;re seeing a conflict between the function you state to be placed in RAM, where it calls functions that have been placed in .text (flash) and therefore the linker throws an error back. In order to link the application properly, you will have to make sure that all functions called within the function that you have placed in RAM, also are located in RAM. If not, only partial segments of the call tree  is present in RAM, thus invoking a higher current consumption. I would recommend that you look into the gcc linker scripts and create proper RAM-segments, or manually trace the call tree of your function and place the sub-functions into RAM using attribute.
However; What I have to ask is which functions do you need to place in RAM? Normally you want time-consuming functions to be placed in RAM, for instance flash-writing operations, or interrupt functions.&lt;/p&gt;
&lt;p&gt;Cheers,
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20805?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2015 12:02:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4d96cfc-c0aa-4d08-b7fb-8b84d8f67a43</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;I  tested with SDK v7 , Still I am facing the same issue as below.
(.data+0x1a): relocation truncated to fit: R_ARM_THM_CALL against symbol `simple_uart_putstring&amp;#39; defined in .text.simple_uart_putstring section in _build/simple_uart.o&lt;/p&gt;
&lt;p&gt;Can you please check this on higher priority.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20808?ContentTypeID=1</link><pubDate>Wed, 25 Mar 2015 09:07:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e938751-8b0f-4a28-9cab-7d0d43b5ccb0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Anand, It seems like there is some incompatibilities in SDK v6 with regards to placing functions in RAM (and calling flash-functions). I could not get this to work properly either. Could you try this on SDK v7.x or newer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20804?ContentTypeID=1</link><pubDate>Tue, 24 Mar 2015 17:09:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c366abb6-2224-4c1b-a430-ee5cb7e78322</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;function2() has variable assignments like saving data from local variable to global variable, and  itos() and memcpy() function and also some function which are related to our application are called.&lt;/p&gt;
&lt;p&gt;I just did one simple experiment like below code which does not have any memcpy or memcpy.&lt;/p&gt;
&lt;p&gt;void toggle_GPIO();
int main(void)
{
toggle_GPIO();
}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;attribute&lt;/strong&gt;((used, long_call, section(&amp;quot;.data&amp;quot;))) void toggle_GPIO(void)
{
nrf_gpio_pin_set(NRF_GPIO0);
nrf_gpio_pin_clear(NRF_GPIO0);
}&lt;/p&gt;
&lt;p&gt;when I build it I got the error &amp;quot;d:..........Source/main.c:190:(.data+0xc): relocation truncated to fit: R_ARM_THM_CALL against `nrf_gpio_pin_clear&amp;quot;.&amp;#39;&lt;/p&gt;
&lt;p&gt;Is the section(&amp;quot;.data&amp;quot;) is the proper section name we are putting. Do I need to give some other section name instead of &amp;quot;.data&amp;quot;? or do I need to change any thing in the gcc_startup_nrf51.s or Makefile.common or in linker files?&lt;/p&gt;
&lt;p&gt;could you please share your email id ?
Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20803?ContentTypeID=1</link><pubDate>Tue, 24 Mar 2015 16:37:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5b9e80d-afa8-4ac3-93fe-fc6df4a165ba</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;What does function2() consist of? Could you try a simpler function which toggles a GPIO or similar and place it in RAM? Does it compile properly then?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20809?ContentTypeID=1</link><pubDate>Tue, 24 Mar 2015 15:37:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:086d07bb-1f3a-4433-9737-422fce92974b</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;Thanks for your input :) .&lt;/p&gt;
&lt;p&gt;Regarding the command &lt;strong&gt;attribute&lt;/strong&gt;((used, long_call, section(&amp;quot;.data&amp;quot;))) , I have implemented as  below. I want to put function1 into RAM.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;attribute&lt;/strong&gt;((used, long_call, section(&amp;quot;.data&amp;quot;)))  void function1(unsigned char *Data, uint16_t len)
{&lt;/p&gt;
&lt;p&gt;function2(Data, len);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;When I tried to build I got the error as &amp;quot;(.data+0x20): relocation truncated to fit: R_ARM_THM_CALL against `function2&amp;#39;&amp;quot;.&lt;/p&gt;
&lt;p&gt;is there any thing I need to change in the linker files(I am using SDK6.1).&lt;/p&gt;
&lt;p&gt;Sorry it looks like some basic stuff , But still I need your help to understand this.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20802?ContentTypeID=1</link><pubDate>Tue, 24 Mar 2015 14:33:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae2cc8ee-d126-467a-9204-8da703ef9df4</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Anand, In theory you can run all your code in RAM if you have the space. However; it seems like gcc does not like it when you try to put standard functions (like memset from string.h) in RAM. This functionality is more towards the compiler suite that you&amp;#39;re using rather than nordic specific functionality, so we do not really have any guidelines on this. Note that even if you put calls to the softdevice into RAM, the softdevice will still access the flash to run it&amp;#39;s own functions.&lt;/p&gt;
&lt;p&gt;Cheers,
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20813?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2015 13:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45871e14-cd1c-4459-b378-aae4027fb0a0</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;I just put the adverise_init into RAM to test whether  &lt;strong&gt;attribute&lt;/strong&gt;((used, long_call, section(&amp;quot;.data&amp;quot;)))  command will work or not. Right now I am thinking about what are the functions i can run from the RAM. Do you have any document or can you share some information about what are the functions in general/softdevice calls i can move it to RAM, So that i can achieve the maximum power optimization.&lt;/p&gt;
&lt;p&gt;Note: The reason i am trying to execute code from RAM instead of flash is to optimize the  power. When i check the nRF51822 version 3.1  product specification doc , i found there is 1.7 mA current consumption difference between Flash and RAM code execution.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20812?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2015 13:13:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b413296-750f-4c14-9487-5d3d2e7df41d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Anand,&lt;/p&gt;
&lt;p&gt;It seems gcc is trying to place standard functions (memset) into RAM, which will not work. Try switching out the &amp;quot;memset&amp;quot; command with a for-loop or similar to set it to &amp;#39;0&amp;#39;. Is there a specific reason why you want to place this specific function &amp;quot;advertising_init&amp;quot; in RAM? Normally you run this function only once, then you&amp;#39;re done with it. It makes more sense to place timing and power critical functions in RAM.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20811?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2015 08:46:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a50d1f65-ec64-4b70-8464-7b6fd8c0f04b</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;To give you a more information.
Please find below versions of the software and hardware I am using.&lt;/p&gt;
&lt;p&gt;Soft device :s110_nrf51822_7.0.0_softdevice
SDK : 6.1
Hardware : N51822 QFACA1 1442AB (version 3.1 -32 KB RAM variant).&lt;/p&gt;
&lt;p&gt;Can you suggest me which files and what changes are needed to come out of the above error.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20807?ContentTypeID=1</link><pubDate>Fri, 20 Mar 2015 15:36:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c64bde4-1290-448e-a47e-8f665c2419c1</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;As per your suggestion I have made changes for one of the function as below.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;attribute&lt;/strong&gt;((used, long_call, section(&amp;quot;.data&amp;quot;))) void advertising_init(void)
{
uint32_t      err_code;
st_device_status device_status;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
static uint8_t device_status_value;
//uint8_t      	flags = BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;.
.
.
.&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;But when I tried to build the project I found below error:&lt;/p&gt;
&lt;p&gt;D:\Power_optimization_Working_code\Power_Optimization_FV_15_Working_Copy\Build/../nRF_Application/Source/nRF_Advertise.c:39:(.data+0x1c): relocation truncated to fit: R_ARM_THM_CALL against symbol &lt;code&gt;device_info&amp;#39; defined in .text.device_info section in _build/nRF_Authentication.o D:\Power_optimization_Working_code\Power_Optimization_FV_15_Working_Copy\Build/../nRF_Application/Source/nRF_Advertise.c:56:(.data+0x38): relocation truncated to fit: R_ARM_THM_CALL against symbol&lt;/code&gt;memset&amp;#39; defined in .text.memset section in C:/Program Files/GNU Tools ARM Embedded/4.8 2013q4/arm-none-eabi/lib/armv6-m\libc.a(lib_a-memset.o)
D:\Power_optimization_Working_code\Power_Optimization_FV_15_Working_Copy\Build/../nRF_Application/Source/nRF_Advertise.c:73:(.data+0x8c): relocation truncated to fit: R_ARM_THM_CALL against symbol &lt;code&gt;memset&amp;#39; defined in .text.memset section in C:/Program Files/GNU Tools ARM Embedded/4.8 2013q4/arm-none-eabi/lib/armv6-m\libc.a(lib_a-memset.o) D:\Power_optimization_Working_code\Power_Optimization_FV_15_Working_Copy\Build/../nRF_Application/Source/nRF_Advertise.c:95:(.data+0xee): relocation truncated to fit: R_ARM_THM_CALL against symbol&lt;/code&gt;ble_advdata_set&amp;#39; defined in .text.ble_advdata_set section in _build/ble_advdata.o
D:\Power_optimization_Working_code\Power_Optimization_FV_15_Working_Copy\Build/../nRF_Application/Source/nRF_Advertise.c:107:(.data+0x10a): relocation truncated to fit: R_ARM_THM_CALL against symbol `app_error_handler&amp;#39; defined in .text.app_error_handler section in _build/main.o
collect2.exe: error: ld returned 1 exit status
make: *** [_build/FITTING_BOARD_HWV1P0_SD7_FV15_s110_xxaa.out] Error 1&lt;/p&gt;
&lt;p&gt;Could you please let me know what is the issue.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20806?ContentTypeID=1</link><pubDate>Fri, 20 Mar 2015 13:16:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:020fdeee-5d37-4af9-94c0-0e41915fed72</guid><dc:creator>Anand Ramashetty</dc:creator><description>&lt;p&gt;Hi Håkon,&lt;/p&gt;
&lt;p&gt;Thanks a lot for your reply. I will implement this and  let you know the status.&lt;/p&gt;
&lt;p&gt;Regards,
Anand&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to execute code from RAM on nRF51 using GCC Environment</title><link>https://devzone.nordicsemi.com/thread/20801?ContentTypeID=1</link><pubDate>Fri, 20 Mar 2015 12:38:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2239abc4-dc53-4aa0-9488-9da883f09c1a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can place a function in RAM in GCC like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;__attribute__((used, long_call, section(&amp;quot;.data&amp;quot;))) void some_func(void)
{
  do_something();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then you should check the .map file to see that it&amp;#39;s located somewhere in RAM (0x2000XYZZ)&lt;/p&gt;
&lt;p&gt;Cheers,
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>