添加rtc组件步骤, 系统版本4.1.1
1.rt-thread settings中添加rtc
2.board.h中打开rtc的开关 #define BSP_USING_ONCHIP_RTC
3.stm32g0xx_hal_conf.h 打开rtc选项 #define HAL_RTC_MODULE_ENABLED
4.rt-thread\components\drivers\rtc\rtc.c中注释掉与drv_rtc.c中冲突的代码,包括以下函数
static rt_err_t rt_rtc_init(struct rt_device *dev)
static rt_err_t rt_rtc_open(struct rt_device *dev, rt_uint16_t oflag)
static rt_err_t rt_rtc_close(struct rt_device *dev)
static rt_err_t rt_rtc_control(struct rt_device *dev, int cmd, void *args)
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,const char *name,rt_uint32_t flag,void *data)
5.rt-thread\components\include\drivers\rtc\rtc.h中注释掉以下声明
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc,const char *name,rt_uint32_t flag,void *data)
完成
常见问题
1.组件初始化失败
board.h中需要添加 void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) (stm32 cubemx 生成)
2.时间乱跳,不能正常走时
通常是drv_rtc.c中配置rtc函数static void rt_rtc_init(void)中由于条件编译缺少了配置项导致,可对比cubemx生成的配置代码调整条件编译即可
标签:rt,rtc,err,void,dev,thread,static From: https://www.cnblogs.com/arthurly/p/18147192