cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 CubeMX critical codegeneration bug (RCC+LL)

Wolfgang Pupp
Associate III

Bug:

CubeMX codegeneration for the RCC (clock module) may lead to hardfault during clock initialization.

I have a minimal example IOC (attached).

This faults during RCC initialization (in SystemClock_Config), after LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);

This happens because the peripheral domain prescalers need to be increased BEFORE switching to the faster clock (AFAICT), this would mean moving LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1) toward the end of the function (after LL_RCC_SetAPB4Prescaler).

This is right now 100% reproducible for me, but I suspect that instruction prefetching can potentially hide/sidestep the problem: If I enable -Os optimization flags, then the problem vanishes depending on how many __NOP() instructions (0-3) are inserted directly before LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);.

Best way to reproduce the hardfault is single-instruction-stepping over this section with the debugger (that catches it every time for me).

Workaround:

Use HAL layer instead.

Occurred with STM32H730VBH in CubeMX v6.3.0, but I'd assume that other controllers and older CubeMX versions are also affected.

1 ACCEPTED SOLUTION

Accepted Solutions
Khouloud ZEMMELI
ST Employee

Hi again @Wolfgang Pupp​ ,

I have checked from my side, and I confirm the issue, you have right.

Sorry for any inconvenient that may have caused and thanks for raising this issue to our attention, it will be fixed.

Khouloud

View solution in original post

2 REPLIES 2
Khouloud ZEMMELI
ST Employee

Hello @Wolfgang Pupp​ ,

Thank you for your post,

I'll check it then I'll get back to you.

Khouloud

Khouloud ZEMMELI
ST Employee

Hi again @Wolfgang Pupp​ ,

I have checked from my side, and I confirm the issue, you have right.

Sorry for any inconvenient that may have caused and thanks for raising this issue to our attention, it will be fixed.

Khouloud