Inconsistent global variables!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inconsistent global variables!

5,425 Views
sparcz
Contributor I

Building a product based on the HCS12NE64, and have problems with a very strange behaviour in the compiler. I have some global variables and an assignment of these. The upper screenshot show how it looks without assignment. This works fine.

In the lower screenshot I have uncommented the assignment. Here the assignment SHOULD occurr AFTER the call to the "MENU_GotoNode" method. When the execution reaches the top of the "MENU_GotoSuccessNode" the assignment has allready occurred!!! This messes up the parameter I use in the "MENU_GotoNode" call.

In the pictures attached I also show the "MENU_GotoFailNode" method. It is not enough to comment out the assignments in one method, I have to do it in BOTH!!! Even though the "MENU_GotoFailNode" is never used!!!

What is causing this? I have a similar problem in the Processor expert bean for  the I2C-bus!

Best regards / Sparcz

 

support1.jpg

Message Edited by t.dowe on 2009-10-20 11:50 PM
Labels (1)
0 Kudos
Reply
6 Replies

1,766 Views
alex_spotw
Contributor III
Hi:

It would be nice to know the variable types, to have a better idea of what is the problem.

Memory corruption usually comes from usign arrays over the the max size of the array, or in the CodeWarrior Case, by using the wrong types in the function calls (for example, if you define a function parameter as int, but pass a byte variable (without casting). Other source of problems for memory corruption is not declaring the functions (Implicit fuction declaration). We've found that the programs always fails if the functions are not declared.

To verify this, check if your compiler is giving you Warnings in the lines MENU_GotoNode() function, or in other places. As a norm, you should not have any warning.

Also, enable in the options the "Error on Implicit fucntion declaration", because this will provent many headaches.

Check also that functions using the the array mnuArr variable don't exceed the array size (27).

Regards,

Alex
0 Kudos
Reply

1,766 Views
sparcz
Contributor I
The variables are declared in the .h-file as:

extern volatile byte MENU_CurrentNode;
extern volatile byte miFailNode;
extern volatile byte miFailMessage;
extern volatile byte miSuccessNode;
extern volatile byte miTimerID

and defined in the .c-file as:

volatile byte miFailNode;
volatile byte miFailMessage;
volatile byte miSuccessNode;
volatile byte miTimerID;
volatile byte MENU_CurrentNode;

They used to be part of a struct, but I have messed around a lot to test ALL possibilities.

regards
0 Kudos
Reply

1,766 Views
sparcz
Contributor I
Thanks for your input, but I found the problem. The error was due to UNBELIEVABLE STUPIDITY by me. I really have to reconcider my choice of carreer as a programmer. Hmm, wander if gardening is my thing? The spring is comming on here in Sweden, it might be the best time! :smileywink:
0 Kudos
Reply

1,766 Views
alex_spotw
Contributor III
Hi:

Please let us know what was the problem, so that we all learn...

Regards,

Alex
0 Kudos
Reply

1,766 Views
sparcz
Contributor I
Uhm, quite embarrasing actually! The method setting the global variables was actually called with the method "MENU_GotoNode", so when it returned the same variables was reset by the assignments mentioned above. I thought that the setting method was called from elsewhere... DUH!

At least I learnt from your feedback, I thank you for that.

/Sparcz
0 Kudos
Reply

1,766 Views
CrasyCat
Specialist III

Hello

For this one I would suggest you to issue a service request through the Freescale on line support web page.

Go to http://www.freescale.com/webapp/sps/site/homepage.jsp?nodeId=054670&tid=FSH

Log in using your Freescale WebApps login and password (if you do not have one register using the Register button on the top of the page) and click on Submit a service Request.

Make sure to attach a zip file containing the whole project reproducing the trouble  and to indicate which version of the tools and which option you are using to build the application.

CrasyCat

0 Kudos
Reply