AnsweredAssumed Answered

[BUG] CubeMX v4.20 RCC Initialization Fail with HSE selected

Question asked by Alexander Olenyev on Mar 10, 2017
Latest reply on Apr 6, 2017 by Khouloud G

Hello! Recent update of CubeMX v4.20 introduced a bug in SystemClock_Config() function which cause HAL_RCC_OscConfig() fail. I am using STM32F103C8T6 chip with SW4STM32 v1.14 under Windows 10.

 

In previous releases of CubeMX (v4.19 and older), when HSE turned on for Crystal\Ceramic Resonator the following code was generated as part of SystemClock_Config(): 

 

RCC_OscInitTypeDef RCC_OscInitStruct;

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;
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();
}

 

In v4.20 the same part of code (generated by same .ioc file) looks like this:

 

RCC_OscInitTypeDef RCC_OscInitStruct;

/**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;

// no HSIState field setting
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 that OscillatorType now has both HSI and HSE (which I think is wrong in the first place) and since the field HSIState is never set to RCC_HSI_ON, the HAL_RCC_OscConfig() returns HAL_ERROR, the chip then falls into Error_Handler().

 

Please fix this ASAP, as it is really painful to manually fix SystemClock_Config() every time the project is regenerated.

Thanks!

Outcomes