This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541 store const data at specific address

Other Parts Discussed in Thread: CC2541

Dear all

I'm using CC2541 connected to an external MCU, everything works fine.
I would like to store 8 bytes at a known address into flash memory code.

I tried the following using IAR:

in my .c file:

#pragma location = "MY_CONST_FLASH_SEGMENT"
__root const uint8 myConsts[8] = { 0,1,2,3,4,5,6,7 };

and in the linker file ti_51ew_cc2540b.xcl

after the checksum definition

-Z(CODE)CHECKSUM#_CODE_END

I added 

-P(CODE)MY_CONST_FLASH_SEGMENT#0x3FFF0-0x3FFFF

I can see the bytes correctly stored when generating a bin output, anyway this seems to conflict with lock bits that seems to be stored also at the end of the 256K flash.
I tried other addresses without success.

My questions are :

1) Is there a better way to place 8 bytes in flash ?

2) What addresses in the flash could be safe to store those 8 bytes (without conflicting with flash locks bits, and without penalizing the compiler to compile properly) ?

thanks to all !

  • Hello.  This is dangerous as areas of flash are used by the stack for bonding, lock bits, etc.

    The safest way to do this is to the osal_snv_write() function which addresses memory by "ID's".
      You will need to ensure not to use an ID that is used by the stack.

    // Device NV Items -    Range 0 - 0x1F
    #define BLE_NVID_IRK                    0x02  //!< The Device's IRK
    #define BLE_NVID_CSRK                   0x03  //!< The Device's CSRK
    #define BLE_NVID_SIGNCOUNTER            0x04  //!< The Device's Sign Counter

    // Bonding NV Items -   Range  0x20 - 0x5F    - This allows for 10 bondings
    #define BLE_NVID_GAP_BOND_START         0x20  //!< Start of the GAP Bond Manager's NV IDs
    #define BLE_NVID_GAP_BOND_END           0x5f  //!< End of the GAP Bond Manager's NV IDs Range

    // GATT Configuration NV Items - Range  0x70 - 0x79 - This must match the number of Bonding entries
    #define BLE_NVID_GATT_CFG_START         0x70  //!< Start of the GATT Configuration NV IDs
    #define BLE_NVID_GATT_CFG_END           0x79  //!< End of the GATT Configuration NV IDs