1.概述
本篇文章主要介绍如何使用e2studio对瑞萨进行独立看门狗iwdt配置,并且配置rtc时钟产生1s的周期中断,通过串口打印查看独立看门狗iwdt的计数值。
2.硬件准备
首先需要准备一个开发板,这里我准备的是芯片型号 r7fa2l1ab2dfl 的开发板。
3.新建工程
4.工程模板
5.保存工程路径
6.芯片配置
本文中使用r7fa2l1ab2dfl来进行演示。
7
7.工程模板选择
8.iwdt配置
点击stacks -> new stack->driver -> monitoring -> watchdog driver on r_iwdt。
9.iwdt属性配置
10.ofs属性配置
11.rtc配置
点击stacks->new stack->driver->timers -> rtc driver on r_rtc。
12.rtc属性配置
13.设置e2studio堆栈
14.e2studio的重定向printf设置
c++ 构建->设置->gnu arm cross c linker->miscellaneous去掉other linker flags中的 “--specs=rdimon.specs”
15.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++)>
16.r_iwdt_open()函数原型
故可以用r_iwdt_open()函数进行初始化和开启iwdt。
/* open the module. */ err = r_iwdt_open(&g_iwdt0_ctrl, &g_iwdt0_cfg); /* handle any errors. this function should be defined by the user. */ assert(fsp_success == err);
17.r_iwdt_refresh()函数原型
故可以用r_iwdt_refresh()函数进行喂狗操作。
/* refresh before the counter underflows to prevent reset or nmi. */(void) r_iwdt_refresh(&g_iwdt0_ctrl);
18.r_iwdt_counterget()函数原型
故可以用r_iwdt_counterget()函数获取当前的计数值。
uint32_t iwdt_counter = 0u; err = r_iwdt_counterget(&g_iwdt0_ctrl, &iwdt_counter);
19.iwdt周期设定
通过查阅数据手册,可以得知iwdt使用的时钟为15k。
iwdt从iwdtclk运行,依据上文的设定,iwdt周期如下所示。
paramete equal to
iwdtclk 15khz
clock division rati iwdtclk/32
timeout period 2048 cycles
iwdt clock frequency 15 khz / 32 = 468.75 hz
cycle time 1 / 468.75 hz = 2.13 ms
timeout 2.13 ms x 2048 cycles = 4.362 seconds
上述可以看到在该设置下的溢出时间为4.362s,那么1s的计数为1s/2.13ms=469。
20.iwdt计数周期
iwdt计数是从最高一直减到0,当到0时候触发复位。
21.演示效果
设置每过1s打印一次当前时间,分别设置喂狗和不喂狗,结果如下。
延迟1s的计数为1s/2.13ms=469,打印为1570,由于是向下计数,2048-1570=478,符合计算值。
当不执行喂狗时候,计数值到0时会进行复位。
22.完整代码
#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;}/*******************************************************************************************************************//** * main() is generated by the ra configuration editor and is used to generate threads if an rtos is used. this function * is called by main() when no rtos is used. **********************************************************************************************************************/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); printf(starting up !\n); /* (optional) enable the iwdt to count and generate nmi or reset when the * debugger is connected. */ r_debug->dbgstopcr_b.dbgstop_iwdt = 0; /* (optional) check if the iwdtrf flag is set to know if the system is * recovering from a iwdt reset. */ if (r_system->rstsr1_b.iwdtrf) { /* clear the flag. */ r_system->rstsr1 = 0u; } /* open the module. */ err = r_iwdt_open(&g_iwdt0_ctrl, &g_iwdt0_cfg); /* handle any errors. this function should be defined by the user. */ assert(fsp_success == err); /* initialize other application code. */ /* do not call r_iwdt_refresh() in auto start mode unless the * counter is in the acceptable refresh window. */ (void) r_iwdt_refresh(&g_iwdt0_ctrl); while(1) { if(rtc_flag) { uint32_t iwdt_counter = 0u; err = r_iwdt_counterget(&g_iwdt0_ctrl, &iwdt_counter); assert(fsp_success == err); printf(iwdt_counter=%d\n,iwdt_counter); /* refresh before the counter underflows to prevent reset or nmi. */ (void) r_iwdt_refresh(&g_iwdt0_ctrl); rtc_flag=0; } }#if bsp_tz_secure_build /* enter non-secure code */ r_bsp_nonsecureenter();#endif};i++)>原创:by ra_billy xiao
原文标题:瑞萨e2studio----独立看门狗iwdt
文章出处:【微信公众号:ra生态工作室】欢迎添加关注!文章转载请注明出处。
Arm化身航空母舰 耗费十年计划打造物联网战队
使用LabVIEW和CompactRIO开发腿轮混合式移动机器人
到2022年全球语音分析市场将达21.758亿美元
E拆解:三星中端机台湾市场之三星Galaxy J8
中国移动发布了以1+4为核心的工业互联网平台产品赋能行业智造未来
瑞萨e2studio----独立看门狗IWDT
Pyramid-MW 探针卡的主要特征说明
聚合物锂离子电池的充放电注意事项及使用说明
华为已拿到5G牌照!
新能源客车行业普遍亏损或盈利下降,最主要的原因是补贴退坡
基于DSP+FPGA的并行信号处理模块设计
区块链为中小型企业提供了怎样的战略机遇
PLC开关量信号和模拟量信号如何转换
5V供电Cortex-M微控制器
为什么要应用智慧畜牧养殖系统,它的优势是什么
便民车务讲青岛汽车违章可以在网上查询处理吗?
PWM占空比趋势测量可快速分析电机运行异常
光电控制过压保护装置的工作原理
通信过程分为哪几个环节?通信系统的基本组成包括哪几部分
魅族PRO6Plus评测 是为真正煤油准备的手机