STM32F427 internal crystal initialization

Publisher:美丽花朵Latest update time:2018-06-27 Source: eefocusKeywords:STM32F427 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  1. void SystemHSIInit(void)  

  2. {  

  3.   /* FPU settings ------------------------------------------------------------*/  

  4.   #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)  

  5.     SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */  

  6.   #endif  

  7.   /* Reset the RCC clock configuration to the default reset state ------------*/  

  8.   /* Set HSION bit */  

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

  10.   

  11.   /* Reset CFGR register */  

  12.   RCC->CFGR = 0x00000000;  

  13.   

  14.   /* Reset HSEON, CSSON and PLLON bits */  

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

  16.   

  17.   /* Reset PLLCFGR register */  

  18.   RCC->PLLCFGR = 0x24003010;  

  19.   

  20.   /* Reset HSEBYP bit */  

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

  22.   

  23.   /* Disable all interrupts */  

  24.   RCC->CIR = 0x00000000;  

  25.   

  26. #if defined(DATA_IN_ExtSRAM) || defined(DATA_IN_ExtSDRAM)  

  27.   SystemInit_ExtMemCtl();   

  28. #endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */  

  29.            

  30.   /* Configure the System clock source, PLL Multiplier and Divider factors,  

  31.      AHB/APBx prescalers and Flash settings ----------------------------------*/  

  32.     {  

  33.    /******************************************************************************/  

  34.     /*            PLL (clocked by HSE) used as System clock source                */  

  35.     /******************************************************************************/  

  36.       __IO uint32_t StartUpCounter = 0, HSEStatus = 0;  

  37.         

  38.       /* Enable HSI */  

  39.       RCC->CR |= ((uint32_t)RCC_CR_HSION);  

  40.        

  41.       /* Wait till HSE is ready and if Time out is reached exit */  

  42.       do  

  43.       {  

  44.         HSEStatus = RCC->CR & RCC_CR_HSIRDY;  

  45.         StartUpCounter++;  

  46.       } while((HSEStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));  

  47.       

  48.       if ((RCC->CR & RCC_CR_HSIRDY) != RESET)  

  49.       {  

  50.         HSEStatus = (uint32_t)0x01;  

  51.       }  

  52.       else  

  53.       {  

  54.         HSEStatus = (uint32_t)0x00;  

  55.       }  

  56.       

  57.       if (HSEStatus == (uint32_t)0x01)  

  58.       {  

  59.         /* Select regulator voltage output Scale 1 mode */  

  60.         RCC->APB1ENR |= RCC_APB1ENR_PWREN;  

  61.         PWR->CR |= PWR_CR_VOS;  

  62.       

  63.         /* HCLK = SYSCLK / 1*/  

  64.         RCC->CFGR |= RCC_CFGR_HPRE_DIV1;  

  65.       

  66.        /* PCLK2 = HCLK / 2*/  

  67.         RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;  

  68.           

  69.         /* PCLK1 = HCLK / 4*/  

  70.         RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;  

  71.      

  72.         /* Configure the main PLL */  

  73.         RCC->PLLCFGR = 16 | (336 << 6) | (((2 >> 1) -1) << 16) |  (RCC_PLLCFGR_PLLSRC_HSE) | (7 << 24);  

  74.           

  75.         /* Enable the main PLL */  

  76.         RCC->CR |= RCC_CR_PLLON;  

  77.       

  78.         /* Wait till the main PLL is ready */  

  79.         while((RCC->CR & RCC_CR_PLLRDY) == 0)  

  80.         {  

  81.         }  

  82.          

  83.         /* Enable the Over-drive to extend the clock frequency to 180 Mhz */  

  84.         PWR->CR |= PWR_CR_ODEN;  

  85.         while((PWR->CSR & PWR_CSR_ODRDY) == 0)  

  86.         {  

  87.         }  

  88.         PWR->CR |= PWR_CR_ODSWEN;  

  89.         while((PWR->CSR & PWR_CSR_ODSWRDY) == 0)  

  90.         {  

  91.         }        

  92.         /* Configure Flash prefetch, Instruction cache, Data cache and wait state */  

  93.         FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;  

  94.           

  95.         /* Select the main PLL as system clock source */  

  96.         RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));  

  97.         RCC->CFGR |= RCC_CFGR_SW_PLL;  

  98.       

  99.         /* Wait till the main PLL is used as system clock source */  

  100.         while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);  

  101.         {  

  102.         }  

  103.       }  

  104.       else  

  105.       { /* If HSE fails to start-up, the application will have wrong clock 

  106.              configuration. User can add here some code to deal with this error */  

  107.       }  

  108.   

  109.     }  

  110.   

  111.   /* Configure the Vector Table location add offset address ------------------*/  

  112.   SCB->VTOR = FLASH_BASE | 0x00; /* Vector Table Relocation in Internal FLASH */  

  113.   

  114. }  



Keywords:STM32F427 Reference address:STM32F427 internal crystal initialization

Previous article:STM32F4 modify crystal frequency
Next article:STM32 timer external counting mode maximum frequency calculation.

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号