stm32f 查看系统时钟配置
扫描二维码
随时随地手机看文章
之前因为系统时钟配置问题吃了很多亏,之前通过查看寄存器配置的形式进行时钟的计算,查看时钟配置是否正确,但是具体每个时钟具体是多少还是需要进行计算的,后来发现在库函数中有一个函数可以直接获取系统时钟,
* @brief Returns the frequencies of different on chip clocks.
* @param RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold
* the clocks frequencies.
* @note The result of this function could be not correct when using
* fractional value for HSE crystal.
* @retval None
*/
void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)
参数如下
typedef struct
{
uint32_t SYSCLK_Frequency; /*!< returns SYSCLK clock frequency expressed in Hz */
uint32_t HCLK_Frequency; /*!< returns HCLK clock frequency expressed in Hz */
uint32_t PCLK1_Frequency; /*!< returns PCLK1 clock frequency expressed in Hz */
uint32_t PCLK2_Frequency; /*!< returns PCLK2 clock frequency expressed in Hz */
uint32_t ADCCLK_Frequency; /*!< returns ADCCLK clock frequency expressed in Hz */
}RCC_ClocksTypeDef;
通过调用这个函数就可以轻松达到查看系统时钟的目的
RCC_ClocksTypeDef ClockInfo;
RCC_GetClocksFreq(&ClockInfo);
结果如下