自己的STM32F407各个时钟是多少?

用stm32cube生成工程的时候,要配置各个时钟,之前一直沿用的模板例程,所以还真不知道各个时钟到底是多少。上图,这是要配置的,可是自己程序配置的是怎样呢?

接下来,看程序,程序开始

1 startup_stm32f40_41xxx.s 

 1 Reset_Handler    PROC
 2                  EXPORT  Reset_Handler             [WEAK]
 3         IMPORT  SystemInit
 4         IMPORT  __main
 5 
 6                  LDR     R0, =SystemInit
 7                  BLX     R0
 8                  LDR     R0, =__main
 9                  BX      R0
10                  ENDP

在进入main函数之前,系统调用了SystemInit函数.

2 system_stm32f4xx.c

在SystemInit里截取一段程序

1   /* Configure the System clock source, PLL Multiplier and Divider factors, 
2      AHB/APBx prescalers and Flash settings ----------------------------------*/
3   SetSysClock();

注释:配置系统时钟源,....

进入SetSysClock();

 1 static void SetSysClock(void)
 2 {
 3    ....
 4   
 5     /* HCLK = SYSCLK / 1*/
 6     RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
 7 
 8 
 9    #if defined (STM32F40_41xxx) || defined (STM32F427_437xx) ||     defined (STM32F429_439xx)      
10     /* PCLK2 = HCLK / 2*
11     RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
12     
13     /* PCLK1 = HCLK / 4*/
14     RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
15 #endif /* STM32F40_41xxx || STM32F427_437x || STM32F429_439xx */
16    ....
17        /* Configure the main PLL */
18     RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
19                    (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
20 
21     /* Enable the main PLL */
22     RCC->CR |= RCC_CR_PLLON;
23 }

可以知道HCLK = SYSCLK/1,PCLK2 = HCLK / 2,PCLK1 = HCLK / 4。接下来就和M,P,Q有关了

这些值在前边有define,以我的工程为例

 1 ....
 2 #if defined (STM32F40_41xxx) || defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F401xx)
 3 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
 4 #define PLL_M      8
 5 #else /* STM32F411xE */
 6 ......
 7 /* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */
 8 #define PLL_Q      7
 9 
10 #if defined (STM32F40_41xxx)
11 #define PLL_N      336
12 /* SYSCLK = PLL_VCO / PLL_P */
13 #define PLL_P      2
14 #endif /* STM32F40_41xxx */
15 ....

至此就差一项还不知道了,就是外部晶振频率,它在stm32f4xx.h中有定义,

#if !defined  (HSE_VALUE) 
  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
  
#endif /* HSE_VALUE */

/**
 * @brief In the following line adjust the External High Speed oscillator (HSE) Startup 
   Timeout value 
   */
#if !defined  (HSE_STARTUP_TIMEOUT) 
  #define HSE_STARTUP_TIMEOUT    ((uint16_t)0x05000)   /*!< Time out for HSE start up */
#endif /* HSE_STARTUP_TIMEOUT */   

#if !defined  (HSI_VALUE)   
  #define HSI_VALUE    ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */   

综合这些,就可以刻第一幅图对应起来了。

 

posted @ 2017-04-12 14:05  不明白就去明白  阅读(6227)  评论(0编辑  收藏  举报