Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2345VOR
rt-thread
提交
5e0e1701
R
rt-thread
项目概览
2345VOR
/
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,发现更多精彩内容 >>
提交
5e0e1701
编写于
11月 19, 2017
作者:
lymzzyh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BSP][stm32f4xx-hal][driver]Add RTC driver
上级
af2b9b99
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
1906 addition
and
292 deletion
+1906
-292
bsp/stm32f4xx-HAL/.config
bsp/stm32f4xx-HAL/.config
+2
-4
bsp/stm32f4xx-HAL/drivers/SConscript
bsp/stm32f4xx-HAL/drivers/SConscript
+3
-0
bsp/stm32f4xx-HAL/drivers/drv_rtc.c
bsp/stm32f4xx-HAL/drivers/drv_rtc.c
+206
-0
bsp/stm32f4xx-HAL/drivers/drv_rtc.h
bsp/stm32f4xx-HAL/drivers/drv_rtc.h
+28
-0
bsp/stm32f4xx-HAL/drivers/stm32f4xx_hal_conf.h
bsp/stm32f4xx-HAL/drivers/stm32f4xx_hal_conf.h
+3
-1
bsp/stm32f4xx-HAL/project.uvoptx
bsp/stm32f4xx-HAL/project.uvoptx
+1602
-2
bsp/stm32f4xx-HAL/project.uvprojx
bsp/stm32f4xx-HAL/project.uvprojx
+60
-281
bsp/stm32f4xx-HAL/rtconfig.h
bsp/stm32f4xx-HAL/rtconfig.h
+2
-4
未找到文件。
bsp/stm32f4xx-HAL/.config
浏览文件 @
5e0e1701
...
...
@@ -94,19 +94,17 @@ CONFIG_RT_USING_SERIAL=y
CONFIG_RT_USING_PIN
=
y
# CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_RTC is not set
CONFIG_RT_USING_RTC
=
y
# CONFIG_RT_USING_SDIO is not set
# CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_WIFI is not set
#
# Using USB
#
# CONFIG_RT_USING_USB_HOST is not set
# CONFIG_RT_USING_USB_DEVICE is not set
# CONFIG__RT_USB_DEVICE_CDC is not set
# CONFIG__RT_USB_DEVICE_MSTORAGE is not set
# CONFIG__RT_USB_DEVICE_HID is not set
#
# POSIX layer and C standard library
...
...
bsp/stm32f4xx-HAL/drivers/SConscript
浏览文件 @
5e0e1701
...
...
@@ -28,6 +28,9 @@ if GetDepend(['RT_USING_WDT']):
if
GetDepend
([
'RT_USING_USB_DEVICE'
]):
src
+=
[
'drv_usb.c'
]
if
GetDepend
([
'RT_USING_RTC'
]):
src
+=
[
'drv_rtc.c'
]
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
...
...
bsp/stm32f4xx-HAL/drivers/drv_rtc.c
0 → 100644
浏览文件 @
5e0e1701
/*
* File : drv_rtc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-10-25 ZYH first implementation
*/
#include "drv_rtc.h"
#include <board.h>
#include <rtdevice.h>
#include <string.h>
#include <time.h>
RTC_HandleTypeDef
hrtc
;
/* RTC init function */
void
MX_RTC_Init
(
void
)
{
RTC_TimeTypeDef
sTime
;
RTC_DateTypeDef
sDate
;
/**Initialize RTC Only
*/
hrtc
.
Instance
=
RTC
;
hrtc
.
Init
.
HourFormat
=
RTC_HOURFORMAT_24
;
hrtc
.
Init
.
AsynchPrediv
=
127
;
hrtc
.
Init
.
SynchPrediv
=
255
;
hrtc
.
Init
.
OutPut
=
RTC_OUTPUT_DISABLE
;
hrtc
.
Init
.
OutPutPolarity
=
RTC_OUTPUT_POLARITY_HIGH
;
hrtc
.
Init
.
OutPutType
=
RTC_OUTPUT_TYPE_OPENDRAIN
;
RT_ASSERT
(
HAL_RTC_Init
(
&
hrtc
)
==
HAL_OK
);
/**Initialize RTC and set the Time and Date
*/
if
(
HAL_RTCEx_BKUPRead
(
&
hrtc
,
RTC_BKP_DR0
)
!=
0x32F2
)
{
sTime
.
Hours
=
22
;
sTime
.
Minutes
=
28
;
sTime
.
Seconds
=
0
;
sTime
.
DayLightSaving
=
RTC_DAYLIGHTSAVING_NONE
;
sTime
.
StoreOperation
=
RTC_STOREOPERATION_RESET
;
RT_ASSERT
(
HAL_RTC_SetTime
(
&
hrtc
,
&
sTime
,
RTC_FORMAT_BIN
)
==
HAL_OK
);
sDate
.
WeekDay
=
RTC_WEEKDAY_THURSDAY
;
sDate
.
Month
=
RTC_MONTH_OCTOBER
;
sDate
.
Date
=
26
;
sDate
.
Year
=
17
;
RT_ASSERT
(
HAL_RTC_SetDate
(
&
hrtc
,
&
sDate
,
RTC_FORMAT_BIN
)
==
HAL_OK
);
}
HAL_RTCEx_BKUPWrite
(
&
hrtc
,
RTC_BKP_DR0
,
0x32F2
);
}
void
HAL_RTC_MspInit
(
RTC_HandleTypeDef
*
rtcHandle
)
{
if
(
rtcHandle
->
Instance
==
RTC
)
{
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/* RTC clock enable */
__HAL_RCC_RTC_ENABLE
();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
void
HAL_RTC_MspDeInit
(
RTC_HandleTypeDef
*
rtcHandle
)
{
if
(
rtcHandle
->
Instance
==
RTC
)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE
();
/* USER CODE BEGIN RTC_MspDeInit 1 */
/* USER CODE END RTC_MspDeInit 1 */
}
}
static
rt_err_t
stm32_rtc_control
(
struct
rt_device
*
dev
,
int
cmd
,
void
*
args
)
{
struct
tm
*
tm_now
;
struct
tm
now
;
RTC_TimeTypeDef
sTime
;
RTC_DateTypeDef
sDate
;
rt_enter_critical
();
/* converts calendar time time into local time. */
tm_now
=
localtime
((
const
time_t
*
)
args
);
/* copy the statically located variable */
memcpy
(
&
now
,
tm_now
,
sizeof
(
struct
tm
));
/* unlock scheduler. */
rt_exit_critical
();
switch
(
cmd
)
{
case
RT_DEVICE_CTRL_RTC_GET_TIME
:
HAL_RTC_GetTime
(
&
hrtc
,
&
sTime
,
RTC_FORMAT_BIN
);
HAL_RTC_GetDate
(
&
hrtc
,
&
sDate
,
RTC_FORMAT_BIN
);
now
.
tm_hour
=
sTime
.
Hours
;
now
.
tm_min
=
sTime
.
Minutes
;
now
.
tm_sec
=
sTime
.
Seconds
;
now
.
tm_year
=
sDate
.
Year
+
100
;
now
.
tm_mon
=
sDate
.
Month
-
1
;
now
.
tm_mday
=
sDate
.
Date
;
*
((
time_t
*
)
args
)
=
mktime
(
&
now
);
break
;
case
RT_DEVICE_CTRL_RTC_SET_TIME
:
sTime
.
Hours
=
now
.
tm_hour
;
sTime
.
Minutes
=
now
.
tm_min
;
sTime
.
Seconds
=
now
.
tm_sec
;
sDate
.
Year
=
now
.
tm_year
-
100
;
sDate
.
Month
=
now
.
tm_mon
+
1
;
sDate
.
Date
=
now
.
tm_mday
;
HAL_RTC_SetTime
(
&
hrtc
,
&
sTime
,
RTC_FORMAT_BIN
);
HAL_RTC_SetDate
(
&
hrtc
,
&
sDate
,
RTC_FORMAT_BIN
);
break
;
}
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_init
(
struct
rt_device
*
dev
)
{
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_open
(
struct
rt_device
*
dev
,
rt_uint16_t
oflag
)
{
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_close
(
struct
rt_device
*
dev
)
{
return
RT_EOK
;
}
static
rt_size_t
stm32_rtc_read
(
struct
rt_device
*
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
stm32_rtc_control
(
dev
,
RT_DEVICE_CTRL_RTC_GET_TIME
,
buffer
);
return
size
;
}
static
rt_size_t
stm32_rtc_write
(
struct
rt_device
*
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
{
stm32_rtc_control
(
dev
,
RT_DEVICE_CTRL_RTC_SET_TIME
,(
void
*
)
buffer
);
return
size
;
}
struct
rt_device
rtc_device
;
int
rt_hw_rtc_init
(
void
)
{
MX_RTC_Init
();
rtc_device
.
type
=
RT_Device_Class_RTC
;
rtc_device
.
rx_indicate
=
RT_NULL
;
rtc_device
.
tx_complete
=
RT_NULL
;
rtc_device
.
init
=
stm32_rtc_init
;
rtc_device
.
open
=
stm32_rtc_open
;
rtc_device
.
close
=
stm32_rtc_close
;
rtc_device
.
read
=
stm32_rtc_read
;
rtc_device
.
write
=
stm32_rtc_write
;
rtc_device
.
control
=
stm32_rtc_control
;
rtc_device
.
user_data
=
RT_NULL
;
/* register a character device */
return
rt_device_register
(
&
rtc_device
,
"rtc"
,
RT_DEVICE_FLAG_DEACTIVATE
);
}
INIT_BOARD_EXPORT
(
rt_hw_rtc_init
);
bsp/stm32f4xx-HAL/drivers/drv_rtc.h
0 → 100644
浏览文件 @
5e0e1701
/*
* File : drv_rtc.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-10-25 ZYH first implementation
*/
#ifndef __DRV_RTC_H__
#define __DRV_RTC_H__
extern
int
rt_hw_rtc_init
(
void
);
#endif
bsp/stm32f4xx-HAL/drivers/stm32f4xx_hal_conf.h
浏览文件 @
5e0e1701
...
...
@@ -75,7 +75,9 @@
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
/* #define HAL_RTC_MODULE_ENABLED */
#ifdef RT_USING_RTC
#define HAL_RTC_MODULE_ENABLED
#endif
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
#ifdef RT_USING_SPI
...
...
bsp/stm32f4xx-HAL/project.uvoptx
浏览文件 @
5e0e1701
此差异已折叠。
点击以展开。
bsp/stm32f4xx-HAL/project.uvprojx
浏览文件 @
5e0e1701
此差异已折叠。
点击以展开。
bsp/stm32f4xx-HAL/rtconfig.h
浏览文件 @
5e0e1701
...
...
@@ -86,18 +86,16 @@
#define RT_USING_PIN
/* RT_USING_MTD_NOR is not set */
/* RT_USING_MTD_NAND is not set */
/* RT_USING_RTC is not set */
#define RT_USING_RTC
/* RT_USING_SDIO is not set */
/* RT_USING_SPI is not set */
/* RT_USING_WDT is not set */
/* RT_USING_WIFI is not set */
/* Using USB */
/* RT_USING_USB_HOST is not set */
/* RT_USING_USB_DEVICE is not set */
/* _RT_USB_DEVICE_CDC is not set */
/* _RT_USB_DEVICE_MSTORAGE is not set */
/* _RT_USB_DEVICE_HID is not set */
/* POSIX layer and C standard library */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录