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:变量启用 O-3优化时、意外更改了问题

Guru**** 2380860 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1483937/tms320f280039c-variable-unexpected-changed-issue-when-enabling-the-o-3-optimization

器件型号:TMS320F280039C

工具与软件:

变量 tPFC_ctrl.bit.OnOff 意外更改、该问题似乎与编译器优化级别 设置有关。
尝试:
1.为确保正确的数据共享,我们修改了变量定义。 具体来说、我们将以前的结构体和联合体格式替换为 uint16_t 类型的全局变量
但是、当启用 O-3优化时、变量 PfcCtrlOnOff 会继续更改。
2. volatile 关键字应用于全局变量,但问题仍然存在。
3.当编译器优化关闭时,变量保持不变,不会出现问题。
 
问题:
1.为什么启用 O-3优化会导致这个问题?  
2.是否有任何解决方案可以在不禁用编译器优化的情况下解决此问题?
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    当你说...

    [quote userid="645251" url="~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1483937/tms320f280039c-variable-unexpected-changed-issue-when-enabling-the-o-3-optimization tpFC_ctrl.bit.OnOff 变量意外更改

    ...我想你的意思是这个变量改变的值,有时,或以不同的方式,这与源代码不同。   

    我怀疑问题的根本原因,不管它是什么,始终存在。  不进行优化的构建会隐藏问题。  优化构建可以揭示问题。

    我想我可以帮助缩小调查范围。  确定一个正在运行的函数...

    [quote userid="645251" url="~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1483937/tms320f280039c-variable-unexpected-changed-issue-when-enabling-the-o-3-optimization tpFC_ctrl.bit.OnOff 变量意外更改

    ...发生。  有关包含此函数的源文件、 请按照 如何提交编译器测试用例一文中的说明进行操作。  预处理后、添加类似...的注释

    此处出现问题。  速度 这一点。  速度 基准电压。 */

    谢谢。此致、

    -George.