Initialisation fails when using CubeMX and HSE clock source
This bug was introduced by CubeMX v4.20.
In SystemClock_Config() function, when HSE is selected it generates code:
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
Notice the OscillatorType filed is initialized for BOTH HSI and HSE, while later field HSIState is never set.
So you have two solutions:
- either remove RCC_OSCILLATORTYPE_HSI for the line to be like this:
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- or add HSIState field like this:
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
I hope they will fix this ASAP, as you have to edit SystemClock_Config() every time the project is regenerated..