Skip to content

Commit

Permalink
πŸ› Fix STM32 FastPWM
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 25, 2021
1 parent 0f7f709 commit 77af48e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Marlin/src/HAL/STM32/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 77af48e

Please sign in to comment.