本文介绍了在调试期间禁用 STM32 IWDG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 STM32F4 微控制器上有一个 ChibiOS 3.x 程序,我使用 IWDG 看门狗在出现这样的错误时重置 MCU:

I have a ChibiOS 3.x program on a STM32F4 microcontroller where I use the IWDG watchdog to reset the MCU on errors like this:

int main() {
    iwdgInit();
    iwdgStart(&IWDGD, &wd_cfg);
    while(true) {
        // ... do stuff
    }
}

如果我现在连接调试器并在任何时候停止程序(手动或通过断点),微控制器将在看门狗配置定义的超时后重置(因此会导致调试过程中出现问题)

If I now attach my debugger and, at any point, stop the program (manually or via a breakpoint), the microcontroller will reset after the timeout defined by the watchdog configuration (and therefore cause issues in my debugging process)

如何禁用此行为,即如何在内核因调试器而停止时禁用 IWDG?

How can I disable this behaviour, i.e. how can I disable the IWDG while the core is stopped due to the debugger?

我已尝试完全禁用它,但是,我需要让它继续运行以捕获不需要的 IWDG 重置.

I have tried disabling it entirely, however, I need to leave it running to catch unwanted IWDG resets.

推荐答案

STM32 MCU 包含一项称为调试冻结的功能.您可以停止多个外设,包括 I2C 超时、RTC,当然还有看门狗.

The STM32 MCUs contain a feature called debug freeze. You can stop several peripherals, including I2C timeouts, the RTC and, of course, the watchdog.

STM32 参考手册,请参阅第 38.16.4ff 节MCU 调试组件 (DBGMCU)".

In the STM32 reference manual, refer to section 38.16.4ff "MCU debug component (DBGMCU)".

IWDG 在 APB1 总线上运行.因此,您需要修改DBGMCU_APB1_FZ,特别是该寄存器中的位DBG_IWDG_STOP.

The IWDG is running on the APB1 bus. Therefore you need to modify DBGMCU_APB1_FZ, most specifically assert the bit DBG_IWDG_STOP in that register.

该寄存器的 POR 值(= 默认值)为 0x0,即如果您不主动禁用它,IWDG 仍将运行.

The POR value (= default value) for this register is 0x0, i.e. if you not actively disable it, the IWDG will still be running.

int main() {
    // Disable IWDG if core is halted
    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_IWDG_STOP;
    // Now we can enable the IWDG
    iwdgInit();
    iwdgStart(&IWDGD, &wd_cfg);
    // [...]
}

请注意,当未在软件中启用看门狗时,如果在闪存选项字节中重置 WDG_SW 位,则它可能仍会在硬件中启用.

Note that when not enabling the watchdog in software, it might still be enabled in hardware if the WDG_SW bit is reset in the flash option bytes.

如果您使用的是 ST HAL(未包含在 ChibiOS 中,请参阅 STM32CubeF4),你也可以使用这个宏:

If you are using the ST HAL (not included in ChibiOS, see STM32CubeF4), you can also use this macro:

 __HAL_DBGMCU_FREEZE_IWDG();

(基本上和我们上面做的完全一样)

(which basically does exactly the same as we did above)

此外,在调用__HAL_DBGMCU_FREEZE_IWDG()之前,您需要在APB2上启用DBGMCU时钟.

Besides, you need enable the DBGMCU clock on APB2 before calling __HAL_DBGMCU_FREEZE_IWDG().

 __HAL_RCC_DBGMCU_CLK_ENABLE();

这篇关于在调试期间禁用 STM32 IWDG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:38