PSoc creator has an issue where so-called unused variables are optimized out despite the fact they are written to more than once. C compilers are not supposed to do this. Is there something I can do without having to turn off optimization?
It doesn't matter how often you write to a variable - when you never read from it, it is unused and compiler can optimize if. The same is true for all writes except the last one - they are useless and will be optimized out.
So when you want to see, during debugging, the value, make sure you use the variable somewhere later on.
In Creator under
Project -> Build Settings -> Compiler
you'll find options to set optimization levels depending on the chip you use PSoC3 or 5. I would suggest to minimize the optimization for the debugging build and maximize them for the release.
Precaution, keep in mind SW based timing loops can be affected by
optimization settings, so be diligent. At minimum look at .lst file before
and after. Or convert them to HW, or hard code them in ASM if in doubt.
As per KEIL's KB article on various Optimization levels, unused code fragments are getting eliminated if set to level 1 or above. So, if you really want to keep a variable undeleted eventhough you are not going to use it anywhere, you might want to set the Optimization level to 0 and try it out.