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.

CCSv6 with GNU v4.9.1 ignores variable initialization

Other Parts Discussed in Thread: MSP430G2553

Hey guys,

I just installed CCS v6.0.1.00040 and chose to install the latest GNU GCC compiler for the msp430 during the installation setup. Version GNU v4.9.1 was installed. I'm using a MSP430-EXP430G2 Rev 1.4 Launchpad with a MSP430G2553. 

I used a project which worked perfectly with the TI compiler and then switched to the GNU compiler. Compiling works like a charm, but I discovered something very interesting: the global variables are not initialized as written in the code.

More specifically, there are two global variables:

unsigned char matching=1;
volatile char ads_reset=1;

Compiling with the TI compiler sets both variables to 1(checked in "Expressions" window in Debug mode before running the program), whereas using the GNU v4.9.1 sets only ads_reset to 1 and matching is 0. Sometimes ads_reset is set to 67, I couldn't think of any reason why that happened. 

I also tried the GNU v4.8.0 (Red Hat) compiler which works just fine, no problems there. Can you think of any reason for this problem?

Andreas

  • I apologize for the delay.

    Andreas Brunner said:
    using the GNU v4.9.1 sets only ads_reset to 1 and matching is 0

    Unfortunately, that version information is not precise enough.  There are versions of 4.9.1 tools where the accompanying linker command files have an error that causes problems with variable initialization.  You have to run this command to see full version information: msp430-elf-gcc --version.

    This version is OK ...

    % msp430-elf-gcc --version
    msp430-elf-gcc (GCC) 4.9.1 20140707 (prerelease (msp430-14r1-10)) (GNUPro 14r1) (Based on: GCC 4.8 GDB 7.7 Binutils 2.24 Newlib 2.1)
    Copyright (C) 2014 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    This version has the problem ...

    $ ./msp430-elf-gcc --version
    msp430-elf-gcc.exe (GCC) 4.9.1 20140707 (prerelease (msp430-14r1-98)) (GNUPro 14r1) (Based on: GCC 4.8 GDB 7.7 Binutils 2.24 Newlib 2.1)
    Copyright (C) 2014 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    Which one do you have?

    Thanks and regards,

    -George

  • Hi George,

    thanks for the reply. My version is:

    msp430-elf-gcc (GCC) 4.9.1 20140707 (prerelease (msp430-14r1-98)) (GNUPro 1
    (Based on: GCC 4.8 GDB 7.7 Binutils 2.24 Newlib 2.1)
    Copyright (C) 2014 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    I used v4.8.0. in the meantime, but it would be great to update to the working version. Can you tell me how to get it?

    Andreas

  • Andreas Brunner said:
    it would be great to update to the working version. Can you tell me how to get it?

    You are currently using the latest version.  You may wish to get the previous version, which does not have the problem I describe.  That is available here.  Please remember that it is only an educated guess that this version will fix your problem.  I might be wrong.

    Thanks and regards,

    -George

  • Hi George,
    Thank for your sincere reply.

    I have been experiencing a similar problem that has driven me mad.

    When using the msp430-14r1-98 and CCS with the linker script it generates, global variables are correctly initialized when debugging, but not when the debugger is detached. I noticed that the reason for this is that in the linker script generated by CCS for this compiler, the .data section placement is specified as " > RAM", whereas before, in the older version the placement was " > RAM AT > ROM", in order to store the variables in ram and their initial values in ROM, as should be. So apparently then, the initialized global variables are setup to their values by the debugger when loading or reseting the program, but when the debugger is detached, they are not properly initialized because no initialization code is linked.

    However if I try to fix this by changing this in the linker script, now the problem is even worst, the global variables are also corrupted when loading the code in the debugger, so clearly there was quite a good reason to remove the "AT > ROM" from the linker script.

    The problem get very nasty when I import a project that I have been developing with the prior msp430-14r1-10, which worked fine. The .ld file generated with that version has the " > RAM AT > ROM" placement specification for the .local section, so when I compile it with msp430-14r1-98, it goes crazy.

    I am very grateful for the MSP GCC effort contributed by TI and Redhat, but I think this bug is quite serious and should at the least be clearly stated in the "known issues", if, as it seems, it is known.

    Do you know if there is there any plan to launch soon a new revision that fix this bug ? Can we help, at least with some testing, in the development?

    Thanks and regards,

    Jose

    PD: Andreas, I recommend you to return to (or install) msp430-14r1-10 compiler as George suggests. You have to install the compiler and then edit the project option to compile with that version (go to properties --> general --> compiler version --> more... -> select new built tool from filesystem" and selects the folder where you installed the previous compiler version ("c:\ti\gcc" by default), and then clean and rebuild the project.