From 7ffada64ceb4d8e5a2ca1e7a75638a3bb6be6cf4 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 30 Nov 2021 13:03:31 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20STM32=20FastPWM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/STM32/fast_pwm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/STM32/fast_pwm.cpp b/Marlin/src/HAL/STM32/fast_pwm.cpp index 8eaecd718e..d28bc1b84b 100644 --- a/Marlin/src/HAL/STM32/fast_pwm.cpp +++ b/Marlin/src/HAL/STM32/fast_pwm.cpp @@ -71,6 +71,8 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255 void set_pwm_frequency(const pin_t pin, int f_desired) { if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer + const PinName pin_name = digitalPinToPinName(pin); + TIM_TypeDef * const Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance uint32_t index = get_timer_index(Instance); // Protect used timers @@ -80,8 +82,6 @@ void set_pwm_frequency(const pin_t pin, int f_desired) { #endif ) return; - const PinName pin_name = digitalPinToPinName(pin); - TIM_TypeDef * const Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance if (HardwareTimer_Handle[index] == nullptr) // If frequency is set before duty we need to create a handle here. HardwareTimer_Handle[index]->__this = new HardwareTimer((TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM)); HardwareTimer * const HT = (HardwareTimer *)(HardwareTimer_Handle[index]->__this);