sysclock.h文件:
#ifndef __SYSCLOCK_H
#define __SYSCLOCK_H
#include "stm32f10x.h"
#define HSE_READY_OVERTIMR (uint32_t)0xFFF
void My_HSE_SetSysClock(void);
#endif
sysyclock.c文件:
#include "sysclock.h"
void My_HSE_SetSysClock(void)
{
uint32_t delay_time = 0;
uint32_t tmpreg = 0;
uint8_t status = 0;
RCC->CR |= (uint32_t)0x00010000;
do
{
tmpreg = RCC->CR & (uint32_t)0x00020000;
delay_time++;
}
while((delay_time != HSE_READY_OVERTIMR) && (tmpreg == 0));
if((RCC->CR & (uint32_t)0x00020000) != 0) status = 0x01;
else status = 0;
if(status == 0x01)
{
FLASH->ACR |= FLASH_ACR_PRFTBE;
FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;
RCC->CFGR |= (uint32_t)0x00000000;
RCC->CFGR |= (uint32_t)0x00000400;
RCC->CFGR |= (uint32_t)0x00000000;
RCC->CFGR &= ~(((uint32_t)0x01)<<16) | (((uint32_t)0x01)<<17) | (((uint32_t)0x0F)<<18);
RCC->CFGR |= (((uint32_t)0x01)<<16) | (((uint32_t)0x00)<<17) | (((uint32_t)0x07)<<18);
RCC->CR |= ((uint32_t)0x01)<<24;
while((RCC->CR & 0x02000000) == 0)
{
}
RCC->CFGR &= ~(uint32_t)0x03;
RCC->CFGR |= (uint32_t)0x02;
while((RCC->CFGR & 0x0000000C) != 0x08)
{
}
}
else
{
}
}
|