Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
9fa72d0b
R
rt-thread
项目概览
BaiXuePrincess
/
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,发现更多精彩内容 >>
提交
9fa72d0b
编写于
11月 16, 2021
作者:
1
192.168.1.134
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix wrong clock input
上级
5711b0a7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
66 deletion
+19
-66
bsp/n32g452xx/Libraries/rt_drivers/drv_hwtimer.c
bsp/n32g452xx/Libraries/rt_drivers/drv_hwtimer.c
+18
-65
bsp/n32g452xx/Libraries/rt_drivers/drv_hwtimer.h
bsp/n32g452xx/Libraries/rt_drivers/drv_hwtimer.h
+1
-1
未找到文件。
bsp/n32g452xx/Libraries/rt_drivers/drv_hwtimer.c
浏览文件 @
9fa72d0b
...
...
@@ -49,34 +49,6 @@ enum
#ifdef BSP_USING_HW_TIM8
TIM8_INDEX
,
#endif
#ifdef BSP_USING_HWTIM9
TIM9_INDEX
,
#endif
#ifdef BSP_USING_HWTIM10
TIM10_INDEX
,
#endif
#ifdef BSP_USING_HWTIM11
TIM11_INDEX
,
#endif
#ifdef BSP_USING_HWTIM12
TIM12_INDEX
,
#endif
#ifdef BSP_USING_HWTIM13
TIM13_INDEX
,
#endif
#ifdef BSP_USING_HWTIM14
TIM14_INDEX
,
#endif
#ifdef BSP_USING_HWTIM15
TIM15_INDEX
,
#endif
};
struct
n32_hwtimer
...
...
@@ -120,34 +92,6 @@ static struct n32_hwtimer n32_hwtimer_obj[] =
#ifdef BSP_USING_HWTIM8
TIM8_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM9
TIM9_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM10
TIM10_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM11
TIM11_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM12
TIM12_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM13
TIM13_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM14
TIM14_CONFIG
,
#endif
#ifdef BSP_USING_HWTIM15
TIM15_CONFIG
,
#endif
};
static
void
n32_timer_init
(
struct
rt_hwtimer_device
*
timer
,
rt_uint32_t
state
)
...
...
@@ -155,6 +99,8 @@ static void n32_timer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
RCC_ClocksType
RCC_ClockStruct
;
TIM_TimeBaseInitType
TIM_TimeBaseStructure
;
NVIC_InitType
NVIC_InitStructure
;
uint32_t
freq
=
0
;
uint32_t
input_clock
;
uint32_t
prescaler_value
=
0
;
TIM_Module
*
tim
=
RT_NULL
;
struct
n32_hwtimer
*
tim_device
=
RT_NULL
;
...
...
@@ -165,18 +111,22 @@ static void n32_timer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
tim
=
(
TIM_Module
*
)
timer
->
parent
.
user_data
;
tim_device
=
(
struct
n32_hwtimer
*
)
timer
;
RT_ASSERT
((
tim
==
TIM2
)
||
(
tim
==
TIM3
)
||
(
tim
==
TIM4
)
||
(
tim
==
TIM5
)
||
(
tim
==
TIM6
)
||
(
tim
==
TIM7
));
/* timer clock enable */
n32_msp_hwtim_init
(
tim
);
/* timer init */
freq
=
timer
->
freq
;
RCC_GetClocksFreqValue
(
&
RCC_ClockStruct
);
/* Set timer clock is 1Mhz */
prescaler_value
=
(
uint32_t
)(
RCC_ClockStruct
.
SysclkFreq
/
10000
)
-
1
;
if
(
1
==
(
RCC_ClockStruct
.
HclkFreq
/
RCC_ClockStruct
.
Pclk1Freq
))
input_clock
=
RCC_ClockStruct
.
Pclk1Freq
;
else
input_clock
=
RCC_ClockStruct
.
Pclk1Freq
*
2
;
prescaler_value
=
(
uint32_t
)(
input_clock
/
freq
)
-
1
;
TIM_TimeBaseStructure
.
Period
=
10000
-
1
;
rt_kprintf
(
"Period=[%d]"
,
TIM_TimeBaseStructure
.
Period
);
TIM_TimeBaseStructure
.
Period
=
freq
-
1
;
TIM_TimeBaseStructure
.
Prescaler
=
prescaler_value
;
rt_kprintf
(
"Prescaler=[%d]"
,
TIM_TimeBaseStructure
.
Prescaler
);
TIM_TimeBaseStructure
.
ClkDiv
=
TIM_CLK_DIV1
;
TIM_TimeBaseStructure
.
RepetCnt
=
0
;
...
...
@@ -274,6 +224,7 @@ static rt_err_t n32_timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)
{
case
HWTIMER_CTRL_FREQ_SET
:
{
rt_uint32_t
input_clock
;
rt_uint32_t
freq
;
rt_uint16_t
val
;
...
...
@@ -282,9 +233,11 @@ static rt_err_t n32_timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)
/* time init */
RCC_GetClocksFreqValue
(
&
RCC_ClockStruct
);
val
=
RCC_ClockStruct
.
SysclkFreq
/
freq
;
if
(
1
==
(
RCC_ClockStruct
.
HclkFreq
/
RCC_ClockStruct
.
Pclk1Freq
))
input_clock
=
RCC_ClockStruct
.
Pclk1Freq
;
else
input_clock
=
RCC_ClockStruct
.
Pclk1Freq
*
2
;
val
=
input_clock
/
freq
;
TIM_ConfigPrescaler
(
tim
,
val
-
1
,
TIM_PSC_RELOAD_MODE_IMMEDIATE
);
}
break
;
...
...
bsp/n32g452xx/Libraries/rt_drivers/drv_hwtimer.h
浏览文件 @
9fa72d0b
...
...
@@ -22,7 +22,7 @@ extern "C" {
#define TIM_DEV_INFO_CONFIG \
{ \
.maxfreq = 1000000, \
.minfreq =
4
000, \
.minfreq =
1
000, \
.maxcnt = 0xFFFF, \
.cntmode = HWTIMER_CNTMODE_UP, \
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录