STM32F4的时钟配置文件system_stm32f4xx.c说明
2012-12-20 21:02
295 查看
/** * @简介 配置系统时钟源, PLL乘法和除法因子, AHB/APBx prescalers and Flash settings * @Note This function should be called only once the RCC clock configuration * is reset to the default reset state (done in SystemInit() function). * @param None * @retval None */ static void SetSysClock(void) { /******************************************************************************/ /* PLL (clocked by HSE) 用作系统时钟源 */ /******************************************************************************/ __IO uint32_t StartUpCounter = 0, HSEStatus = 0; /* 使能外部高速时钟 */ RCC->CR |= ((uint32_t)RCC_CR_HSEON); /* 等待外部时钟准备好,如果时间超出则退出 */ do { HSEStatus = RCC->CR & RCC_CR_HSERDY; StartUpCounter++; } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); if ((RCC->CR & RCC_CR_HSERDY) != RESET) { HSEStatus = (uint32_t)0x01; } else { HSEStatus = (uint32_t)0x00; } if (HSEStatus == (uint32_t)0x01) { /* Select regulator voltage output Scale 1 mode, System frequency up to 168 MHz */ RCC->APB1ENR |= RCC_APB1ENR_PWREN; PWR->CR |= PWR_CR_VOS; /* HCLK = SYSCLK / 1*/ RCC->CFGR |= RCC_CFGR_HPRE_DIV1; /* PCLK2 = HCLK / 2*/ RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; /* PCLK1 = HCLK / 4*/ RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; /* Configure the main PLL */ RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) | (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24); /* Enable the main PLL */ RCC->CR |= RCC_CR_PLLON; /* Wait till the main PLL is ready */ while((RCC->CR & RCC_CR_PLLRDY) == 0) { } /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; /* Select the main PLL as system clock source */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); RCC->CFGR |= RCC_CFGR_SW_PLL; /* Wait till the main PLL is used as system clock source */ while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL); { } } else { /* If HSE fails to start-up, the application will have wrong clock configuration. User can add here some code to deal with this error */ } }
该程序中用到的寄存器为RCC_CR
![](http://img.my.csdn.net/uploads/201212/20/1356009828_2857.png)
时钟设置主要步骤:
1、使能外部高速时钟,即该寄存器的第16位;
2、等待外部高速时钟就绪,即该寄存器的第17位;
![](http://img.my.csdn.net/uploads/201212/20/1356009858_4187.png)
![](http://img.my.csdn.net/uploads/201212/20/1356009878_5264.png)
相关文章推荐
- xx实体.hbm.xml 配置文件的主键生成机制说明
- STM32F4xx那点事(二)——系统时钟的配置
- STM32F4的启动文件startup_stm32f4xx.s说明
- 只有在配置文件中或 Page 说明会 enableSessionState 至 true 时刻,能够使用会话状态。另外,还要确保应用程序配置 // 段包含 System.Web.SessionSta
- STM32F4的system_stm32f4xx.c文件需要根据不同板卡进行修改
- xx实体.hbm.xml 配置文件的主键生成机制说明
- FCKeditor.Net 2.6.3 配置说明与文件精简
- asp.net2.0中Web.config文件标准配置简要说明
- MySQL的配置文件说明
- Nginx配置文件简要说明(未完)
- 在运行配置文件中指定的扩展时出现异常。 System.Web.HttpException: 超过了最大请求长度。
- Hadoop集群搭建之三 配置文件说明
- mysql配置文件my.cnf详细说明
- IIS服务器配置文件路径及相关说明
- destoon 配置文件config.inc.php参数说明
- Nginx学习笔记(九) 配置文件详细说明
- 微信JSSDK配置文件说明
- log4j配置文件基本含义说明
- kickstart配置文件详解和system-config-kickstart
- Nginx配置文件详细说明