powder-320203 发表于 2016-4-15 20:17:40

stm32f4xx需要初始化主频吗?

stm32f1xx我们知道是需要MRCC_Init();初始化主频的。stm32f4xx需要初始化主频吗?现在st管网上很难下载到固件例程,这里请大侠帮帮忙。谢谢!

Angel_YY 发表于 2018-3-9 14:36:57

STM32F4启动与STM32F10X不同,时钟已经默认配置好。
STM32F4的启动文件:startup_stm32f4xx.s 内容如下Reset_Handler   PROC
                     EXPORTReset_Handler            
                     IMPORTSystemInit
                     IMPORT__main

                      LDR   R0, =SystemInit
                      BLX   R0
                      LDR   R0, =__main
                      BX      R0
                      ENDP可以看出,在进入main函数之前,系统调用了SystemInit函数。
SystemInit函数位于system_stm32f4xx.c文件中.此文件提供几个宏定义可以设置各个时钟:
/************************* PLL Parameters *************************************/
#if defined (STM32F40_41xxx) || defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F401xx)
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
#define PLL_M      8
#else /* STM32F411xE */
#if defined (USE_HSE_BYPASS)
#define PLL_M      8      
#else /* STM32F411xE */   
#define PLL_M      16
#endif /* USE_HSE_BYPASS */
#endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx */   


/* USB OTG FS, SDIO and RNG Clock =PLL_VCO / PLLQ */
#define PLL_Q      7


#if defined (STM32F40_41xxx)
#define PLL_N      336
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P      2//2            //2---168M   4---84M
#endif /* STM32F40_41xxx */


#if defined (STM32F427_437xx) || defined (STM32F429_439xx)
#define PLL_N      360
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P      2
#endif /* STM32F427_437x || STM32F429_439xx */


#if defined (STM32F401xx)
#define PLL_N      336
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P      4
#endif /* STM32F401xx */


#if defined (STM32F411xE)
#define PLL_N      400
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P      4   
#endif /* STM32F411xx */


/******************************************************************************/以STM32F407为例,筛选可用信息如下:
/************************* PLL Parameters *************************************/   
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */   
#define PLL_M      8
#define PLL_N      336   

/* SYSCLK = PLL_VCO / PLL_P */   
#define PLL_P      2   

/* USB OTG FS, SDIO and RNG Clock =PLL_VCO / PLLQ */   
#define PLL_Q      7   

/******************************************************************************/而晶振频率则是在文件stm32f4xx.h中进行设置:
外部晶振:
#if !defined(HSE_VALUE)   
#define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
   
#endif /* HSE_VALUE */ 综上,如果使用外部晶振8MHz,则可以得出默认配置中:
锁相环压腔振荡器时钟PLL_VCO =(HSE_VALUE/PLL_M)* PLL_N=8/ 8* 336 = 336MHz
系统时钟SYSCLK = PLL_VCO / PLL_P=336 / 2 = 168MHz
USB,SD卡时钟 = PLL_VCO / PLLQ=336 / 7 = 48MHz


页: [1]
查看完整版本: stm32f4xx需要初始化主频吗?