I have a problem with this code when activate optimization:
inside main i have this cycle, that waiting a trigger of interrupt to proceed:
for(;;)
{
WaitTrigger();
..
...
}
void WaitTrigger(void)
{
while (!appTrigger)
;
appTrigger = FALSE;
}
and appTrigger is forced TRUE by interrupt.
with -O0 working fine, but if I insert -O1 stop work.
I can disable the optimization in this area, or other idea to enable the optimization?
Solved! Go to Solution.
Hello,
make sure you declared all variables shared between main application code and an ISR as "volatile", e.g. like this:
volatile unsigned int appTrigger;
Short explanation: "volatile" tells the compiler to not make any assumptions about the content of the variable. That is essential for all variables that are used in a (for the compiler) non-deterministic way (i.e. ISR).
HTH,
MJW
Hello,
make sure you declared all variables shared between main application code and an ISR as "volatile", e.g. like this:
volatile unsigned int appTrigger;
Short explanation: "volatile" tells the compiler to not make any assumptions about the content of the variable. That is essential for all variables that are used in a (for the compiler) non-deterministic way (i.e. ISR).
HTH,
MJW
Hello Riccardo
To workaround the problem, you may use compiler pragma to disable the optimization locally for this ISR.
To dig into the problem, we need to know the CodeWarrior version you're using.
For Classic CodeWarrior, please:
1)Start the IDE and click on Help | About Freescale(Metrowerks) CodeWarrior.
2)Click on Installed Products
3)Provide us all info displayed. Or you can save them in a txt file.
For Eclipse CodeWarrior, please:
1)Start the IDE and click on Help | About CodeWarrior Development Studio.
2)Provide us the info displayed.
And an example project will be greatly appreciated.
Best Regards
Fiona Kuang
Technical Information & Commercial Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Dear Fiona,
thanks for the replay.
The CodeWarrior version is 10.6,
The MCU used are MKE02Z64.
I have create the grid of software with PE.
Hello neuzzo
CodeWarrior v10.6 is an old version, please upgrade to CW10.6.6.
Please first install CW10.6.4 which can be downloaded from:
Its update v10.6.5 and v10.6.6 are also available at the same link.
Further information and the release notes are available on the following Freescale community page:
https://community.freescale.com/docs/DOC-143655
To workaround the problem, you may use compiler pragma to disable the optimization locally for this ISR. For GCC compiler, it should be :
#pragma GCC optimize ("O0")
For details, please refer to the link below:
http://stackoverflow.com/questions/2219829/how-to-prevent-gcc-optimizing-some-statements-in-c
Hope this helps!
Best Regards
Fiona Kuang
Technical Information & Commercial Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------