debugging - UART 代码端口后的 TI MSP430 中断问题

标签 debugging embedded interrupt msp430 iar

我将 MSP430F2013 处理器用于没有 UART 的应用程序。我需要一个 UART,因此我使用了 TI 的示例代码“msp430x20x3_ta_uart2400.c”来模拟一个使用 Timer 模块的代码。这一切都很好(使用 IAR Embedded Workbench 编译),使用 PuTTY 将字符传输到开发板并使用环回将它们回显到终端对其进行了测试。

这是一个降低风险的练习,现在我已经将该代码移植到我的应用程序的状态机中。完成此操作后,我遇到了有关定时器中断和低功耗 sleep 模式的问题。这是我进入低功耗( sleep )模式的代码片段:

// Prepare the UART to receive one byte.
prepare_receiver();

// Enter low power mode 1.
__bis_SR_register(LPM1_bits + GIE);

// Check whether the full message has been received.
if(true == get_message_complete())
{
    process_event(e_euart_message_received, NULL);
}

我在调试器 (C-Spy) 上看到的是有时它会执行 bis_SR_register()第一个条目的行,然后转到 if声明,即忽略我已要求它进入休眠的事实。在其他情况下,当它应该进入休眠状态时,ISR 会正确触发并最终将我带回到 if。继续执行程序的语句(如我所料)。但是,如果我尝试进入下一条语句,应用程序会在第一行卡住,即我无法前进。

我想不出与我正在做的 TI 示例在功能上有何不同,所以我认为我的问题一定与我如何移植它有关。例如,我的 Timer ISR 和我在此处发布的代码位于不同的编译单元中 - 这种决定会对事情产生任何影响吗?我知道我的问题可能有点含糊,但不幸的是我不能发布我的所有代码,所以我正在寻找具有 MSP 经验的人,他可能能够提出一些值得关注的事情或一些潜在的陷阱我可能陷入了。

最佳答案

在低功耗模式下使用 C-Spy 调试中断会很棘手。根据Section A.3 Debugging (C-Spy) - IAR User's Guide :

5) C-SPY can debug applications that utilize interrupts and low power modes



但是您应该注意一些“陷阱”,这可能会导致您的头痛。

尤其:

14) When C-SPY has control of the device, the CPU is ON (that is, it is not in low-power mode) regardless of the settings of the low-power mode bits in the status register. Any low-power mode conditions are restored prior to Step or Go. Consequently, do not measure the power consumed by the device while C-SPY has control of the device. Instead, run your application using Go with JTAG released

19) C-SPY utilizes the system clock to control the device during debugging. Therefore, device counters, etc., that are clocked by the Main System Clock (MCLK) are affected when C-SPY has control of the device. Special precautions are taken to minimize the effect upon the Watchdog Timer. The CPU core registers are preserved. All other clock sources (SMCLK, ACLK) and peripherals continue to operate normally during emulation. In other words, the Flash Emulation Tool is a partially intrusive tool.

Devices that support clock control (Emulator → Advanced → Clock Control) can further minimize these effects by selecting to stop the clock(s) during debugging

24) Peripheral bits that are cleared when read during normal program execution (that is, interrupt flags) are cleared when read while being debugged (that is, memory dump, peripheral registers).

When using certain MSP430 devices (such as MSP430F15x, MSP430F16x, MSP430F43x, and MSP430F44x devices), bits do not behave this way (that is, the bits are not cleared by C-SPY read operations).

26) While single stepping with active and enabled interrupts, it can appear that only the interrupt service routine (ISR) is active (that is, the non-ISR code never appears to execute, and the single step operation always stops on the first line of the ISR). However, this behavior is correct because the device always processes an active and enabled interrupt before processing non-ISR (that is, mainline) code. A workaround for this behavior is, while within the ISR, to disable the GIE bit on the stack so that interrupts are disabled after exiting the ISR. This permits the non-ISR code to be debugged (but without interrupts). Interrupts can later be reenabled by setting GIE in the status register in the Register window.

On devices with the clock control emulation feature, it may be possible to suspend a clock between single steps and delay an interrupt request (Emulator → Advanced → Clock Control).



要尝试的一件事是注释掉所有低功耗代码并查看您的 UART 代码是否可以这样工作。然后返回并尝试重新启用低功耗模式。

关于debugging - UART 代码端口后的 TI MSP430 中断问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12463875/

相关文章:

c - 多线程中堆栈和调用堆栈的区别?

interrupt - STM32f0 是否可以在 DMA 完成一半时获得中断

c - 操作系统: Isn't it a wrong practice to switch to another process with the interrupt blocked?

java - 使用 Hashmap 调试 foreach 时出错

macos - 如何在 Mac OS X 上调试 .app 包启动时崩溃?

debugging - 预期的行为?除在 Debug模式下外,MATLAB会忽略反序列化时的错误

java - tomcat上的 "remote debugging"是什么?

c++ - 修复了带引用的内存布局同步变量

linux-kernel - 被抢占的中断处理程序会发生什么?

c++ - 用于在已编译程序中进行数据操作的嵌入式 C++ 解释器