Optimization problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Optimization problem

跳至解决方案
2,457 次查看
neuzzo
Contributor II

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?

标签 (1)
标记 (1)
1 解答
1,781 次查看
MJW
NXP Employee
NXP Employee

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

在原帖中查看解决方案

4 回复数
1,782 次查看
MJW
NXP Employee
NXP Employee

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

1,781 次查看
TICS_Fiona
NXP Employee
NXP Employee

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!

-----------------------------------------------------------------------------------------------------------------------

1,781 次查看
neuzzo
Contributor II

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.

0 项奖励
回复
1,781 次查看
TICS_Fiona
NXP Employee
NXP Employee

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:

  1. www.freescale.com/cwmcu10

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!

-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复