- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A further note, making the variable volatile does not help, weird.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Moreover, you might want to take a look at this Application Note on PSoC 3 - 8051 code Optimization.