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.

FR5739 variables



Take example code MSP430FR57xx_FRAMWrite.c ,,, move "unsigned long data" from outside main() to inside main(){}

unsigned long data;
int main(void)
{
  data = 0x11111111;
}

The compiler is happy.

int main(void)
{
  unsigned long data;
  data = 0x11111111;
}

The compiler complains ... data is undefined.

  • 460822 said:
    The compiler complains ... data is undefined.

    I cannot reproduce that behavior.  I do get this diagnostic ...

    "file.c", line 3: warning: variable "data" was set but never used

    But that is to be expected.  The variable data is local to the function main.  Once main goes out of scope, so does data.  And within the scope of main, data is written, but it is never read.

    Thanks and regards,

    -George

  • This is a very strange problem.   I noticed all of the FRAM example code places the variable definitions outside of main().

    Are you using Code Composer 4?

  • I tested another variation.  I added six lines to the original code ... changed the code to:

    int main(void)
    {
      unsigned long x;
      unsigned long y;
        x = REFTCOFF;
        y = x + 1;
        data = x + 1;
        data = y + 2;

    It compiles fine. 

    The debugger goes to y = x + 1 on startup ... skips x = REFTCOFF. 

    x has the address "unknown register ID = 0xC" ... y has the address "unknown register ID = 0xE".   Both x and y = 0 ... although x should equal 8.

    Stepping to the next line results in x = 8 and y = 9 ... still at unknown registers. 

    Stepping to the next line results in x = 9, y = 9 ... still at unknown registers, and data = 9 at location 0xC204 which makes sense.

    Questions: 1) why are x and y placed at an unknown register?  2) why does the value of x change with the statement data = x + 1?

    Note that I am connected to an MSP-EXT430FR5739. 

  • I don't have any MSP boards.  And I have CCS 5.4, not CCS 4.  But I was able to create that same project, and I have a guess as to what is happening.

    The compiler builds with a default optimization level that is probably causing most of your confusion.  Statements get reordered, variables get assigned to registers, and the like.  You can disable all optimization by setting the compiler build option --opt_level=off.  Below I show a screen shot of what that looks like in CCS 5.4.  It is probably similar in CCS 4.

    Thanks and regards,

    -George

  • The attachment depicts my settings. 

  • I tried the same code using Code Composer 5 ... similar problem.  The value of x changes for the statement "data = x + 1".  I then tried by disabling optimization.  It work correctly.

    This is a serious problem.  Optimizing should not change the results for simple addition.

    Also, how does one disable optimization using Code Composer 4?

  • 460822 said:
    This is a serious problem.  Optimizing should not change the results for simple addition.

    No, it isn't a serious problem.  I think the best way to explain is by example.  Consider this code ...

    void contrived_example(int input)
    {
        int data = input + 1;
    }

    When you build that with optimization, the compiler will optimize that into an empty function.  Why?  Because data is a local variable.  The computation for data is not used anywhere else.  Eliminating the computation has no effect on the rest of the program.  Suppose you try to single step through this function.  That is going to be a bit awkward.  There is no code which corresponds to the data statement.

    Your code is more complicated, but the principle still applies.  Since data is a local variable that is not referred to elsewhere, computations regarding it can be removed.  That makes single stepping those statements a bit confusing.

    460822 said:
    how does one disable optimization using Code Composer 4?

    Highlight Basic Options, and you'll see the drop-down box for optimization level.

    Thanks and regards,

    -George

  • For debugging, it can be a serious problem.  On occasion I capture a value or register prior to some action and then view it later.  Values should not be changed by Code Composer for debugging.

    In my case, I was trying to determine the location of the variables ... in FRAM or RAM ... and finding a way to assign variable names to the FRAM Info section.  The optimization wasted a lot of my time.

    For disabling Code Composer 4 optimization ... the sequence I followed is left click Project name -> Properties -> C/C++ Build (list) -> Tool Settings (tab) -> Msp430 Compiler (list box) -> Basic Options -> Optimization level. 

    Hovering the mouse over the combo box displays the options.  None of the options listed includes "no optimization". 

  • Hi,

    in ccsv4 you disable optimization by going to project->properties->C/C++ Build.  Then to the right to to Basic Options under the msp430 Compiler.   See the attached screen capture.  You need to set the optimization level to blank which is above 0.

    Best Regards,

    Lisa