微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 启动过程都在这个文件的开头描述了system_stm32f10x.c

启动过程都在这个文件的开头描述了system_stm32f10x.c

时间:11-27 来源:互联网 点击:
#include "stm32f10x.h"

#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)

#define SYSCLK_FREQ_24MHz 24000000

#else

#define SYSCLK_FREQ_72MHz 72000000

#endif

#if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)

#endif

#define VECT_TAB_OFFSET 0x0

#ifdef SYSCLK_FREQ_HSE

uint32_t SystemCoreClock = SYSCLK_FREQ_HSE;

#elif defined SYSCLK_FREQ_24MHz

uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz;

#elif defined SYSCLK_FREQ_36MHz

uint32_t SystemCoreClock = SYSCLK_FREQ_36MHz;

#elif defined SYSCLK_FREQ_48MHz

uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz;

#elif defined SYSCLK_FREQ_56MHz

uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz;

#elif defined SYSCLK_FREQ_72MHz

uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz;

#else

uint32_t SystemCoreClock = HSI_VALUE;

#endif

__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};

static void SetSysClock(void);

#ifdef SYSCLK_FREQ_HSE

static void SetSysClockToHSE(void);

#elif defined SYSCLK_FREQ_24MHz

static void SetSysClockTo24(void);

#elif defined SYSCLK_FREQ_36MHz

static void SetSysClockTo36(void);

#elif defined SYSCLK_FREQ_48MHz

static void SetSysClockTo48(void);

#elif defined SYSCLK_FREQ_56MHz

static void SetSysClockTo56(void);

#elif defined SYSCLK_FREQ_72MHz

static void SetSysClockTo72(void);

#endif

#ifdef DATA_IN_ExtSRAM

static void SystemInit_ExtMemCtl(void);

#endif

void SystemInit (void)

{

RCC->CR |= (uint32_t)0x00000001;

#ifndef STM32F10X_CL

RCC->CFGR &= (uint32_t)0xF8FF0000;

#else

RCC->CFGR &= (uint32_t)0xF0FF0000;

#endif

RCC->CR &= (uint32_t)0xFEF6FFFF;

RCC->CR &= (uint32_t)0xFFFBFFFF;

RCC->CFGR &= (uint32_t)0xFF80FFFF;

#ifdef STM32F10X_CL

RCC->CR &= (uint32_t)0xEBFFFFFF;

RCC->CIR = 0x00FF0000;

RCC->CFGR2 = 0x00000000;

#elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)

RCC->CIR = 0x009F0000;

RCC->CFGR2 = 0x00000000;

#else

RCC->CIR = 0x009F0000;

#endif

#if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)

#ifdef DATA_IN_ExtSRAM

SystemInit_ExtMemCtl();

#endif

#endif

SetSysClock();

#ifdef VECT_TAB_SRAM

SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET;

#else

SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET;

#endif

}

void SystemCoreClockUpdate (void)

{

uint32_t tmp = 0, pllmull = 0, pllsource = 0;

#ifdef STM32F10X_CL

uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;

#endif

#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)

uint32_t prediv1factor = 0;

#endif

tmp = RCC->CFGR & RCC_CFGR_SWS;

switch (tmp)

{

case 0x00:

SystemCoreClock = HSI_VALUE;

break;

case 0x04:

SystemCoreClock = HSE_VALUE;

break;

case 0x08:

pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;

pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;

#ifndef STM32F10X_CL

pllmull = ( pllmull >> 18) + 2;

if (pllsource == 0x00)

{

SystemCoreClock = (HSI_VALUE >> 1) * pllmull;

}

else

{

#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)

prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREdiv1) + 1;

SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;

#else

if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)

{

SystemCoreClock = (HSE_VALUE >> 1) * pllmull;

}

else

{

SystemCoreClock = HSE_VALUE * pllmull;

}

#endif

}

#else

pllmull = pllmull >> 18;

if (pllmull != 0x0D)

{

pllmull += 2;

}

else

{

pllmull = 13 / 2;

}

if (pllsource == 0x00)

{

SystemCoreClock = (HSI_VALUE >> 1) * pllmull;

}

else

{

prediv1source = RCC->CFGR2 & RCC_CFGR2_PREdiv1SRC;

prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREdiv1) + 1;

if (prediv1source == 0)

{

SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;

}

else

{

prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREdiv2) >> 4) + 1;

pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top