I'm having a hard time to figure out what is wrong with my code. My code is spread into one common area and additional 4 banks. I have some global variables, mainly structs, that are used throughout the application. These variables are filled with default values that are stored as code variables when the program runs for the first time(after JTAG programming). I have a small keyboard and display so I can check the values and navigate through menus.
The problem showed up after I added some more code to the application, but nothing connected to the variables themselves.
These variables are not being overlapped, the memory map shows it (I've tried NOOL directive just to be sure and nothing). The interrupts do not change by any way these variables.
The funny thing is that depending on which level of the menu I am I get either the correct values or the default values. It seems that for some reason the address of the variable is changed and pointed to the default values(code area) or the real values(ram area). If I force the variables to be placed on a certain memory place using the _at_ command they don't get corrupted but the ones that were not corrupted get corrupted instead. If they were filled up with garbage I think it would be easier to say that they were getting overwritten by some other thing but they are not getting garbage, they are getting filled up with the default values stored in code area.
Was I too vague?
Variable corruption
OK, I finally discovered the problem.
I created a new struct that uses another struct inside. The problem was that the declaration of the new struct was placed before the other.
Something like this:
struct VarA { struct VarB[16]; unsigned char varC; unsigned char varD; }; struct VarB { unsigned char varC[30]; unsigned char varD; };
The compiler didn't complain about not understanding struct VarB, and I think it should! Looking at the listings of the project it was clear that not enough memory were being reserved. So that's how I figured it out. The variable that was clearly getting overwritten was adjacent to the one that was type VarA.
The strange thing is that it was not garbage that was being written but the default values I mentioned earlier. I wish one day I will understand...
The compiler didn't complain about not understanding struct VarB,
which version?