#include "stm32f10x.h" ErrorStatus HSEStartUpStatus; int main(void) { RCC_ClocksTypeDef clocks; RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON); HSEStartUpStatus=RCC_WaitForHSEStartUp(); if( HSEStartUpStatus==SUCCESS) {//继续正常RCC操作 FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); FLASH_SetLatency(FLASH_Latency_1); RCC_HCLKConfig(RCC_SYSCLK_Div1); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);//8*9=72MHz RCC_PLLCmd(ENABLE); while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET); RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while(RCC_GetSYSCLKSource()!=0x08);//等待SYSCLK为PLLCLK RCC_GetClocksFreq(&clocks); while(1);//在此设中断后可通过读取clocks变量的成员值获取当前的时钟 } }改写此代码要求HSE8MHz、SYSCLK、HCLK、PCLK2为36MHz,PCLK1为18MHz。
时间: 2024-05-04 07:21:57 浏览: 189
#include "stm32f10x.h"
ErrorStatus HSEStartUpStatus;
int main(void) {
RCC_ClocksTypeDef clocks;
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (HSEStartUpStatus == SUCCESS) {
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_1);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_4); // 8 * 4 = 32MHz
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != RCC_CFGR_SWS_PLL); // 等待SYSCLK为PLLCLK
RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK = 32MHz
RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK = 32MHz
RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK / 2 = 16MHz
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // 8 * 9 = 72MHz
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != RCC_CFGR_SWS_PLL); // 等待SYSCLK为PLLCLK
RCC_GetClocksFreq(&clocks);
while (1);
}
}
阅读全文