完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
static void SetSysClock(void) { __IO uint32_t StartUpCounter = 0, HSEStatus = 0; /* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/ /* Enable HSE */ // RCC-》CR |= ((uint32_t)RCC_CR_HSEON);//使用外部8M时钟 RCC-》CR |= ((uint32_t)RCC_CR_HSION);//使用内部8M时钟 /* Wait till HSE is ready and if Time out is reached exit */ do { // HSEStatus = RCC-》CR & RCC_CR_HSERDY;//使用外部8M时钟 HSEStatus = RCC-》CR & RCC_CR_HSIRDY;//使用内部8M时钟 StartUpCounter++; } // while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));//使用外部8M时钟 while((HSEStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));//使用内部8M时钟 // if ((RCC-》CR & RCC_CR_HSERDY) != RESET)//使用外部8M时钟 if ((RCC-》CR & RCC_CR_HSIRDY) != RESET)//使用内部8M时钟 { HSEStatus = (uint32_t)0x01; } else { HSEStatus = (uint32_t)0x00; } if (HSEStatus == (uint32_t)0x01) { /* Enable Prefetch Buffer */ FLASH-》ACR |= FLASH_ACR_PRFTBE; FLASH-》ACR |= (uint32_t)FLASH_ACR_LATENCY; /* HCLK = SYSCLK */ RCC-》CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; /* PCLK = HCLK */ RCC-》CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1; /* PLL configuration: = HSE * 6 = 48 MHz */ // RCC-》CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));//使用外部8M时钟 // RCC-》CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL6);//使用外部8M时钟 // RCC-》CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1|RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL9);//内外都不使用 RCC-》CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSI_Div2|RCC_CFGR_PLLXTPRE_PREDIV1|RCC_CFGR_PLLMULL9);//使用内部8M时钟 /* Enable PLL */ RCC-》CR |= RCC_CR_PLLON; /* Wait till PLL is ready */ while((RCC-》CR & RCC_CR_PLLRDY) == 0) { } /* Select PLL as system clock source */ RCC-》CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); RCC-》CFGR |= (uint32_t)RCC_CFGR_SW_PLL; /* Wait till PLL is used as system clock source */ while ((RCC-》CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) { } } 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 */ } } /******************************************************************************/ /* */ /* Reset and Clock Control */ /* */ /******************************************************************************/ /******************** Bit definition for RCC_CR register ********************/ #define RCC_CR_HSION ((uint32_t)0x00000001) /*!《 Internal High Speed clock enable */ #define RCC_CR_HSIRDY ((uint32_t)0x00000002) /*!《 Internal High Speed clock ready flag */ #define RCC_CR_HSITRIM ((uint32_t)0x000000F8) /*!《 Internal High Speed clock trimming */ #define RCC_CR_HSICAL ((uint32_t)0x0000FF00) /*!《 Internal High Speed clock Calibration */ #define RCC_CR_HSEON ((uint32_t)0x00010000) /*!《 External High Speed clock enable */ #define RCC_CR_HSERDY ((uint32_t)0x00020000) /*!《 External High Speed clock ready flag */ #define RCC_CR_HSEBYP ((uint32_t)0x00040000) /*!《 External High Speed clock Bypass */ #define RCC_CR_CSSON ((uint32_t)0x00080000) /*!《 Clock Security System enable */ #define RCC_CR_PLLON ((uint32_t)0x01000000) /*!《 PLL enable */ #define RCC_CR_PLLRDY ((uint32_t)0x02000000) /*!《 PLL clock ready flag */ /******************* Bit definition for RCC_CFGR register *******************/ /*!《 SW configuration */ #define RCC_CFGR_SW ((uint32_t)0x00000003) /*!《 SW[1:0] bits (System clock Switch) */ #define RCC_CFGR_SW_0 ((uint32_t)0x00000001) /*!《 Bit 0 */ #define RCC_CFGR_SW_1 ((uint32_t)0x00000002) /*!《 Bit 1 */ #define RCC_CFGR_SW_HSI ((uint32_t)0x00000000) /*!《 HSI selected as system clock */ #define RCC_CFGR_SW_HSE ((uint32_t)0x00000001) /*!《 HSE selected as system clock */ #define RCC_CFGR_SW_PLL ((uint32_t)0x00000002) /*!《 PLL selected as system clock */ /*!《 SWS configuration */ #define RCC_CFGR_SWS ((uint32_t)0x0000000C) /*!《 SWS[1:0] bits (System Clock Switch Status) */ #define RCC_CFGR_SWS_0 ((uint32_t)0x00000004) /*!《 Bit 0 */ #define RCC_CFGR_SWS_1 ((uint32_t)0x00000008) /*!《 Bit 1 */ #define RCC_CFGR_SWS_HSI ((uint32_t)0x00000000) /*!《 HSI oscillator used as system clock */ #define RCC_CFGR_SWS_HSE ((uint32_t)0x00000004) /*!《 HSE oscillator used as system clock */ #define RCC_CFGR_SWS_PLL ((uint32_t)0x00000008) /*!《 PLL used as system clock */ |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1627 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1550 浏览 1 评论
984 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
688 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1601 浏览 2 评论
1867浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
650浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
518浏览 3评论
536浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
506浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 18:17 , Processed in 0.823049 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号