cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107VC How to set up an Clock with HSE

felix239955_stm1
Associate
Posted on December 20, 2015 at 12:30

Hello everyone 

I have an Evaluation Board from Thailand (No example projects found), with an STM32F107VC. Now I'd like to select the on board 25MHz oscillator as clock-source.

As it is the first time for me to set up a Clocksource I tried to make the code on my own and to compare it with the code produced by the STMCubeMX. The thing is, I actually dont want to use the Cube as I dont like the HAL-Library. Furthermore I want to learn how to make it myself, where the Standard Peripheral Library fits better in my Ideas.

Here is the Code i wrote myself:

//Flash Settings

FLASH_SetLatency(FLASH_Latency_2);

//Configs

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PCLK1Config(RCC_HCLK_Div2);

RCC_PCLK2Config(RCC_HCLK_Div1);

//Enable HSE, Pre-Div's and PLL's and Flags

RCC_HSEConfig(RCC_HSE_ON);

while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) {}

RCC_PREDIV2Config(5);

RCC_PLL2Config(14);

while(RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET) {}

RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2,8);

RCC_PLLConfig(RCC_PLLSource_PREDIV1,8);

RCC_PLLCmd(ENABLE);

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

Sadly the product wasnt that good. Several register as the RCC_CR, CFGR or the CFGR2 have been set wrong. Wrong means for example PREDIV1 was 5 instead of 8 and so on.

Id be really thankful if someone could tell me what is wrong with my code and perhaps explain what the correct order is to set up the register. Another thing Id like to know is, if it is necessary to check the flags if I enable the HSE or the PLL. I have seen projects from other people where they checked either one or the other flag. 

Strange was also that the Cube enabled me the PLL3 but I dont use this dude, do I?

Finally, when do I have to enable the ADC or DMA clock. Can I do this afterwards?

Greetings

Felix

#!stm32-!clock
1 REPLY 1
Posted on December 20, 2015 at 17:01

STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.c

Pass STM32F10X_CL as a command line define.

And look also at the STM3210C-EVAL board project builds within the examples

STM32F10x_StdPeriph_Lib_V3.5.0\Utilities\STM32_EVAL\STM3210C_EVAL\stm3210c_eval.c

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..