cancel
Showing results for 
Search instead for 
Did you mean: 

Clock settings in CubeMX 4.6 doesn't work for F072

jesper
Associate II
Posted on March 22, 2015 at 10:45

I am using CubeMX 4.6.0 with STM32Cube FW 1.2.1 for a STM32F072 chip.

I am having trouble getting the clock settings code to work properly. I have activated some ADC features in CubeMX, which turns on the HSI14 clock. This is fine. But it mixes HSI14 with the system clock in a strange way. If I start with selecting HSI as the clock source in CubeMX, the following code is generated:

void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
__SYSCFG_CLK_ENABLE();
}

This code fails at the HAL_RCC_OscConfig() call, the CPU dies and has to be full-chip erased to start communicating again. If I remove the RCC_OSCILLATORTYPE_HSI14 argument to OscillatorType, the problem disappears and the code works just fine. So I suspect this is an error in the CubeMX generator??? Now if I select HSI48 as the System Clock in CubeMX, the following code is generated:

void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
__SYSCFG_CLK_ENABLE();
}

Again I remove RCC_OSCILLATORTYPE_HSI14 from OscillatorType, but now this doesn't help, the CPU still fails at the HAL_RCC_OscConfig() call. So now should I suspect a firmware problem??? The specific code which fails in the 48MHz case is the

__HAL_RCC_HSI48_ENABLE()

macro in stm32f0xx_hal_rcc_ex.c:498 in

HAL_RCC_OscConfig()

. I can single step up to this point, but when uit is run the CPU loses contact with the debugger. #stm32cube #clock #stm32cubemx
2 REPLIES 2
henrik2399
Associate II
Posted on March 23, 2015 at 22:30

@ST: May I add, the clock code generation for STM32F103 seems also not to work.

The system_stm32f1xx.c file is not created, only the template in the CMSIS/Device/STM.. Path, but the template does not have the settings that were set in CubeMX. Or is the new HAL_RCC_OscConfig supposed to do the same, but what is the template then good for?

@OP: There used to be Excelfiles around that could generate the system_xxx.c file you need for your clock settings.
Amel NASRI
ST Employee
Posted on March 30, 2015 at 10:37

Hello,

The current CubeMX version is 4.7.0 (4.5.0 is wrongly displayed now in the web, it will be soon fixed).

This version is supporting much more products & many bugs are fixed. Please check if you still facing reported issues with this version.

-Mayla-

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.