AnsweredAssumed Answered

STM32F107VC How to set up an Clock with HSE

Question asked by crazzolara.felix on Dec 20, 2015
Latest reply on Dec 20, 2015 by Clive One
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

Outcomes