diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c index e1078b5d206ef542aa7fa83376bc8ec6f3eaf620..247c8f88fe946180c981d1b9f7d8b89d6111758c 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c @@ -314,9 +314,6 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device) tim = (TIM_HandleTypeDef *)&device->tim_handle; - /* enable timer clock */ - HAL_TIM_PWM_MspInit(tim); - /* configure the timer to pwm mode */ tim->Init.Prescaler = 0; tim->Init.CounterMode = TIM_COUNTERMODE_UP; @@ -325,24 +322,25 @@ static rt_err_t stm32_hw_pwm_init(struct stm32_pwm *device) #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) 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; } - clock_config.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(tim, &clock_config) != HAL_OK) + if (HAL_TIM_Base_Init(tim) != HAL_OK) { - LOG_E("%s clock init failed", device->name); + LOG_E("%s time base init failed", device->name); result = -RT_ERROR; goto __exit; } - if (HAL_TIM_PWM_Init(tim) != HAL_OK) + clock_config.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(tim, &clock_config) != HAL_OK) { - LOG_E("%s pwm init failed", device->name); + LOG_E("%s clock init failed", device->name); result = -RT_ERROR; goto __exit; }