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.

Creating MSP430 FRAM Variables Using IAR

On this wiki: http://processors.wiki.ti.com/index.php/Creating_MSP430_FRAM_Variables_Using_CCS I can see how to define FRAM space variables while using CCS. What if I am using IAR? How is the same definition taken care of? Thanks!

  • Placement of variables in memory is a linker job. The linekr scripts define where there is space for variables and where code goes. These scripts are linker specific and are not portable.

  • Here is a piece of code that works in CCS:

    #pragma DATA_SECTION(VarName, ".fram_vars")
    unsigned int VarName;

    IAR doesn't like this line of code so there must be a way in which IAR handles this kind of definition, but I can't find it anywhere in the web. That's what I am asking to learn. Thanks!

  • Jose,

    i think this other wiki page i just made should be able to help:

    http://processors.wiki.ti.com/index.php/Placing_Variables_in_Specific_Memory_Location_-_MSP430

    I was also the one made the FRAM variable wiki above. I might try to update this for IAR if i would have time.

  • Hi Leo,

    Thanks! With this information I was able to move ahead!

    Best regards,

    Jose Quinones

  • Hello to all,

    I have the same problem in using FRAM.

    Following the suggested wiki page I wrote

    char Data[100] @ 0xCCFE;

    to initialize an array of 100 elements starting from the CCFE address.

    The compiler fails and returns this error message  

    Error[Be022]: location address not allowed for initialized variables (writable variables without the __no_init attribute) D:\Lavoro\Smart Watch\IAR\MSP430FR57 I2C NFC\NFC_I2C_Test.c 13

    What am I doing wrong?

  • Danilo Porcarelli said:
    What am I doing wrong?

    You're not listening to the compiler.

    The error message tells you what's wrong: initialized variables (including those which are initialized to 0 implicitly) may only be placed into the section for initialized variables. (unless they are const and therefore read-only and don't need to be re-initialized on each start) Or else the startup code cannot initialize/clear them.

    The solution is also there: to make the array non-initialized (and allow it to be placed anywhere in memory) you must add the __no_init attribute. And clear the array manually in your code later, if you need it to be cleared.

  • put "const" in the front of it and you should be good.

    QUESTION: On FRAM, the size of each address is 1 byte.  I need to store 500, 1 byte values in an array.  How do I define that the array are the values in these 500addresses.  I need to be able to send all 500 values over UDP on the CC3000 all at once, so I need to call all the values at once.

    Is this possible?

  • That's right! :-)

    Thank you for yor help.

    Now, I have another important question: is it possible to initialize variables in FRAM using IAR? 

    It seems (from the .xcl file) that variables can be initialized only in RAM, while FRAM can be used for constant or no_init variables.

    Can someone confirm that?

  • Preemptive Disclaimer: I am not super familiar with the FR devices...

    Danilo Porcarelli said:
    Now, I have another important question: is it possible to initialize variables in FRAM using IAR?

    Not out of the box. The issue is that IAR has no way of knowing in advance (before main() is called) as to whether the FRAM timing needs to be adjusted in order to perform the writes.

    Theoretically, if you could guarantee that the default power-on values for the timing and for the CPU clock speed would always be ok, then you could change the linker file and carve out a chunk of FRAM as it's own segment and tell the linker that this section is RAM. I would check also that the MPU is in the correct state for this after a PUC.

    That's my take...

  • Danilo Porcarelli said:
    Now, I have another important question: is it possible to initialize variables in FRAM using IAR? 

    It depends on what you want to do. If you want to place all your variables in FRAM and want the normal initialization code run every time you activate your device, you can simple place the DATA16_Z and DATA16_I segments in the FRAM area. Unfortunately, there is no support for placing some initialized variables in RAM and some in FRAM.

    On the other hand, if you want to initialize a variable once when the application is first downloaded, you can use the __persistent keyword. Note that once you have modified the variable, it will keep it's now value even if you torn your device off and then on again.

        -- Anders Lindgren, IAR Systems

  • Brian Boorman said:
    IAR has no way of knowing in advance (before main() is called) as to whether the FRAM timing needs to be adjusted in order to perform the writes.

    Why should it? In order to execute the code, FRAM timing must be okay, because every read is a write. Including instruction reads.
    So I don’t see why it shouldn’t be safe to assume that if the code executes, the writing of the init values will be successful too with the current settings.

**Attention** This is a public forum