1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141 |
-
-
- #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;
- SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
- }
- }
- #endif
- break;
- default:
- SystemCoreClock = HSI_VALUE;
- break;
- }
-
-
-
- tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
-
- SystemCoreClock >>= tmp;
- }
- static void SetSysClock(void)
- {
- #ifdef SYSCLK_FREQ_HSE
- SetSysClockToHSE();
- #elif defined SYSCLK_FREQ_24MHz
- SetSysClockTo24();
- #elif defined SYSCLK_FREQ_36MHz
- SetSysClockTo36();
- #elif defined SYSCLK_FREQ_48MHz
- SetSysClockTo48();
- #elif defined SYSCLK_FREQ_56MHz
- SetSysClockTo56();
- #elif defined SYSCLK_FREQ_72MHz
- SetSysClockTo72();
- #endif
-
-
-
- }
-
- #ifdef DATA_IN_ExtSRAM
-
- void SystemInit_ExtMemCtl(void)
- {
-
- RCC->AHBENR = 0x00000114;
-
-
- RCC->APB2ENR = 0x000001E0;
-
-
-
- GPIOD->CRL = 0x44BB44BB;
- GPIOD->CRH = 0xBBBBBBBB;
- GPIOE->CRL = 0xB44444BB;
- GPIOE->CRH = 0xBBBBBBBB;
- GPIOF->CRL = 0x44BBBBBB;
- GPIOF->CRH = 0xBBBB4444;
- GPIOG->CRL = 0x44BBBBBB;
- GPIOG->CRH = 0x44444B44;
-
-
-
- FSMC_Bank1->BTCR[4] = 0x00001011;
- FSMC_Bank1->BTCR[5] = 0x00000200;
- }
- #endif
- #ifdef SYSCLK_FREQ_HSE
- static void SetSysClockToHSE(void)
- {
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
-
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
-
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)0x01)
- {
- #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
-
- FLASH->ACR |= FLASH_ACR_PRFTBE;
-
- FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
- #ifndef STM32F10X_CL
- FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;
- #else
- if (HSE_VALUE <= 24000000)
- {
- FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;
- }
- else
- {
- FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
- }
- #endif
- #endif
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
-
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
- RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSE;
-
- while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x04)
- {
- }
- }
- else
- {
- }
- }
- #elif defined SYSCLK_FREQ_24MHz
- static void SetSysClockTo24(void)
- {
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
-
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
-
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)0x01)
- {
- #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
-
- FLASH->ACR |= FLASH_ACR_PRFTBE;
-
- FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
- FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;
- #endif
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
-
- #ifdef STM32F10X_CL
-
-
- RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
- RCC_CFGR_PLLMULL6);
-
-
- RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
- RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
- RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
- RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
-
-
- RCC->CR |= RCC_CR_PLL2ON;
-
- while((RCC->CR & RCC_CR_PLL2RDY) == 0)
- {
- }
- #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6);
- #else
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6);
- #endif
-
- RCC->CR |= RCC_CR_PLLON;
-
- while((RCC->CR & RCC_CR_PLLRDY) == 0)
- {
- }
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
- RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
-
- while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- }
- }
- #elif defined SYSCLK_FREQ_36MHz
- static void SetSysClockTo36(void)
- {
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
-
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
-
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)0x01)
- {
-
- FLASH->ACR |= FLASH_ACR_PRFTBE;
-
- FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
- FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
-
- #ifdef STM32F10X_CL
-
-
-
- RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
- RCC_CFGR_PLLMULL9);
-
-
-
- RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
- RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
- RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
- RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
-
-
- RCC->CR |= RCC_CR_PLL2ON;
-
- while((RCC->CR & RCC_CR_PLL2RDY) == 0)
- {
- }
-
- #else
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL9);
- #endif
-
- RCC->CR |= RCC_CR_PLLON;
-
- while((RCC->CR & RCC_CR_PLLRDY) == 0)
- {
- }
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
- RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
-
- while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- }
- }
- #elif defined SYSCLK_FREQ_48MHz
- static void SetSysClockTo48(void)
- {
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
-
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
-
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)0x01)
- {
-
- FLASH->ACR |= FLASH_ACR_PRFTBE;
-
- FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
- FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
-
- #ifdef STM32F10X_CL
-
-
-
-
- RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
- RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
- RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
- RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
-
-
- RCC->CR |= RCC_CR_PLL2ON;
-
- while((RCC->CR & RCC_CR_PLL2RDY) == 0)
- {
- }
-
-
-
- RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
- RCC_CFGR_PLLMULL6);
- #else
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);
- #endif
-
- RCC->CR |= RCC_CR_PLLON;
-
- while((RCC->CR & RCC_CR_PLLRDY) == 0)
- {
- }
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
- RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
-
- while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- }
- }
- #elif defined SYSCLK_FREQ_56MHz
- static void SetSysClockTo56(void)
- {
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
-
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
-
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)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)RCC_CFGR_HPRE_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
- #ifdef STM32F10X_CL
-
-
-
-
- RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
- RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
- RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
- RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
-
-
- RCC->CR |= RCC_CR_PLL2ON;
-
- while((RCC->CR & RCC_CR_PLL2RDY) == 0)
- {
- }
-
-
-
- RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
- RCC_CFGR_PLLMULL7);
- #else
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7);
- #endif
-
- RCC->CR |= RCC_CR_PLLON;
-
- while((RCC->CR & RCC_CR_PLLRDY) == 0)
- {
- }
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
- RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
-
- while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- }
- }
- #elif defined SYSCLK_FREQ_72MHz
- static void SetSysClockTo72(void)
- {
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
-
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
-
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)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)RCC_CFGR_HPRE_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
-
-
- RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
- #ifdef STM32F10X_CL
-
-
-
-
- RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
- RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
- RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
- RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
-
-
- RCC->CR |= RCC_CR_PLL2ON;
-
- while((RCC->CR & RCC_CR_PLL2RDY) == 0)
- {
- }
-
-
-
- RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
- RCC_CFGR_PLLMULL9);
- #else
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
- RCC_CFGR_PLLMULL));
- RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);
- #endif
-
- RCC->CR |= RCC_CR_PLLON;
-
- while((RCC->CR & RCC_CR_PLLRDY) == 0)
- {
- }
-
-
- RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
- RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
-
- while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- }
- }
- #endif
- static uint8_t fac_us=0;
- static uint16_t fac_ms=0;
- void delay_init(uint8_t SYSCLK)
- {
- SysTick->CTRL&=0xfffffffb;
- fac_us=SYSCLK/8;
- fac_ms=(uint16_t)fac_us*1000;
- }
- void delay_ms(uint16_t nms)
- {
- u32 temp;
- SysTick->LOAD=(u32)nms*fac_ms;
- SysTick->VAL =0x00;
- SysTick->CTRL=0x01 ;
- do
- {
- temp=SysTick->CTRL;
- }
- while(temp&0x01&&!(temp&(1<<16)));
- SysTick->CTRL=0x00;
- SysTick->VAL =0X00;
- }
- void delay_us(uint32_t nus)
- {
- u32 temp;
- SysTick->LOAD=nus*fac_us;
- SysTick->VAL=0x00;
- SysTick->CTRL=0x01 ;
- do
- {
- temp=SysTick->CTRL;
- }
- while(temp&0x01&&!(temp&(1<<16)));
- SysTick->CTRL=0x00;
- SysTick->VAL =0X00;
- }
-
-
|