summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxieyangrun <[email protected]>2020-01-15 13:45:30 +0800
committerxieyangrun <[email protected]>2020-01-15 13:45:30 +0800
commitd2a857e13a97f50559d0b88a983d902f422e2fc9 (patch)
tree0d23c5e5046e7460a89ac0b759c500f0f67d66e4
parentcad32a326ce5774044837197fe566f0d5bd69ca9 (diff)
[STM32/drv_pwm.c]fixed PWM timer init.
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_pwm.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c
index 2c2af0dcc0..23efb88df6 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c
@@ -205,7 +205,7 @@ static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration
tim_clock = HAL_RCC_GetPCLK1Freq() * 2;
#endif
}
-
+
if (__HAL_TIM_GET_CLOCKDIVISION(htim) == TIM_CLOCKDIVISION_DIV2)
{
tim_clock = tim_clock / 2;
@@ -323,9 +323,9 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
#endif
- if (HAL_TIM_Base_Init(tim) != HAL_OK)
+ if (HAL_TIM_PWM_Init(tim) != HAL_OK)
{
- LOG_E("%s time base init failed", device->name);
+ LOG_E("%s pwm init failed", device->name);
result = -RT_ERROR;
goto __exit;
}
@@ -338,13 +338,6 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
goto __exit;
}
- if (HAL_TIM_PWM_Init(tim) != HAL_OK)
- {
- LOG_E("%s pwm init failed", device->name);
- result = -RT_ERROR;
- goto __exit;
- }
-
master_config.MasterOutputTrigger = TIM_TRGO_RESET;
master_config.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
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)
oc_config.Pulse = 0;
oc_config.OCPolarity = TIM_OCPOLARITY_HIGH;
oc_config.OCFastMode = TIM_OCFAST_DISABLE;
+ oc_config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
+ oc_config.OCIdleState = TIM_OCIDLESTATE_RESET;
/* config pwm channel */
if (device->channel & 0x01)
@@ -551,7 +546,6 @@ static int stm32_pwm_init(void)
/* register pwm device */
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)
{
-
LOG_D("%s register success", stm32_pwm_obj[i].name);
}
else