RA4M2的WDT是一个14位递减计数器,可用于在计数器下溢时复位MCU,因为系统已失控且无法刷新WDT。此外,WDT可用于产生不可屏蔽中断或下溢中断。
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:
配置USART9用于log输出,printf代码如下:
void hal_uart9_init()
{
R_SCI_UART_Open(&g_uart9_ctrl, &g_uart9_cfg);
}
int fputc(int ch, FILE* f)
{
(void) f;
uart_tx_done = false;
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&ch, 1);
while (uart_tx_done == false);
return ch;
}
void user_uart9_callback(uart_callback_args_t* p_args)
{
switch (p_args->event)
{
case UART_EVENT_RX_CHAR:
break;
case UART_EVENT_TX_COMPLETE:
uart_tx_done = true;
break;
default:
break;
}
}
DEBUG部分记得设置SWD,不要用JTAG,否则会跟USART9的PIN冲突。
最后点击生成代码:
后续就是在hal_entry()中使用r_wdt_nmi_internal_callback()
和R_WDT_CallbackSet()
加入打印log的回调函数:
printf("feed the dog!\n ");
最后编译烧录:
compiling common_data.c...
compiling r_wdt.c...
compiling r_ioport.c...
compiling hal_data.c...
compiling main.c...
compiling pin_data.c...
compiling vector_data.c...
compiling r_sci_uart.c...
linking...
Program Size: Code=8712 RO-data=2392 RW-data=16 ZI-data=4216
FromELF: creating hex file...
".\Objects\wdt_ra4m2.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:03
跑起来……
##感谢阅读##
更多回帖