Merge pull request #3337 from geniusgogo/fixed_drv_pwm

[STM32/drv_pwm.c]fixed PWM timer init.
This commit is contained in:
Bernard Xiong 2020-02-19 09:40:12 +08:00 committed by GitHub
commit 3bd9694c2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 11 deletions

View File

@ -205,7 +205,7 @@ static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration
tim_clock = HAL_RCC_GetPCLK1Freq() * 2; tim_clock = HAL_RCC_GetPCLK1Freq() * 2;
#endif #endif
} }
if (__HAL_TIM_GET_CLOCKDIVISION(htim) == TIM_CLOCKDIVISION_DIV2) if (__HAL_TIM_GET_CLOCKDIVISION(htim) == TIM_CLOCKDIVISION_DIV2)
{ {
tim_clock = tim_clock / 2; 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; tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
#endif #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; result = -RT_ERROR;
goto __exit; goto __exit;
} }
@ -338,13 +338,6 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
goto __exit; 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.MasterOutputTrigger = TIM_TRGO_RESET;
master_config.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; master_config.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(tim, &master_config) != HAL_OK) 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.Pulse = 0;
oc_config.OCPolarity = TIM_OCPOLARITY_HIGH; oc_config.OCPolarity = TIM_OCPOLARITY_HIGH;
oc_config.OCFastMode = TIM_OCFAST_DISABLE; oc_config.OCFastMode = TIM_OCFAST_DISABLE;
oc_config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
oc_config.OCIdleState = TIM_OCIDLESTATE_RESET;
/* config pwm channel */ /* config pwm channel */
if (device->channel & 0x01) if (device->channel & 0x01)
@ -551,7 +546,6 @@ static int stm32_pwm_init(void)
/* register pwm device */ /* 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) 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); LOG_D("%s register success", stm32_pwm_obj[i].name);
} }
else else