调用库函数RCC_GetClocksFreq,该函数可以返回片上的各种时钟的频率
函数原形 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)
RCC_ClocksTypeDef定义于文件“stm32f10x_rcc.h”:
typedef struct
{
uint32_t SYSCLK_Frequency; /*!< SYSCLK clock frequency expressed in Hz */
uint32_t HCLK_Frequency; /*!< HCLK clock frequency expressed in Hz */
uint32_t PCLK1_Frequency; /*!< PCLK1 clock frequency expressed in Hz */
uint32_t PCLK2_Frequency; /*!< PCLK2 clock frequency expressed in Hz */
}RCC_ClocksTypeDef;
例:
/* Get the frequencies of different on chip clocks */
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);
执行完后,直接查看RCC_Clocks,在各成员中取出所需要时钟频率就行了。