同样的时钟配置代码,ucosiii官方的例程中的代码,我分别移植到iar和eclipse+gnu下.编译之后调试发现系统时钟竟然不一样.
先看下时钟配置代码
- void BSP_SystemClkCfg (void)
- {
- static RCC_OscInitTypeDef RCC_OscInit;
- static RCC_ClkInitTypeDef RCC_ClkInit;
- HAL_StatusTypeDef hal_status;
- __HAL_RCC_PWR_CLK_ENABLE(); //使能PWR时钟
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);//设置调压器输出电压级别,以便在器件未以最大频率工作
- /* VCO out-freq = HSE * (PLLN / PLLM) = 432MHz. */
- /* PLLCLK = (VCO out-freq) / PLLP = 216MHz. */
- RCC_OscInit.OscillatorType = RCC_OSCILLATORTYPE_HSE; /* HSE freq = 25MHz. */
- RCC_OscInit.HSEState = RCC_HSE_ON;
- RCC_OscInit.HSIState = RCC_HSI_OFF;
- RCC_OscInit.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInit.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInit.PLL.PLLM = 25u;
- RCC_OscInit.PLL.PLLN = 432u;
- RCC_OscInit.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInit.PLL.PLLQ = 9;/* PLL_Q out freq = (VCO out-freq) / PLLQ = 48MHz. */
- //RCC_OscInit.PLL.PLLR = 7;
- hal_status = HAL_RCC_OscConfig(&RCC_OscInit);
- if (hal_status != HAL_OK) {
- while (DEF_TRUE) { /* STOP if error */
- ;
- }
- }
- hal_status = HAL_PWREx_EnableOverDrive(); /* Activate the OverDrive to reach the 216 Mhz Freq */
- if (hal_status != HAL_OK) {
- while (DEF_TRUE) { /* STOP if error */
- ;
- }
- }
- RCC_ClkInit.ClockType = RCC_CLOCKTYPE_SYSCLK |
- RCC_CLOCKTYPE_HCLK |
- RCC_CLOCKTYPE_PCLK1 |
- RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInit.AHBCLKDivider = RCC_SYSCLK_DIV1; /* HCLK = AHBCLK = PLLCLK / AHBPRES(1) = 216MHz. */
- RCC_ClkInit.APB1CLKDivider = RCC_HCLK_DIV4; /* APB1CLK = AHBCLK / APB1DIV(4) = 54MHz. */
- RCC_ClkInit.APB2CLKDivider = RCC_HCLK_DIV2; /* APB2CLK = AHBCLK / APB2DIV(2) = 108MHz. */
- hal_status = HAL_RCC_ClockConfig(&RCC_ClkInit, FLASH_LATENCY_7);
- if (hal_status != HAL_OK) {
- while (DEF_TRUE) { /* STOP if error */
- ;
- }
- }
- }
复制代码在eclipse下调试,截图
在IAR下调试的截图
这些配置寄存器都是一样的,但是执行完
BSP_SystemClkCfg 这个函数之后,系统时钟还是不一样啊,IAR下的是216MHz正常的.gnu下的出现了问题变成了69120000Hz.这是为什么呢?感觉很神奇阿.
-
-
修改之后,就可以了
一周热门 更多>