Skip to content

Commit d2a857e

Browse files
author
xieyangrun
committed
[STM32/drv_pwm.c]fixed PWM timer init.
1 parent cad32a3 commit d2a857e

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_pwm.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration
205205
tim_clock = HAL_RCC_GetPCLK1Freq() * 2;
206206
#endif
207207
}
208-
208+
209209
if (__HAL_TIM_GET_CLOCKDIVISION(htim) == TIM_CLOCKDIVISION_DIV2)
210210
{
211211
tim_clock = tim_clock / 2;
@@ -323,9 +323,9 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
323323
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
324324
#endif
325325

326-
if (HAL_TIM_Base_Init(tim) != HAL_OK)
326+
if (HAL_TIM_PWM_Init(tim) != HAL_OK)
327327
{
328-
LOG_E("%s time base init failed", device->name);
328+
LOG_E("%s pwm init failed", device->name);
329329
result = -RT_ERROR;
330330
goto __exit;
331331
}
@@ -338,13 +338,6 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
338338
goto __exit;
339339
}
340340

341-
if (HAL_TIM_PWM_Init(tim) != HAL_OK)
342-
{
343-
LOG_E("%s pwm init failed", device->name);
344-
result = -RT_ERROR;
345-
goto __exit;
346-
}
347-
348341
master_config.MasterOutputTrigger = TIM_TRGO_RESET;
349342
master_config.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
350343
if (HAL_TIMEx_MasterConfigSynchronization(tim, &master_config) != HAL_OK)
@@ -358,6 +351,8 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
358351
oc_config.Pulse = 0;
359352
oc_config.OCPolarity = TIM_OCPOLARITY_HIGH;
360353
oc_config.OCFastMode = TIM_OCFAST_DISABLE;
354+
oc_config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
355+
oc_config.OCIdleState = TIM_OCIDLESTATE_RESET;
361356

362357
/* config pwm channel */
363358
if (device->channel & 0x01)
@@ -551,7 +546,6 @@ static int stm32_pwm_init(void)
551546
/* register pwm device */
552547
if (rt_device_pwm_register(&stm32_pwm_obj[i].pwm_device, stm32_pwm_obj[i].name, &drv_ops, &stm32_pwm_obj[i].tim_handle) == RT_EOK)
553548
{
554-
555549
LOG_D("%s register success", stm32_pwm_obj[i].name);
556550
}
557551
else

0 commit comments

Comments
 (0)