Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
ecc0981d
R
rt-thread
项目概览
AdRainty
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ecc0981d
编写于
7月 05, 2021
作者:
I
iysheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp][stm32] Implement stm32 rtc driver to RTC framework V2.0
上级
2bd7e048
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
81 deletion
+61
-81
bsp/stm32/libraries/HAL_Drivers/drv_rtc.c
bsp/stm32/libraries/HAL_Drivers/drv_rtc.c
+61
-81
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_rtc.c
浏览文件 @
ecc0981d
...
...
@@ -8,6 +8,7 @@
* 2018-12-04 balanceTWK first version
* 2020-10-14 Dozingfiretruck Porting for stm32wbxx
* 2021-02-05 Meco Man fix the problem of mixing local time and UTC time
* 2021-07-05 iysheng implement RTC framework V2.0
*/
#include "board.h"
...
...
@@ -25,8 +26,6 @@
#define BKUP_REG_DATA 0xA5A5
static
struct
rt_device
rtc
;
static
RTC_HandleTypeDef
RTC_Handler
;
RT_WEAK
uint32_t
HAL_RTCEx_BKUPRead
(
RTC_HandleTypeDef
*
hrtc
,
uint32_t
BackupRegister
)
...
...
@@ -102,34 +101,6 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
return
RT_EOK
;
}
static
void
rt_rtc_init
(
void
)
{
#if !defined(SOC_SERIES_STM32H7) && !defined(SOC_SERIES_STM32WL) && !defined(SOC_SERIES_STM32WB)
__HAL_RCC_PWR_CLK_ENABLE
();
#endif
RCC_OscInitTypeDef
RCC_OscInitStruct
=
{
0
};
#ifdef BSP_RTC_USING_LSI
#ifdef SOC_SERIES_STM32WB
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_LSI1
;
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_NONE
;
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_OFF
;
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_ON
;
#else
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_LSI
;
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_NONE
;
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_OFF
;
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_ON
;
#endif
#else
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_LSE
;
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_NONE
;
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_ON
;
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_OFF
;
#endif
HAL_RCC_OscConfig
(
&
RCC_OscInitStruct
);
}
#ifdef SOC_SERIES_STM32F1
/* update RTC_BKP_DRx*/
static
void
rt_rtc_f1_bkp_update
(
void
)
...
...
@@ -160,7 +131,7 @@ static void rt_rtc_f1_bkp_update(void)
}
#endif
static
rt_err_t
rt_rtc_config
(
struct
rt_device
*
dev
)
static
rt_err_t
rt_rtc_config
(
void
)
{
RCC_PeriphCLKInitTypeDef
PeriphClkInitStruct
=
{
0
};
...
...
@@ -234,81 +205,90 @@ static rt_err_t rt_rtc_config(struct rt_device *dev)
return
RT_EOK
;
}
static
rt_err_t
rt_rtc_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
static
rt_err_t
stm32_rtc_init
(
void
)
{
rt_err_t
result
=
RT_EOK
;
RT_ASSERT
(
dev
!=
RT_NULL
);
switch
(
cmd
)
#if !defined(SOC_SERIES_STM32H7) && !defined(SOC_SERIES_STM32WL) && !defined(SOC_SERIES_STM32WB)
__HAL_RCC_PWR_CLK_ENABLE
();
#endif
RCC_OscInitTypeDef
RCC_OscInitStruct
=
{
0
};
#ifdef BSP_RTC_USING_LSI
#ifdef SOC_SERIES_STM32WB
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_LSI1
;
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_NONE
;
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_OFF
;
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_ON
;
#else
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_LSI
;
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_NONE
;
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_OFF
;
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_ON
;
#endif
#else
RCC_OscInitStruct
.
OscillatorType
=
RCC_OSCILLATORTYPE_LSE
;
RCC_OscInitStruct
.
PLL
.
PLLState
=
RCC_PLL_NONE
;
RCC_OscInitStruct
.
LSEState
=
RCC_LSE_ON
;
RCC_OscInitStruct
.
LSIState
=
RCC_LSI_OFF
;
#endif
HAL_RCC_OscConfig
(
&
RCC_OscInitStruct
);
if
(
rt_rtc_config
()
!=
RT_EOK
)
{
case
RT_DEVICE_CTRL_RTC_GET_TIME
:
*
(
rt_uint32_t
*
)
args
=
get_rtc_timestamp
();
LOG_D
(
"RTC: get rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
break
;
LOG_E
(
"rtc init failed."
);
return
-
RT_ERROR
;
}
case
RT_DEVICE_CTRL_RTC_SET_TIME
:
if
(
set_rtc_time_stamp
(
*
(
rt_uint32_t
*
)
args
))
{
result
=
-
RT_ERROR
;
}
LOG_D
(
"RTC: set rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
break
;
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_get_secs
(
void
*
args
)
{
*
(
rt_uint32_t
*
)
args
=
get_rtc_timestamp
();
LOG_D
(
"RTC: get rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_set_secs
(
void
*
args
)
{
rt_err_t
result
=
RT_EOK
;
if
(
set_rtc_time_stamp
(
*
(
rt_uint32_t
*
)
args
))
{
result
=
-
RT_ERROR
;
}
LOG_D
(
"RTC: set rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
return
result
;
}
#ifdef RT_USING_DEVICE_OPS
const
static
struct
rt_device_ops
rtc_ops
=
static
const
struct
rt_rtc_ops
stm32_rtc_ops
=
{
stm32_rtc_init
,
stm32_rtc_get_secs
,
/* get_secs */
stm32_rtc_set_secs
,
/* set secs */
RT_NULL
,
RT_NULL
,
RT_NULL
,
RT_NULL
,
RT_NULL
,
rt_rtc_control
};
#endif
static
rt_err_t
rt_hw_rtc_register
(
rt_device_t
device
,
const
char
*
name
,
rt_uint32_t
flag
)
{
RT_ASSERT
(
device
!=
RT_NULL
);
static
rt_rtc_dev_t
stm32_rtc_dev
;
rt_rtc_init
();
if
(
rt_rtc_config
(
device
)
!=
RT_EOK
)
{
return
-
RT_ERROR
;
}
#ifdef RT_USING_DEVICE_OPS
device
->
ops
=
&
rtc_ops
;
#else
device
->
init
=
RT_NULL
;
device
->
open
=
RT_NULL
;
device
->
close
=
RT_NULL
;
device
->
read
=
RT_NULL
;
device
->
write
=
RT_NULL
;
device
->
control
=
rt_rtc_control
;
#endif
device
->
type
=
RT_Device_Class_RTC
;
device
->
rx_indicate
=
RT_NULL
;
device
->
tx_complete
=
RT_NULL
;
device
->
user_data
=
RT_NULL
;
/* register a character device */
return
rt_device_register
(
device
,
name
,
flag
);
}
int
rt_hw_rtc_init
(
void
)
static
int
rt_hw_rtc_init
(
void
)
{
rt_err_t
result
;
result
=
rt_hw_rtc_register
(
&
rtc
,
"rtc"
,
RT_DEVICE_FLAG_RDWR
);
stm32_rtc_dev
.
ops
=
&
stm32_rtc_ops
;
result
=
rt_rtc_dev_register
(
&
stm32_rtc_dev
,
"rtc"
,
RT_DEVICE_FLAG_RDWR
,
RT_NULL
);
if
(
result
!=
RT_EOK
)
{
LOG_E
(
"rtc register err code: %d"
,
result
);
return
result
;
}
LOG_D
(
"rtc init success"
);
return
RT_EOK
;
}
INIT_DEVICE_EXPORT
(
rt_hw_rtc_init
);
#endif
/* BSP_USING_ONCHIP_RTC */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录