This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to execute code from RAM on nRF51 using GCC Environment

How to execute code from RAM on nRF51 using GCC Environment

  • Hi,

    You can place a function in RAM in GCC like this:

    __attribute__((used, long_call, section(".data"))) void some_func(void)
    {
      do_something();
    }
    

    Then you should check the .map file to see that it's located somewhere in RAM (0x2000XYZZ)

    Cheers, Håkon

  • Hi Håkon,

    Thanks a lot for your reply. I will implement this and let you know the status.

    Regards, Anand

  • Hi Håkon,

    As per your suggestion I have made changes for one of the function as below.

    attribute((used, long_call, section(".data"))) void advertising_init(void) { uint32_t err_code; st_device_status device_status;

    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;
    

    . . . .

    }

    But when I tried to build the project I found below error:

    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 device_info' 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 symbolmemset' 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 memset' 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 symbolble_advdata_set' 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' 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

    Could you please let me know what is the issue.

    Regards, Anand

  • Hi Håkon,

    To give you a more information. Please find below versions of the software and hardware I am using.

    Soft device :s110_nrf51822_7.0.0_softdevice SDK : 6.1 Hardware : N51822 QFACA1 1442AB (version 3.1 -32 KB RAM variant).

    Can you suggest me which files and what changes are needed to come out of the above error.

    Regards, Anand

  • Hi Anand,

    It seems gcc is trying to place standard functions (memset) into RAM, which will not work. Try switching out the "memset" command with a for-loop or similar to set it to '0'. Is there a specific reason why you want to place this specific function "advertising_init" in RAM? Normally you run this function only once, then you're done with it. It makes more sense to place timing and power critical functions in RAM.

Related