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.
Hello, I'm running into an issue where my global and static variables are not initializing to the correct values.
For example, if I declare a variable at the top of a .c like :
unsigned long my_variable = 0x00000010UL;
when I view the variable from the debugger after performing one single step, so none of my other code has run, the variable has some random value. The same thing happens when I declare a static variable within a function. For example,
void MyFunction( void )
{
static unsigned long my_variable = 0x011F5C3UL;
.....
}
If I enter this function for the first time from the debugger, the variable has a random value. I'm using CCSv5 with the TI C/C++ compiler version 4.0.0. The target MCU is a MSP430F5529.
I urgently need help understanding this issue. Thanks in advance for your help.
The issue you are seeing may be related to the bug noted in this thread. Could you please check if that is the case?
http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/169308/706747.aspx#706747
If it is the same issue, you should be able to update to CCS 5.2.1.00018 and MSP430 CGT 4.1.1 to get the fix.
Hi,
I don't think my issue is related to this bug. I'm actually passing the variable to my PC via a USB protocol, and the value is still not what would be expected, so that should take the debugger out of the equation. This issue did seem to surface when I moved from CCSv4 to CCSv5, however. I noticed there are a couple of linker settings (RAM auto initialization or ROM auto initialization). Would either of these settings affect this?
Thanks
Are you sure MyFunction accurately reflects your real code? The local variable my_variable is not static. Because it is not static, there should be code in the function to initialize it with the given value. Could you post the generated assembly code for MyFunction, or perhaps the disassembly?
My mistake. I meant to declare it as static in the example. In the real code, it is static. Also, that wouldn't explain the issue with the global variable.
Accessviolation said:This issue did seem to surface when I moved from CCSv4 to CCSv5
So this all worked under CCSv4? The compiler has made no changes in how globals and statics are initialized since that time. So this suggests that the problem is something other than the compiler.
Accessviolation said:I noticed there are a couple of linker settings (RAM auto initialization or ROM auto initialization). Would either of these settings affect this?
Possibly. I recommend you read through the section titled System Initialization in the MSP430 compiler manual. Try to understand which parts of that are working correctly, and which are not.
Thanks and regards,
-George
I have had similar issues with the MSP430's debugger.
If I have a break point and hover my mouse over the value it will be completly off. Like 100% off. But if I put the value in the expressions window I see the correct value.
Have you tried looking at the value in the expressions window?
Is your project set for eabi output format or legacy COFF? This would be under Project Properties->CCS General->Advanced Settings.
It might be worth a shot to update your compiler tools to v4.1.1. Or if you're willing to install 5.2.1 along side your existing installation, that should come with compiler 4.1.1. If you want just the compiler update, you can get it by going to CCS menu Help->Install new software. Choose the "Code Generation Tools Updates" site and then from the list select the MSP430 Compiler Tools 4.1.1 and install it. After installation, set your project to use this new version and rebuild.
If the problem continues to persist after updating to latest compiler tools, we may need a small reproducible test case that we can use to recreate the behavior.
Ok. Well, I have the --rom_model enabled on the linker, so the _c_int00 function should automatically be linked into my project. According to the documentation that you pointed out, the _c_int00 function should:
It initializes global variables by copying the data from the initialization tables to the storage allocated for
the variables in the .bss section.
That doesn't seem to be happening.
Another suggestion ...
Create a new project that is very simple. It will have one source file that looks like ...
int is_ten = 10;
void main() {} // empty main
When you get to the start of main, is_ten should be 10. My guess is it won't be. But this small project will be a lot easier to debug.
Thanks and regards,
-George
Hi George,
Before I read your reply, I did the same thing. I created a new project from the Hello World template and initialized a global variable. When I got to the start of main, the variable was initialized correctly. So, I guess there is something wrong with my project. This issue only manifested itself after I moved from CCSv4 to CCSv5. Also, I attempted to install the updates to get to the latest compiler, but the update failed miserably and left my environment completely unusable. I had to reinstall CCSv5 from scratch. However, the problem still exists.
Thanks,
Steve
Additional information. I can see the correct value in the .cinit section of memory, but it does not appear to be copied into RAM.
Then this problem, whatever it is, probably lies outside the things the compiler influences. Perhaps the memory system is not initialized correctly?
Another suggestion ... Make the very simple project gradually more complex, until you see it fail. The idea is to catch the same failure, but in a simpler form. I'm not so sure this will work. But it is all I can think to suggest.
Thanks and regards,
-George
Hi George,
Yes, this is the approach I took, and was able to identify a static variable (an array of structures) that seemed to be causing the initialization corruption.I'm back in business now. This was a pretty subtle problem to find, which was causing very strange behavior.
Thanks,
Steve