[stm32][driver] switch HAL_TIM_PWM_Init with HAL_TIM_Base_Init for new CubeMX

This commit is contained in:
Wu Han 2019-08-15 13:38:44 +08:00
parent 6a1e12f178
commit 2e90a7e5b2
1 changed files with 8 additions and 10 deletions

View File

@ -314,9 +314,6 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
tim = (TIM_HandleTypeDef *)&device->tim_handle; tim = (TIM_HandleTypeDef *)&device->tim_handle;
/* enable timer clock */
HAL_TIM_PWM_MspInit(tim);
/* configure the timer to pwm mode */ /* configure the timer to pwm mode */
tim->Init.Prescaler = 0; tim->Init.Prescaler = 0;
tim->Init.CounterMode = TIM_COUNTERMODE_UP; tim->Init.CounterMode = TIM_COUNTERMODE_UP;
@ -325,6 +322,14 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device)
#if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4)
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
#endif #endif
if (HAL_TIM_PWM_Init(tim) != HAL_OK)
{
LOG_E("%s pwm init failed", device->name);
result = -RT_ERROR;
goto __exit;
}
if (HAL_TIM_Base_Init(tim) != HAL_OK) if (HAL_TIM_Base_Init(tim) != HAL_OK)
{ {
LOG_E("%s time base init failed", device->name); LOG_E("%s time base init failed", device->name);
@ -340,13 +345,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)