Announcements
IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Anonymous
Not applicable

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?

0 Likes
6 Replies
Anonymous
Not applicable

A further note, making the variable volatile does not help, weird.

0 Likes
HeLi_263931
Honored Contributor II

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.

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
ETRO_SSN583
Esteemed Contributor

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.

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

 Moreover, you might want to take a look at this Application Note on PSoC 3 - 8051 code Optimization.

0 Likes