STSPIN32G4 gets stuck in an infinite while loop inside R3_2_SwitchOffPWM() during the motor control
- April 27, 2026
- 1 reply
- 71 views
I'm running into an issue where my STM32G4 gets stuck in an infinite while loop inside R3_2_SwitchOffPWM() during the motor control initialisation sequence, and I wanted to share it here in case others have encountered the same thing.
---
Hardware & Software
- Board: EVSPIN32G4
- Code generation tool: ST Motor Control Workbench v6.4.2
- No manual edits made to any generated files
---
What happens
During startup, MX_MotorControl_Init() is called from main(), which triggers MCboot() → FOC_Clear() → PWMC_SwitchOffPWM() → R3_2_SwitchOffPWM(). Inside that function, execution enters this loop and never exits:
/* wait for a new PWM period to flush last HF task */
LL_TIM_ClearFlag_UPDATE(TIMx);
while (LL_TIM_IsActiveFlag_UPDATE(TIMx) == 0u)
{}
LL_TIM_ClearFlag_UPDATE(TIMx);
(Project Files attached)
