How to execute code from RAM on nRF51 using GCC Environment
How to execute code from RAM on nRF51 using GCC Environment
Hi Håkon,
I just put the adverise_init into RAM to test whether attribute((used, long_call, section(".data"))) 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.
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.
Regards, Anand
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'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's own functions.
Cheers, Håkon
Hi Håkon,
Thanks for your input :) .
Regarding the command attribute((used, long_call, section(".data"))) , I have implemented as below. I want to put function1 into RAM.
attribute((used, long_call, section(".data"))) void function1(unsigned char *Data, uint16_t len) {
function2(Data, len);
}
When I tried to build I got the error as "(.data+0x20): relocation truncated to fit: R_ARM_THM_CALL against `function2'".
is there any thing I need to change in the linker files(I am using SDK6.1).
Sorry it looks like some basic stuff , But still I need your help to understand this.
Regards, Anand
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?
Hi Håkon,
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.
I just did one simple experiment like below code which does not have any memcpy or memcpy.
void toggle_GPIO(); int main(void) { toggle_GPIO(); }
attribute((used, long_call, section(".data"))) void toggle_GPIO(void) { nrf_gpio_pin_set(NRF_GPIO0); nrf_gpio_pin_clear(NRF_GPIO0); }
when I build it I got the error "d:..........Source/main.c:190:(.data+0xc): relocation truncated to fit: R_ARM_THM_CALL against `nrf_gpio_pin_clear".'
Is the section(".data") is the proper section name we are putting. Do I need to give some other section name instead of ".data"? or do I need to change any thing in the gcc_startup_nrf51.s or Makefile.common or in linker files?
could you please share your email id ? Regards, Anand