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.

CC2640R2F: How to use a variable defined using #pragma

Part Number: CC2640R2F


Hi all,

I have created a variable using #pragma location and  #pragma NOINIT and assigned a value in one file and I have used it in another file.
The code gets hung when accessing the variable or printing the variable. 


Why is this happening?

  • Hi Roshini,

    Are you using CCS or IAR? Also, could you show me snippets from your code on how you declare and use the variable?
  • Hi Edward,

    Im using CCS and im working on OAD code.

    In bootloader,
    #pragma location = BIM_VAR_ADDR
    #pragma NOINIT(_bim_var)
    uint32_t _bim_var;

    _bim_var= 0x101;

    In downloader,
    Display_print1(dispHandle,0,10,"BIM VARIABLE:%d", _bim_var);

    When I use it in downloader.c (downloader) with UART serial the code gets hung after printing the value once. But when I remove UART the code seems to be working fine without any issue. Or when i re assign a value to _bim_var and use it, the code works fine.
    Eg:
    _bim_var= 0x101; //0x102
    Display_print1(dispHandle,0,10,"BIM VARIABLE:%d", _bim_var);

    Why is this occuring?
  • Your pragma location doesn't look right. I think it should be on the format

    #pragma LOCATION( x , address )
    int x

  • Hi Edward,

    I don't think that's the issue. The _bim_var is defined in the same manner in the example code (simple_peripheral_oad_onchip).

    Also I tried the above method as you suggested. I still get the same behaviour. Could you help me with this issue?

    Thanks,

    Roshini R
  • Could you provide a minimal code example that reproduces this issue, as I'm unable to reproduce this.
  • Hi Edvard,

    Thanks for your reply. I found out that my issue was not due to printing the _bim_var stored using #pragma LOCATION.

     It was due to the lines,

     const char* bimcode[] = {"Hard Reset", "Downloader Restart", "APP Start", "Bad APP Header", "Bad CRC"};

     Display_print1 ("Down Loader :%s", bimcode [ (_bim_var - 0xFF) ] ) ; 

    Can you suggest an alternate method to print this?

    Thanks for your concern.

    Regards,

    Roshini Radhakrishnan.

  • I'm not sure what you are trying to do. Could you elaborate?
  • Hi Edvard,

    Im just trying to display a message based on the _bim_var value;

    Consider this,

    Example 1

    ---------------

    int temp1;

    Display_print0(dispHandle,0,0,"==============================");

    const char* bimcode[] = {"Hard Reset", "Downloader Restart", "APP Start", "Bad APP Header", "Bad CRC"};

    temp1=3;

    Display_print1(dispHandle,0,0,"Down Loader:%s", bimcode[temp1]);

    OUTPUT:

    ==============================

    Down Loader:Bad APP Header

    Example 2

    -----------------

    uint32_t _bim_var;

    int temp1;

    Display_print0(dispHandle,0,0,"==============================");

    const char* bimcode[] = {"Hard Reset", "Downloader Restart", "APP Start", "Bad APP Header", "Bad CRC"};

     Display_print1(dispHandle,0,0,"BIM VARIABLE:%d", _bim_var); // Value of _bim_var is 258 (Set in bootloader code previously)

    temp1=_bim_var-255; 

    Display_print1(dispHandle,0,0,"TEMP1:%s", temp1); // Value of temp1 printed as 3

    Display_print0(dispHandle,0,0,"Rest of the code");

    OUTPUT:

    ==============================

    BIM VARIABLE:258

    TEMP1:3

    Rest of the code

    Example 3

    -----------------

    uint32_t _bim_var;

    int temp1;

    Display_print0(dispHandle,0,0,"==============================");

    const char* bimcode[] = {"Hard Reset", "Downloader Restart", "APP Start", "Bad APP Header", "Bad CRC"};

     Display_print1(dispHandle,0,0,"BIM VARIABLE:%d", _bim_var); // Value of _bim_var is 258 (Set in bootloader code previously)

    temp1=_bim_var-255; 

    Display_print1(dispHandle,0,0,"TEMP1:%s", temp1); // Value of temp1 printed as 3

    Display_print1(dispHandle,0,0,"Down Loader:%s", bimcode[temp1]); // Code hangs indefinitely because of this line but if removed code works fine

    Display_print0(dispHandle,0,0,"Rest of the code");

    OUTPUT:

    ==============================

    Only the above line printed

    I cant figure out the issue. Why is this happening?

    Thanks,

    Roshini Radhakrishnan

  • Could you post the entire code snippet that causes this issue? I feel like there some context you're not showing here.
  • Hi Edvard,

    Thanks for your help and support. I figured out that my issue was due to compiler optimisation. It is set to level 4 (by default) to reduce code size. The code hangs if set to level 4 but is running successfully if optimisation level is set to 3 or below. I cant reduce optimisation level risking code size and therefore has to figure out another method for this above condition. 

    I think my issue is solved. Thanks for your help.

    Regards,

    Roshini Radhakrishnan.