From 77af48e5479eb0840977fc6ad16f1b8ad651efd4 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Marlin/src/HAL/STM32/fast_pwm.cpp b/Marlin/src/HAL/STM32/fast_pwm.cpp
index 4986e138a1..99dc37dd7a 100644
--- a/Marlin/src/HAL/STM32/fast_pwm.cpp
+++ b/Marlin/src/HAL/STM32/fast_pwm.cpp
@@ -74,6 +74,8 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
   PinName pin_name = digitalPinToPinName(pin);
   TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance
 
+  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
@@ -83,11 +85,11 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
     #endif
   ) return;
 
-  if (HardwareTimer_Handle[index] == nullptr) // If frequency is set before duty we need to create a handle here. 
+  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));
   HT = (HardwareTimer *)(HardwareTimer_Handle[index]->__this);
   timer_freq[index] = f_desired; // Save the last frequency so duty will not set the default for this timer number.
-  HT->setOverflow(f_desired, HERTZ_FORMAT);   
+  HT->setOverflow(f_desired, HERTZ_FORMAT);
 }
 
 #endif // HAL_STM32