RT-Thread Studio STM32 RTC使用笔记
1、使能RTC:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200420164502163.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlanB0bQ==,size_16,color_FFFFFF,t_70)
2、拷贝drv_rtc.c和drv_log.h(这两个文件也会自动生成);使能#define HAL_RTC_MODULE_ENABLED:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200420164631213.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlanB0bQ==,size_16,color_FFFFFF,t_70)
3、修改board.h,使能片上RTC
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200420164955362.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlanB0bQ==,size_16,color_FFFFFF,t_70#pic_center)
4、修改main函数即可使用:
#include <time.h>
int main(void)
{
struct tm t;
t=rt_malloc(sizeof(struct tm));
time_t now=0;
LOG_D(“Hello RT-Thread!”);
while (1)
{
/ set LED0 pin level to high or low */
now=time(RT_NULL);
t=localtime(&now);
rt_kprintf("%d %d %d %d %d %d\n",t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
rt_thread_mdelay(1000);
}
return RT_EOK;
}