This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280039C: variable unexpected changed issue when enabling the O-3 optimization

Part Number: TMS320F280039C


Tool/software:

The variable tPFC_Ctrl.Bit.OnOff is unexpected changed, and this issue seems to be related to the compiler optimization level settings.
Our Try:
1. In an effort to ensure correct data sharing, we have modified the variable definitions. Specifically, we replaced the previous struct and union format with global variables of type uint16_t.
However, the variable PfcCtrlOnOff continues to be altered when the O-3 optimization is enabled.
2. The volatile keyword was applied to the global variable, but the problem still exists.
3. When the compiler optimization is turned off, the variable remains unchanged and the issue does not occur.
 
Question:
1. Why does enabling the O-3 optimization cause this issue? 
2. Are there any solutions to resolve this problem without disabling the compiler optimization?
  • When you say ...

    The variable tPFC_Ctrl.Bit.OnOff is unexpected changed

    ... I presume you mean this variable changes value at times, or in ways, that are different from the source code.  

    I suspect the root cause of the problem, whatever it is, is present all the time.  Building without optimization hides the problem.  Building with optimization reveals the problem.

    I think I can help narrow the scope of the investigation.  Identify one function that is running when this ...

    The variable tPFC_Ctrl.Bit.OnOff is unexpected changed

    ... happens.  For the source file that contains this function, please follow the directions in the article How to Submit a Compiler Test Case.  After preprocessing, add a comment similar to ...

    /* Problem occurs here.  Behavior <something> is expected.  Behavior <something else> is seen instead. */

    Thanks and regards,

    -George