74 #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL)
76 #define SYSCLK_FREQ_24MHz 24000000
83 #define SYSCLK_FREQ_72MHz 72000000
88 #if defined (STM32F10X_HD) || (defined STM32F10X_XL)
111 #ifdef SYSCLK_FREQ_HSE
113 #elif defined SYSCLK_FREQ_24MHz
115 #elif defined SYSCLK_FREQ_36MHz
117 #elif defined SYSCLK_FREQ_48MHz
119 #elif defined SYSCLK_FREQ_56MHz
121 #elif defined SYSCLK_FREQ_72MHz
124 uint32_t SystemCoreClock = HSI_Value;
127 __I uint8_t
AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
136 static void SetSysClock(
void);
138 #ifdef SYSCLK_FREQ_HSE
139 static void SetSysClockToHSE(
void);
140 #elif defined SYSCLK_FREQ_24MHz
141 static void SetSysClockTo24(
void);
142 #elif defined SYSCLK_FREQ_36MHz
143 static void SetSysClockTo36(
void);
144 #elif defined SYSCLK_FREQ_48MHz
145 static void SetSysClockTo48(
void);
146 #elif defined SYSCLK_FREQ_56MHz
147 static void SetSysClockTo56(
void);
148 #elif defined SYSCLK_FREQ_72MHz
149 static void SetSysClockTo72(
void);
152 #ifdef DATA_IN_ExtSRAM
153 static void SystemInit_ExtMemCtl(
void);
176 RCC->CR |= (uint32_t)0x00000001;
180 RCC->CFGR &= (uint32_t)0xF8FF0000;
182 RCC->CFGR &= (uint32_t)0xF0FF0000;
186 RCC->CR &= (uint32_t)0xFEF6FFFF;
189 RCC->CR &= (uint32_t)0xFFFBFFFF;
192 RCC->CFGR &= (uint32_t)0xFF80FFFF;
196 RCC->CR &= (uint32_t)0xEBFFFFFF;
199 RCC->CIR = 0x00FF0000;
202 RCC->CFGR2 = 0x00000000;
203 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)
205 RCC->CIR = 0x009F0000;
208 RCC->CFGR2 = 0x00000000;
211 RCC->CIR = 0x009F0000;
214 #if defined (STM32F10X_HD) || (defined STM32F10X_XL)
215 #ifdef DATA_IN_ExtSRAM
216 SystemInit_ExtMemCtl();
233 uint32_t tmp = 0, pllmull = 0, pllsource = 0;
236 uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;
239 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)
240 uint32_t prediv1factor = 0;
261 pllmull = ( pllmull >> 18) + 2;
263 if (pllsource == 0x00)
270 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)
271 prediv1factor = (
RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
287 pllmull = pllmull >> 18;
298 if (pllsource == 0x00)
307 prediv1source =
RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
308 prediv1factor = (
RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
310 if (prediv1source == 0)
319 prediv2factor = ((
RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1;
320 pll2mull = ((
RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2;
344 static void SetSysClock(
void)
346 #ifdef SYSCLK_FREQ_HSE
348 #elif defined SYSCLK_FREQ_24MHz
350 #elif defined SYSCLK_FREQ_36MHz
352 #elif defined SYSCLK_FREQ_48MHz
354 #elif defined SYSCLK_FREQ_56MHz
356 #elif defined SYSCLK_FREQ_72MHz
370 #ifdef DATA_IN_ExtSRAM
380 void SystemInit_ExtMemCtl(
void)
386 RCC->AHBENR = 0x00000114;
389 RCC->APB2ENR = 0x000001E0;
397 GPIOD->CRL = 0x44BB44BB;
398 GPIOD->CRH = 0xBBBBBBBB;
400 GPIOE->CRL = 0xB44444BB;
401 GPIOE->CRH = 0xBBBBBBBB;
403 GPIOF->CRL = 0x44BBBBBB;
404 GPIOF->CRH = 0xBBBB4444;
406 GPIOG->CRL = 0x44BBBBBB;
407 GPIOG->CRH = 0x44444B44;
417 #ifdef SYSCLK_FREQ_HSE
425 static void SetSysClockToHSE(
void)
427 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
442 HSEStatus = (uint32_t)0x01;
446 HSEStatus = (uint32_t)0x00;
449 if (HSEStatus == (uint32_t)0x01)
452 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
496 #elif defined SYSCLK_FREQ_24MHz
504 static void SetSysClockTo24(
void)
506 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
521 HSEStatus = (uint32_t)0x01;
525 HSEStatus = (uint32_t)0x00;
528 if (HSEStatus == (uint32_t)0x01)
530 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
552 RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
557 RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
558 RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
559 RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
560 RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
563 RCC->CR |= RCC_CR_PLL2ON;
565 while((
RCC->CR & RCC_CR_PLL2RDY) == 0)
568 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)
571 RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1_Div2 |
RCC_CFGR_PLLMULL6);
600 #elif defined SYSCLK_FREQ_36MHz
608 static void SetSysClockTo36(
void)
610 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
625 HSEStatus = (uint32_t)0x01;
629 HSEStatus = (uint32_t)0x00;
632 if (HSEStatus == (uint32_t)0x01)
655 RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
661 RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
662 RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
663 RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
664 RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
667 RCC->CR |= RCC_CR_PLL2ON;
669 while((
RCC->CR & RCC_CR_PLL2RDY) == 0)
701 #elif defined SYSCLK_FREQ_48MHz
709 static void SetSysClockTo48(
void)
711 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
726 HSEStatus = (uint32_t)0x01;
730 HSEStatus = (uint32_t)0x00;
733 if (HSEStatus == (uint32_t)0x01)
756 RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
757 RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
758 RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
759 RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
762 RCC->CR |= RCC_CR_PLL2ON;
764 while((
RCC->CR & RCC_CR_PLL2RDY) == 0)
771 RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
802 #elif defined SYSCLK_FREQ_56MHz
810 static void SetSysClockTo56(
void)
812 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
827 HSEStatus = (uint32_t)0x01;
831 HSEStatus = (uint32_t)0x00;
834 if (HSEStatus == (uint32_t)0x01)
857 RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
858 RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
859 RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
860 RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
863 RCC->CR |= RCC_CR_PLL2ON;
865 while((
RCC->CR & RCC_CR_PLL2RDY) == 0)
872 RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
904 #elif defined SYSCLK_FREQ_72MHz
912 static void SetSysClockTo72(
void)
914 __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
929 HSEStatus = (uint32_t)0x01;
933 HSEStatus = (uint32_t)0x00;
936 if (HSEStatus == (uint32_t)0x01)
960 RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
961 RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
962 RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
963 RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
966 RCC->CR |= RCC_CR_PLL2ON;
968 while((
RCC->CR & RCC_CR_PLL2RDY) == 0)
975 RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |