瑞萨e2studio----看门狗WDT

1.概述      
     本篇文章主要介绍如何使用e2studio对瑞萨进行看门狗wdt配置,并且配置rtc时钟产生1s的周期中断,通过串口打印查看看门狗wdt的计数值。
2.硬件准备   
     首先需要准备一个开发板,这里我准备的是芯片型号 r7fa2l1ab2dfl 的开发板。 
3.新建工程
4.工程模板
5.保存工程路径
6.芯片配置     
    本文中使用r7fa2l1ab2dfl来进行演示。 
7
   7.工程模板选择
8.wdt配置     
    点击stacks->new stack->driver->monitoring -> watchdog driver on r_wdt。
9.wdt属性配置
10.rtc配置     
        点击stacks->new stack->driver->timers -> rtc driver on r_rtc。
11.rtc属性配置
12.设置e2studio堆栈
13.e2studio的重定向printf设置     
    c++ 构建->设置->gnu arm cross c linker->miscellaneous去掉other linker flags中的 “--specs=rdimon.specs”
14.printf输出重定向到串口         打印最常用的方法是printf,所以要解决的问题是将printf的输出重定向到串口,然后通过串口将数据发送出去。    注意一定要加上头文件#include#ifdef __gnuc__ //串口重定向 #define putchar_prototype int __io_putchar(int ch)#else #define putchar_prototype int fputc(int ch, file *f)#endifputchar_prototype{ err = r_sci_uart_write(&g_uart0_ctrl, (uint8_t *)&ch, 1); if(fsp_success != err) __bkpt(); while(uart_send_complete_flag == false){} uart_send_complete_flag = false; return ch;}int _write(int fd,char *pbuffer,int size){ for(int i=0;i;i++)>
15.r_wdt_open()函数原型       
    故可以用r_wdt_open()函数进行初始化和开启wdt。 /* open the module. */ err = r_wdt_open(&g_wdt0_ctrl, &g_wdt0_cfg); /* handle any errors. this function should be defined by the user. */ assert(fsp_success == err);
16.r_wdt_refresh()函数原型      
     故可以用r_wdt_refresh()函数进行喂狗操作。 /* refresh before the counter underflows to prevent reset or nmi. */ err = r_wdt_refresh(&g_wdt0_ctrl); assert(fsp_success == err);
17.r_wdt_counterget()函数原型      
    故可以用r_wdt_counterget()函数获取当前的计数值。 /* read the current wdt counter value. */ err = r_wdt_counterget(&g_wdt0_ctrl, &wdt_counter); assert(fsp_success == err);
18.wdt周期设定      
     通过查阅数据手册,可以得知wdt使用的时钟为pclkb。    在本案例中,使用的pclkb时钟为24mhz。    wdt从pclkb运行,依据上文的设定,pclkb周期如下所示。paramete equal to
plckb/2 24mhz
clock division ratio plck/8192
timeout period 16384 cycles
wdt clock frequency 24mhz / 8192 = 2929.6875 hz
cycle time 1 / 2929.6875 hz = 341.33 us
timeout 341.33 us * 16384 cycles = 5.59 seconds
上述可以看到在该设置下的溢出时间为5.59s,那么1s的计数为1s/341.33 us=2930。
19.wdt计数周期         
    wdt计数是从最高一直减到0,当到0时候触发复位。
20.演示效果       
    设置每过1s打印一次当前时间,分别设置喂狗和不喂狗,结果如下。    延迟1s的计数为1s/341.33us=2930,打印为13460,由于是向下计数,16384-2930=13554,符合计算值。    当不执行喂狗时候,计数值到0时会进行复位,2个复位之间为5.595s,符合计算的5.59s。
21.完整代码    #include hal_data.h#include fsp_cpp_headervoid r_bsp_warmstart(bsp_warm_start_event_t event);fsp_cpp_footerfsp_err_t err = fsp_success;volatile bool uart_send_complete_flag = false;void user_uart_callback (uart_callback_args_t * p_args){ if(p_args->event == uart_event_tx_complete) { uart_send_complete_flag = true; }}#ifdef __gnuc__ //串口重定向 #define putchar_prototype int __io_putchar(int ch)#else #define putchar_prototype int fputc(int ch, file *f)#endifputchar_prototype{ err = r_sci_uart_write(&g_uart0_ctrl, (uint8_t *)&ch, 1); if(fsp_success != err) __bkpt(); while(uart_send_complete_flag == false){} uart_send_complete_flag = false; return ch;}int _write(int fd,char *pbuffer,int size){ for(int i=0;ievent == rtc_event_periodic_irq) rtc_flag=1;}void hal_entry(void){ /* todo: add your own code here */ err = r_sci_uart_open(&g_uart0_ctrl, &g_uart0_cfg); assert(fsp_success == err); /* initialize the rtc module*/ err = r_rtc_open(&g_rtc0_ctrl, &g_rtc0_cfg); /* handle any errors. this function should be defined by the user. */ assert(fsp_success == err); /* set the periodic interrupt rate to 1 second */ r_rtc_periodicirqrateset(&g_rtc0_ctrl, rtc_periodic_irq_select_1_second); /* (optional) enable the wdt to count and generate nmi or reset when the * debugger is connected. */ r_debug->dbgstopcr_b.dbgstop_wdt = 0; /* (optional) check if the wdtrf flag is set to know if the system is * recovering from a wdt reset. */ if (r_system->rstsr1_b.wdtrf) { /* clear the flag. */ r_system->rstsr1 = 0u; } /* open the module. */ err = r_wdt_open(&g_wdt0_ctrl, &g_wdt0_cfg); /* handle any errors. this function should be defined by the user. */ assert(fsp_success == err); /* in register start mode, start the watchdog by calling r_wdt_refresh. */ err = r_wdt_refresh(&g_wdt0_ctrl); assert(fsp_success == err); printf(starting up !\n); uint32_t wdt_counter = 0u;while(1) { if(rtc_flag) { /* read the current wdt counter value. */ err = r_wdt_counterget(&g_wdt0_ctrl, &wdt_counter); assert(fsp_success == err); printf(wdt_counter=%d\n,wdt_counter); rtc_flag=0; /* refresh before the counter underflows to prevent reset or nmi. */ err = r_wdt_refresh(&g_wdt0_ctrl); assert(fsp_success == err); } }#if bsp_tz_secure_build /* enter non-secure code */ r_bsp_nonsecureenter();#endif};i++)>

提前过双十一 红米4上市价格低到冰点499元起性价比超高
DSP运营商能否转型为从卖网络管道转型为卖管道+算力?
香蕉派BPI-M2 Pro单板计算机采用Amlogic S905x3 芯片方案设计,板载2G RAM 和16GB eMMC
激光投影上半年成绩:忧喜两面更分化
SMC100A射频信号发生器的特点及应用
瑞萨e2studio----看门狗WDT
新思科技推出面向低功耗嵌入式SoC的全新ARC DSP IP解决方案,提升处理器IP核领导地位
服务器安全需要从根源得到解决
气密性测试仪,新能源电池水冷板气密性检测解决技术
Wi-Fi对实现智能家居有何帮助?
静止同步补偿器的工作原理、类型、应用及发展现状介绍
反向电池充电器保护
隔着屏幕杀敌,无人机战士也有心理创伤
高压软启动器与低压软启动器的几大区别
大型减速机对开式轴承室磨损如何修复
在用户态与内核中实现并使用线程
光纤激光器的用途
在手持式触摸屏系统中增添接近检测传感器
怎样判断大功率三极管的好坏 浅析三极管的好坏检测
微小产品推拉力机,有哪些产品特点?行程、荷重