void Stm32_Clock_Init(uint8_t SW,uint8_t PLLSRC,uint8_t PLLXTPRE,uint8_t PLLMUL,uint8_t HPRE,uint8_t PPRE1,uint8_t PPRE2,uint8_t Latency)
{
unsigned char temp=0;
RCC_DeInit();
if(SW == 00)
{
RCC->CR |= 0x00000001;
while(!((RCC->CR>>1) & 0x01));
}
else if(SW == 01)
{
RCC->CR |= 0x00010000;
while(!((RCC->CR>>17) & 0x01));
RCC->CR |= 0x00080000;
}
else if(SW == 10)
{
if(PLLSRC)
{
RCC->CR |= 0x00010000;
while(!((RCC->CR>>17) & 0x01));
RCC->CR |= 0x00080000;
RCC->CFGR |= PLLMUL<CFGR |= 1<CR |= PLLXTPRE<CR|=0x01000000;
while(!(RCC->CR>>25));
}
else
{
RCC->CR |= 0x00000001;
while(!((RCC->CR>>1) & 0x01));
RCC->CFGR |= PLLMUL<CR|=0x01000000;
while(!(RCC->CR>>25));
}
FLASH->ACR |= 0x30 + Latency;
RCC->CFGR |= HPRE<CFGR |= PPRE1<CFGR |= PPRE2<CFGR |= SW;
while(temp != SW)
{
temp = ((RCC->CFGR>>2) & 0x03);
}
}
}
1