提交 9fa72d0b 编写于 作者: 1 192.168.1.134

fix: fix wrong clock input

上级 5711b0a7
...@@ -49,34 +49,6 @@ enum ...@@ -49,34 +49,6 @@ enum
#ifdef BSP_USING_HW_TIM8 #ifdef BSP_USING_HW_TIM8
TIM8_INDEX, TIM8_INDEX,
#endif #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 struct n32_hwtimer
...@@ -120,34 +92,6 @@ static struct n32_hwtimer n32_hwtimer_obj[] = ...@@ -120,34 +92,6 @@ static struct n32_hwtimer n32_hwtimer_obj[] =
#ifdef BSP_USING_HWTIM8 #ifdef BSP_USING_HWTIM8
TIM8_CONFIG, TIM8_CONFIG,
#endif #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) 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) ...@@ -155,6 +99,8 @@ static void n32_timer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
RCC_ClocksType RCC_ClockStruct; RCC_ClocksType RCC_ClockStruct;
TIM_TimeBaseInitType TIM_TimeBaseStructure; TIM_TimeBaseInitType TIM_TimeBaseStructure;
NVIC_InitType NVIC_InitStructure; NVIC_InitType NVIC_InitStructure;
uint32_t freq = 0;
uint32_t input_clock;
uint32_t prescaler_value = 0; uint32_t prescaler_value = 0;
TIM_Module *tim = RT_NULL; TIM_Module *tim = RT_NULL;
struct n32_hwtimer *tim_device = 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) ...@@ -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 = (TIM_Module *)timer->parent.user_data;
tim_device = (struct n32_hwtimer *)timer; tim_device = (struct n32_hwtimer *)timer;
RT_ASSERT((tim == TIM2) || (tim == TIM3) || (tim == TIM4) || (tim == TIM5)
|| (tim == TIM6) || (tim == TIM7));
/* timer clock enable */ /* timer clock enable */
n32_msp_hwtim_init(tim); n32_msp_hwtim_init(tim);
/* timer init */ freq = timer->freq;
RCC_GetClocksFreqValue(&RCC_ClockStruct); RCC_GetClocksFreqValue(&RCC_ClockStruct);
/* Set timer clock is 1Mhz */ if (1 == (RCC_ClockStruct.HclkFreq / RCC_ClockStruct.Pclk1Freq))
prescaler_value = (uint32_t)(RCC_ClockStruct.SysclkFreq / 10000) - 1; 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; TIM_TimeBaseStructure.Period = freq - 1;
rt_kprintf("Period=[%d]", TIM_TimeBaseStructure.Period);
TIM_TimeBaseStructure.Prescaler = prescaler_value; TIM_TimeBaseStructure.Prescaler = prescaler_value;
rt_kprintf("Prescaler=[%d]", TIM_TimeBaseStructure.Prescaler);
TIM_TimeBaseStructure.ClkDiv = TIM_CLK_DIV1; TIM_TimeBaseStructure.ClkDiv = TIM_CLK_DIV1;
TIM_TimeBaseStructure.RepetCnt = 0; 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) ...@@ -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: case HWTIMER_CTRL_FREQ_SET:
{ {
rt_uint32_t input_clock;
rt_uint32_t freq; rt_uint32_t freq;
rt_uint16_t val; 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) ...@@ -282,9 +233,11 @@ static rt_err_t n32_timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)
/* time init */ /* time init */
RCC_GetClocksFreqValue(&RCC_ClockStruct); RCC_GetClocksFreqValue(&RCC_ClockStruct);
if (1 == (RCC_ClockStruct.HclkFreq / RCC_ClockStruct.Pclk1Freq))
val = RCC_ClockStruct.SysclkFreq / freq; 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); TIM_ConfigPrescaler(tim, val - 1, TIM_PSC_RELOAD_MODE_IMMEDIATE);
} }
break; break;
......
...@@ -22,7 +22,7 @@ extern "C" { ...@@ -22,7 +22,7 @@ extern "C" {
#define TIM_DEV_INFO_CONFIG \ #define TIM_DEV_INFO_CONFIG \
{ \ { \
.maxfreq = 1000000, \ .maxfreq = 1000000, \
.minfreq = 4000, \ .minfreq = 1000, \
.maxcnt = 0xFFFF, \ .maxcnt = 0xFFFF, \
.cntmode = HWTIMER_CNTMODE_UP, \ .cntmode = HWTIMER_CNTMODE_UP, \
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册