Skip to main content
Associate II
Apr 27, 2026 5:30 AM UTC
Solved

STSPIN32G4 gets stuck in an infinite while loop inside R3_2_SwitchOffPWM() during the motor control

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)

GMA
GMABest answer
ST Technical Moderator
Apr 27, 2026 1:21 PM UTC

Hello @Raj6135,

Does MCSDK_v6.4.2-Full folder present in ~/STM32Cube/Repository? If not, uninstall and reinstall MCSDK6.4.2.
Generate a new project (do not use a previously use directory).
Generated .ioc file should contain "ExtraMW.MotorControl.Root=MCSDK_v6.4.2-Full/MotorControl".

STM32CubeMX v6.17.0 is recommended for MCSDK6.4.2 (refer to MCSDK release note for more details).

If you agree with the answer, please accept it by clicking on 'Best answer'.Best regards.GMA

3 replies

GMA
ST Technical Moderator
Apr 27, 2026 9:21 AM UTC

Hello @Raj6135,

Project has been generated with MCSDK6.4.2, but on your ioc file "ExtraMW.MotorControl.Root=MCSDK_v5.4.8-Full/MotorControl" and in the project directory there is MCSDK_v5.4.8-Full.
Did you modify the wb2mx.properties file?

If you agree with the answer, please accept it by clicking on 'Best answer'.Best regards.GMA
Raj6135Author
Associate II
Apr 27, 2026 10:20 AM UTC

Thank you for the reply, @GMA. I did not modify any project files; however, there are multiple versions installed on my computer (as listed in the attached image).

Raj6135_0-1777285177467.png

 

GMA
GMABest answer
ST Technical Moderator
Apr 27, 2026 1:21 PM UTC

Hello @Raj6135,

Does MCSDK_v6.4.2-Full folder present in ~/STM32Cube/Repository? If not, uninstall and reinstall MCSDK6.4.2.
Generate a new project (do not use a previously use directory).
Generated .ioc file should contain "ExtraMW.MotorControl.Root=MCSDK_v6.4.2-Full/MotorControl".

STM32CubeMX v6.17.0 is recommended for MCSDK6.4.2 (refer to MCSDK release note for more details).

If you agree with the answer, please accept it by clicking on 'Best answer'.Best regards.GMA