6

RP2040(树莓派Pico) 看门狗

 3 years ago
source link: https://www.taterli.com/7559/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

RP2040(树莓派Pico) 看门狗

这个芯片内置看门狗,但是只是最基础的看门狗,不过RP2040的很多外设都是很基础的配置,按照手册来说,他可以定时范围从你绝对喂不上狗(1个WDG周期)到16秒左右,但是根据SDK限制,你最短是50ms,最长是8秒,为什么8秒?又是一个芯片设计BUG…

如果因为看门狗功能导致复位,上电后可以通过watchdog_caused_reboot判断复位源,通过watchdog_enable进行参数初始化,可以选择是否在DEBUG模式暂停,但是低功耗模式所有时钟都停了的时候他也不例外,通过定期的watchdog_update喂狗,可以不被狗咬,没有中断功能,也没有窗口喂狗的能力,所以我认为这个大概是史上最简单的外设了.


int main() {
    stdio_init_all();

    if (watchdog_caused_reboot()) {
        printf("Rebooted by Watchdog!\n");
        return 0;
    } else {
        printf("Clean boot\n");
    }

    // Enable the watchdog, requiring the watchdog to be updated every 100ms or the chip will reboot
    // second arg is pause on debug which means the watchdog will pause when stepping through code
    watchdog_enable(100, 1);

    for (uint i = 0; i < 5; i++) {
        printf("Updating watchdog %d\n", i);
        watchdog_update();
    }

    // Wait in an infinite loop and don't update the watchdog so it reboots us
    printf("Waiting to be rebooted by watchdog\n");
    while(1);
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK