WDT示例

源码路径:example/rt_device/wdt/wdt

支持的平台

  • em-lb525

  • em-lb587

概述

本例程演示基于rt-device(使用rt-thread)的WDT使用,包含:

  • WDT开关。

  • WDT喂狗。

  • WDT超时响应。

小技巧

本例程基于HCPU,使用到IWDT和WDT1。

例程的使用

硬件需求

运行该例程前,需要准备一块本例程支持的开发板

编译和烧录

切换到例程project目录,运行scons命令执行编译:

scons --board=eh-lb525 -j32

运行build_em-lb525_hcpu\uart_download.bat,按提示选择端口即可进行下载:

$ ./uart_download.bat

     Uart Download

please input the serial port num:5

关于编译、下载的详细步骤,请参考上手指南的相关介绍。

例程的预期结果

例程启动后,串口输出如下:

  1. WDT关闭再打开:

11-01 11:05:24:772    WDT Example.
11-01 11:05:24:813    WDT off.
11-01 11:05:24:816    WDT on.

小技巧

使用rt-thread时,WDT初始化配置、使能(rt_hw_watchdog_init)已经在启动流程中默认完成,不需要再单独调用初始化配置和使能。

  1. 取消idle线程中的喂狗:

11-01 11:05:24:820    Unregister idle hook.

小技巧

rt_hw_watchdog_init中注册了idle hook,用于喂狗。这里取消,用于示例主动喂狗。

  1. 喂狗(每5秒):

11-01 11:05:29:709    watchdog feeding.
11-01 11:05:34:699    watchdog feeding.
11-01 11:05:39:668    watchdog feeding.
11-01 11:05:44:660    watchdog feeding.
11-01 11:05:49:629    watchdog feeding.
11-01 11:05:54:600    watchdog feeding.
11-01 11:05:59:594    watchdog feeding.
11-01 11:06:04:575    watchdog feeding.
11-01 11:06:09:558    watchdog feeding.
11-01 11:06:14:553    watchdog feeding.
  1. 停止喂狗后,WDT1超时(WDT_TIMEOUT, menuconfig中配置),产生中断。中断中(WDT_IRQHandler)会将WDT1/WDT2关闭,刷新IWDT,更新IWDT超时时间(WDT_TIMEOUT):

11-01 11:06:14:557    Stop watchdog feeding.
11-01 11:06:51:813    WDT1 timeout occurs.
11-01 11:06:51:817    WDT reconfig:
11-01 11:06:51:821      WDT1 and WDT2 has been stopped.
11-01 11:06:51:825      IWDT refreshed and set timeout time to WDT_TIMEOUT.

小技巧

提供了可复写函数:wdt_store_exception_information,wdt_store_exception_information被WDT_IRQHandler调用。可以用来保存现场、reboot系统等。

  1. IWDT超时复位系统:

11-01 11:07:35:237    SFBL
11-01 11:07:37:445    Serial:c2,Chip:4,Package:3,Rev:2  Reason:00000000

异常诊断

  1. 通过WDT寄存器确认WDT配置状态(使能状态、计数配置、工作模式): WDT regmap

参考文档

更新记录

版本

日期

发布说明

0.0.1

10/2024

初始版本