diff --git a/stmhal/servo.c b/stmhal/servo.c index 57f1eb5d18..2c94614207 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -29,7 +29,7 @@ STATIC const mp_obj_type_t servo_obj_type; STATIC pyb_servo_obj_t pyb_servo_obj[PYB_SERVO_NUM]; -TIM_HandleTypeDef servo_TIM2_Handle; +TIM_HandleTypeDef TIM2_Handle; void servo_init(void) { // TIM2 clock enable @@ -40,12 +40,12 @@ void servo_init(void) { HAL_NVIC_EnableIRQ(TIM2_IRQn); // PWM clock configuration - servo_TIM2_Handle.Instance = TIM2; - servo_TIM2_Handle.Init.Period = 2000; // timer cycles at 50Hz - servo_TIM2_Handle.Init.Prescaler = ((SystemCoreClock / 2) / 100000) - 1; // timer runs at 100kHz - servo_TIM2_Handle.Init.ClockDivision = 0; - servo_TIM2_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_PWM_Init(&servo_TIM2_Handle); + TIM2_Handle.Instance = TIM2; + TIM2_Handle.Init.Period = 2000; // timer cycles at 50Hz + TIM2_Handle.Init.Prescaler = ((SystemCoreClock / 2) / 100000) - 1; // timer runs at 100kHz + TIM2_Handle.Init.ClockDivision = 0; + TIM2_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; + HAL_TIM_PWM_Init(&TIM2_Handle); // reset servo objects for (int i = 0; i < PYB_SERVO_NUM; i++) { @@ -83,9 +83,9 @@ void servo_timer_irq_callback(void) { } } if (need_it) { - __HAL_TIM_ENABLE_IT(&servo_TIM2_Handle, TIM_IT_UPDATE); + __HAL_TIM_ENABLE_IT(&TIM2_Handle, TIM_IT_UPDATE); } else { - __HAL_TIM_DISABLE_IT(&servo_TIM2_Handle, TIM_IT_UPDATE); + __HAL_TIM_DISABLE_IT(&TIM2_Handle, TIM_IT_UPDATE); } } @@ -115,10 +115,10 @@ STATIC void servo_init_channel(pyb_servo_obj_t *s) { oc_init.Pulse = s->pulse_cur; // units of 10us oc_init.OCPolarity = TIM_OCPOLARITY_HIGH; oc_init.OCFastMode = TIM_OCFAST_DISABLE; - HAL_TIM_PWM_ConfigChannel(&servo_TIM2_Handle, &oc_init, channel); + HAL_TIM_PWM_ConfigChannel(&TIM2_Handle, &oc_init, channel); // start PWM - HAL_TIM_PWM_Start(&servo_TIM2_Handle, channel); + HAL_TIM_PWM_Start(&TIM2_Handle, channel); } /******************************************************************************/ diff --git a/stmhal/servo.h b/stmhal/servo.h index 277ccdd1c3..753ca49598 100644 --- a/stmhal/servo.h +++ b/stmhal/servo.h @@ -1,4 +1,4 @@ -extern TIM_HandleTypeDef servo_TIM2_Handle; +extern TIM_HandleTypeDef TIM2_Handle; void servo_init(void); void servo_timer_irq_callback(void); diff --git a/stmhal/stm32f4xx_hal_msp.c b/stmhal/stm32f4xx_hal_msp.c index a8587c384a..15dca56517 100644 --- a/stmhal/stm32f4xx_hal_msp.c +++ b/stmhal/stm32f4xx_hal_msp.c @@ -149,7 +149,7 @@ void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc) void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim == &TIM3_Handle) { USBD_CDC_HAL_TIM_PeriodElapsedCallback(); - } else if (htim == &servo_TIM2_Handle) { + } else if (htim == &TIM2_Handle) { servo_timer_irq_callback(); } } diff --git a/stmhal/stm32f4xx_it.c b/stmhal/stm32f4xx_it.c index cfd24dd331..bd324a030d 100644 --- a/stmhal/stm32f4xx_it.c +++ b/stmhal/stm32f4xx_it.c @@ -352,8 +352,7 @@ void RTC_WKUP_IRQHandler(void) { } void TIM2_IRQHandler(void) { - // servo timer is TIM2 - HAL_TIM_IRQHandler(&servo_TIM2_Handle); + HAL_TIM_IRQHandler(&TIM2_Handle); } void TIM3_IRQHandler(void) {