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.

[参考译文] MSP430G2553-Q1:当优化大于1时、LOOP 挂起

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1193147/msp430g2553-q1-while-loop-hangs-with-optimization-greater-than-1

器件型号:MSP430G2553-Q1

此问题适用于最新的 CCS 版本。 我有一个例程会延迟可调的毫秒计数。 ISR 每 ms 递增一次 MsCount。 以下 c 代码等待 mSDuration ms 后再返回:

// c 代码例程等待设定的 ms 计数
//计时器 ISR 每 ms 递增一次 MxCount
WaitTimer = MsCount;//初始化计数
//当 MsCount 增长到超过等待时间的 mSDuration 时,等待就会结束
while ((MsCount - WaitTimer)< mSDuration);

此延迟适用于优化级别1:以下是针对优化级别1的反汇编。 代码将 MsCount 加载到 R15 (e1be)、然后减去 WaitTimer (e1c2)并将结果与 mSDuration (e1c6)进行比较。

171 WaitTimer = MsCount;
e1b8:4292 02F4 02E6 MOV.W &MsCount、&WaitTimer
172 while ((MsCount - WaitTimer)< mSDuration)
$C$L2:
e1be:421F 02F4 MOV.W &MsCount、R15
e1c2:821F 02E6 sub.W WaitTimer、R15
e1c6:912F CMP.W @SP、R15
e1c8:2BFA JLo ($C$L2)

优化2跳过减法、R15永不改变。 while 循环被卡住。
171 WaitTimer = MsCount;
e12e:4292 02F4 02E6 MOV.W MsCount、WaitTimer
E134:430F CLR.W R15
172 while ((MsCount - WaitTimer)< mSDuration);
$C$L2:
E136:912F CMP.W @SP、R15
E138:2BFE JLO ($C$L2)

优化为何会排除基本步骤? 有什么建议吗?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="45931" URL"~/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1193147/msp430g2553-q1-while-loop-hangs-with-optimization-greater-than-1 "/>计时器 ISR 会每毫秒递增 MxCount [/quot]

    MxCount 是否声明为易失性?

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

    我以为我曾尝试将所有涉及的变量声明为易变变量、但我再次尝试了它。 WaitTimer 在例程之前声明、并声明它 为易失性、从而解决了问题。 声明其他两个变量为易失性并不会产生影响。  

    感谢您的评论!