SystemInit

(1)SystemInit(): This function is called at startup just after reset and before branch to main program. 

This call is made inside the "startup_stm32f3xx.s" file.


(2)SystemCoreClock variable: Contains the core clock (HCLK), it can be used by the user application to setup the SysTick timer or configure other parameters.


(3)SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution.


 2. After each device reset, the HSI (8 MHz) is used as system clock source.

Then SystemInit() function is called, in "startup_stm32f3xx.s" file, to configure the system clock before to branch to main program.


void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
  #endif


  /* Reset the RCC clock configuration to the default reset state ------------*/
  /* Set HSION bit */
  RCC->CR |= 0x00000001U;


  /* Reset CFGR register */
  RCC->CFGR &= 0xF87FC00CU; //1111_1000_0111_1111   1100_0000_0000_1100


  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= 0xFEF6FFFFU; //1111_1110_1111_0110 1111_1111_1111_1111


  /* Reset HSEBYP bit */
  RCC->CR &= 0xFFFBFFFFU; //1111_1111_1111_1011 1111_1111_1111_1111


  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE bits */
  RCC->CFGR &= 0xFF80FFFFU; //1111_1111_1000_0000 1111_1111_1111_1111


  /* Reset PREDIV1[3:0] bits */
  RCC->CFGR2 &= 0xFFFFFFF0U; //1111_1111_1111_1111 1111_1111_1111_0000


  /* Reset USARTSW[1:0], I2CSW and TIMs bits */
  RCC->CFGR3 &= 0xFF00FCCCU; //1111_1111_0000_0000 1111_1100_1100_1100


  /* Disable all interrupts */
  RCC->CIR = 0x00000000U;


#ifdef VECT_TAB_SRAM
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}



你可能感兴趣的:(STM32学习)