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 - How to find 'const' variable physical address?

Other Parts Discussed in Thread: CC2541

Hello, 

How can one tell the actual physical address of const variable in run time ?

I would like to modify const variable using HalFlashWrite() but I don't know the physical address (considering the flash bank used)...

Thanks

  • Hi Eyalasko,

    At run time, you can use the address-of operator (&) to get a const variable's address at run time. However, note that the variable may not be in Flash as expected.

    For example you can place the variable in the global scope, and there's a high chance the variable will be in flash. (Instead of being optimized out or placed in RAM)

    If you do go this approach, make sure to review Section 7.5 in the 26xx Technical Reference Manual (http://www.ti.com/lit/pdf/swcu117) on how to properly write to flash for 26xx devices. Chapter 6 of the 25xx User's Guide if you're using a CC254x device.(http://www.ti.com/lit/pdf/swru191)

    Hope this helps,

    -Rebel

  • Hey, 

    Thanks for your reply.

    In my application I need a variable to be persistent hence it has to be located in flash (using const keyword with either __code or __xdata_rom attribute).

    However, since CC2541 has a banked flash architecture, accessing the address with the address-of operator (&) does not return the actual physical address of the variable, only its  a mapped address in the contiguous 0000-FFFF code address space making it unsuitable for using with HalFlashWrite() function.

  • Hey Eyalasko,

    You're absolutely right; Is there a particular reason why it needs to be during run time?

    Another approach would be to reserve a bank for your data and use the application note below to place all your data there. Then use the address of operator to get their relative positions in the bank. (Or just keep track of the declaration order)

    It's a Technical Note for IAR's Linker - There's a similar process for CCS.

    https://www.iar.com/support/tech-notes/linker/how-do-i-place-a-group-of-functions-or-variables-in-a-specific-section/

    This won't give you at the logical address at run time, but instead will allow you to specify where to place your information prior. This would allow you to be able to use HalFlashWrite with the correct addresses with some math. If you do go this approach, make sure to save a backup of your (.xcl) file.

    Note that there's other ways to specify location of variables/functions within IAR, see the "Controlling data and function placement in memory" section in the IAR help for additional examples. (eg. the #pragma location=)

    There's been other posts on HalFlashWrite, take a look at https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/340456

    Generally, we recommend utilizing SNV, via osal_snv_read and osal_snv_write  for CC25xx for flash writes.

    Hope this helps,

    -Rebel