Recently I have discovered a serious bug in the new version of STM32CubeMX. It considers the clock configuration but does not always appears and is hard to debug.
The problem with version 4.25 of STM32CubeMX is quite problematic. The code generated with the software does not properly initialize the PLL of the MCU which leads to the calling the _Error_Handler() function. The core of the problem lies within uninitialized local variable:
When the MCU is supposed to use PLL there are a handful of coefficients which divide and multiply input clock signal. One of them is M coefficient which divides the input source clock. When this is selected as 1 then the CubeMX does not generate proper initialization of the field in RCC_OscInitTypeDef structure. This was showed below in screen shoot:
Notice that when HAL_RCC_OscConfig(&RCC_OscInitStruct) function in if statement is being called the RCC_OscInitStruct.PLL.PLLM value is nowhere near to the correct value — it is completely out of range. This is because the RCC_OscInitStruct is a local variable and is not initialized. What is more important depending on the output code the value can change and sometimes, with very low probability, can be good or at least in the range. To fix this problem it is required to manually add following line:
RCC_OscInitStruct.PLL.PLLM = 1;
This fixes the bug but every time the code is regenerated it has to be manually applied. Now, the program behaves as it should:
ST was already notified about my discovery. If I get a response I will update the post so stay tuned.
ST released a new version of STM32CubeMX v4.25.1.