This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32f103 Clock configuration problem

Hello,

Here is my code:

    #include <stdio.h>
    #include <string.h>
    #include "stm32f10x_gpio.h"
    #include "stm32f10x_rcc.h"
     
    void GPIOSYS(void){
    		GPIO_InitTypeDef GPIOStructure;
    	
    		RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
    		//GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);
    	
    	
    		GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
    	
    	
    		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
    		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
    	
    	
    			RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    		/* Output clock on MCO pin ---------------------------------------------*/
    		GPIOStructure.GPIO_Pin = GPIO_Pin_8;
    		GPIOStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    		GPIOStructure.GPIO_Speed = GPIO_Speed_50MHz;
    		GPIO_Init(GPIOA, &GPIOStructure);
     
    		GPIOStructure.GPIO_Mode=GPIO_Mode_Out_PP;
    		GPIOStructure.GPIO_Pin=GPIO_Pin_7 | GPIO_Pin_0 | GPIO_Pin_1 ;
    		GPIOStructure.GPIO_Speed=GPIO_Speed_50MHz;
    		GPIO_Init(GPIOB,&GPIOStructure);		
    		
    		GPIOStructure.GPIO_Mode=GPIO_Mode_Out_PP;
    		GPIOStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_10;
    		GPIOStructure.GPIO_Speed=GPIO_Speed_50MHz;
    		GPIO_Init(GPIOA,&GPIOStructure);
     
    	
    }
     
    void CLOCK(void){
    	
    	//RCC_DeInit(); 
    	
    	RCC_HSEConfig(RCC_HSE_ON);
    	
    	if(RCC_WaitForHSEStartUp()!=ERROR){
    	
    	RCC_HCLKConfig(RCC_SYSCLK_Div2);
    		
    	FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);	
    	FLASH_SetLatency(FLASH_Latency_2);
    		
    		
    	RCC_PLLCmd(DISABLE);	
    	RCC_PCLK1Config(RCC_HCLK_Div1);  						// APB1 Phrepheral 36Mhz, 
    	RCC_PCLK2Config(RCC_HCLK_Div1);  						//PCLK is 36Mhz		
    	RCC_PLLConfig(RCC_PLLSource_HSE_Div1,9);     //36Mhz
    	RCC_PLLCmd(ENABLE);
    	
    	while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)!=SET);
    	
    	FLASH_SetLatency(FLASH_Latency_2);
    	
    	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    	
    //	RCC_ClockSecuritySystemCmd(ENABLE);
    	
    	while (RCC_GetSYSCLKSource() != 0x08);
    	SystemCoreClockUpdate();
    	
    }
    	//else
    //	{
    //		GPIO_ResetBits(GPIOB,GPIO_Pin_0);
    //	}
     
    }
     
    void Delay(){
    	int i;
    	for(i=0;i<5;i++);
    }
     
    int main(void){
    	int i;
    		GPIOSYS();
    	CLOCK();
    	
    	GPIO_SetBits(GPIOA,GPIO_Pin_10);  //PC
    	GPIO_SetBits(GPIOB,GPIO_Pin_0); //UDP
    	GPIO_SetBits(GPIOB,GPIO_Pin_1); //UDP
    //	SysTick_Config(SystemCoreClock / (14000));
     
    	RCC_MCOConfig(RCC_MCO_SYSCLK);
    	
    	while(1){
    		//delay();
    			GPIO_SetBits(GPIOA,GPIO_Pin_10);  //PC
    			GPIO_SetBits(GPIOB,GPIO_Pin_0); //UDP
    			GPIO_SetBits(GPIOB,GPIO_Pin_1); //UDP
    		//delay();
    			GPIO_ResetBits(GPIOA,GPIO_Pin_10);  //PC
    			GPIO_ResetBits(GPIOB,GPIO_Pin_0);  //PC
    			GPIO_ResetBits(GPIOB,GPIO_Pin_1);  //PC
    		
      	}
    }
     
     
     
     
     
     

I have tried to set my MCU frequency to 36Mhz. However, on PA8 I see 72Mhz which is more than I wanted. I need to know what is my problem that the MCU frequency is not 36Mhz. In addition,when I use "RCC_DeInit(); " at the beginning of my clock configuration, I don't see anything at PA8.

 

it is necessary to change clock and make it safe (connected to HSI )when the external clock fails to 36Mhz (both mode should have the same frequency)