2025-11-30 9:13 PM
Hello ST team and community,
I am working with STM32H755 and noticed a potential bug in the code generated by STM32CubeMX when handling the RCC_FLAG_D2CKRDY check during system initialization. CubeMX produces two variants of the loop:
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
if (timeout < 0)
{
Error_Handler();
}and
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
if (timeout < 0)
{
Error_Handler();
}The loop condition uses (timeout-- > 0).
This means the loop exits when timeout reaches 0, but never decrements below zero.
As a result, the check if (timeout < 0) will never be true, so Error_Handler() is never called — even if the D2 domain clock never becomes ready.
Since STM32H755 relies on proper synchronization between the Cortex‑M7 and Cortex‑M4 domains, missing this error condition can mask serious startup failures. Developers may assume the system initialized correctly when in fact the D2 domain clock never stabilized.
Could ST confirm whether this is a known issue in STM32CubeMX for STM32H7 series (specifically STM32H755)?
Thanks for your support!
Solved! Go to Solution.
2025-12-01 6:32 AM - edited 2025-12-01 6:32 AM
This works. "timeout--" will post-decrement and the value will be -1 after the loop exits. Try it. Compared to "--timeout" which will pre-decrement and not work here.
2025-12-01 1:45 AM
Hello @Duc
I'm currently checking this behavior. I will get back to you asap.
THX
Ghofrane
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-12-01 6:32 AM - edited 2025-12-01 6:32 AM
This works. "timeout--" will post-decrement and the value will be -1 after the loop exits. Try it. Compared to "--timeout" which will pre-decrement and not work here.