STM32 RCC 的用途

在第一次使用ARM STM32時看到KEIL C下的範例程式中的內容時,實在不知它的內容是作什麼用途的,因為和以往寫8051的經驗差異很大,當第一個研究是USART的程式碼時看到對於STM32F10x的初始化

/* System Clocks Configuration */
  RCC_Configuration();    
  /* NVIC configuration */
  NVIC_Configuration();
  /* Configure the GPIO ports */
  GPIO_Configuration();

初始化定義在於上面三個副程式中,而它們的縮寫及解釋如下所示。
RCC: reset and clock control 簡單的講就是時脈控制
NVIC :Nested vectored interrupt controller
GPIO:general-purpose I/O

而本篇要說明的是RCC,記得在STM32 F10xx 系統時鐘關連圖中的貼圖,現在看一下範例程式碼的內容。

/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();  /*這個函數是有很多內容的*/

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
 
  /* Enable GPIOA and USART1 clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
}

參考上面程式碼,你應該可以發現整個流程就如我在下圖中深紅色的箭頭的方向般的規劃。
其中 RCC_DeInit();   這個函數是有很多內容的,以後再來深入討論。






留言

這個網誌中的熱門文章

STM32 I2C-EEPROM 的讀寫

如何提高STM32 ADC的精度

ENC28J60+Uip TCP Server/Client