2026-04-26 10:30 PM
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)
Solved! Go to Solution.
2026-04-27 6:21 AM
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).
2026-04-27 2:21 AM
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?
2026-04-27 3:20 AM
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).
2026-04-27 6:21 AM
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).