查看: 552|回复: 1

【瑞萨RA4系列开发板体验】WATCHDOG功能使用

[复制链接]

116

主题

133

帖子

3768

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3768
发表于 2023-2-1 10:11:11 | 显示全部楼层 |阅读模式
【瑞萨RA4系列开发板体验】WATCHDOG功能使用
作者:大菠萝Alpha

RA4M2的WDT是一个14位递减计数器,可用于在计数器下溢时复位MCU,因为系统已失控且无法刷新WDT。此外,WDT可用于产生不可屏蔽中断或下溢中断。

  1. The Watchdog Timer (WDT) is a 14-bit down counter that can be used to reset the MCU when the counter underflows because the system has run out of control and is unable to refresh the WDT. In addition, the WDT can be used to generate a non-maskable interrupt or an underflow interrupt.
复制代码
首先FSP配置USART和WactchDog:

首先FSP配置USART和WactchDog:
  1. void hal_uart9_init()
  2. {
  3.     R_SCI_UART_Open(&g_uart9_ctrl, &g_uart9_cfg);
  4. }

  5. int fputc(int ch, FILE* f)
  6. {
  7.     (void) f;

  8.     uart_tx_done = false;

  9.     R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&ch, 1);

  10.     while (uart_tx_done == false);

  11.     return ch;
  12. }

  13. void user_uart9_callback(uart_callback_args_t* p_args)
  14. {
  15.    switch (p_args->event)
  16.    {
  17.       case UART_EVENT_RX_CHAR:
  18.             break;
  19.       case UART_EVENT_TX_COMPLETE:
  20.             uart_tx_done = true;
  21.             break;
  22.       default:
  23.             break;
  24.    }
  25. }
复制代码

DEBUG部分记得设置SWD,不要用JTAG,否则会跟USART9的PIN冲突。

最后点击生成代码:

最后点击生成代码:
  1. r_wdt_nmi_internal_callback()
复制代码

  1. R_WDT_CallbackSet()
复制代码
加入打印log的回调函数:
  1. printf("feed the dog!\n ");
复制代码

最后编译烧录:
  1. compiling common_data.c...
  2. compiling r_wdt.c...
  3. compiling r_ioport.c...
  4. compiling hal_data.c...
  5. compiling main.c...
  6. compiling pin_data.c...
  7. compiling vector_data.c...
  8. compiling r_sci_uart.c...
  9. linking...
  10. Program Size: Code=8712 RO-data=2392 RW-data=16 ZI-data=4216  
  11. FromELF: creating hex file...
  12. ".\Objects\wdt_ra4m2.axf" - 0 Error(s), 0 Warning(s).
  13. Build Time Elapsed:  00:00:03
复制代码
跑起来……



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

3

主题

195

帖子

1236

积分

金牌会员

Rank: 6Rank: 6

积分
1236
发表于 2023-3-14 11:16:56 | 显示全部楼层

不错,学习一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

用户排行榜

RA助手

主题: 116帖子:133精华:0

RA_Lance

主题: 92帖子:132精华:9

lugl

主题: 38帖子:126精华:0

xujiwei263

主题: 16帖子:73精华:0

books咦

主题: 11帖子:11精华:2

Juggernaut

主题: 9帖子:95精华:0
快速回复 返回顶部 返回列表