MCU为stm32l0系列,时钟配置如下:
- //时钟系统配置函数
- //SYSCLK=Fs*PLLMUL/PLLDIV;
- //
- //Fusb=Fvco/pllq=Fs*(plln/(pllm*pllq));
- //SYSCLK =
- //Fs 8M
- //Fvco: 8M
- //SYSCLK: 系统时钟频率 8*8/2=32
- //PLLMUL:倍频 8
- //PLLDIV:分频系数 2
- void SystemClockConfig( void )
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_PWR_CLK_ENABLE( );
- __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 );
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //高速外部时钟 8M
- RCC_OscInitStruct.HSEState = RCC_HSE_ON; //打开HSE
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; //打开PLL
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; //设置PLL时钟源
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL8; //8倍频
- RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV2; //PLL VCO输入时钟的分频系数
- if( HAL_RCC_OscConfig( &RCC_OscInitStruct ) != HAL_OK )
- {
- assert_param( FAIL );
- }
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
- RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; //设置系统时钟源
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; //AHB分频系数为1 32
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8; //APB1分频系数为8 4
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //APB2分频系数为1 32
- if( HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_1 ) != HAL_OK )
- {
- assert_param( FAIL );
- }
- HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq( ) / 1000 );
- HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK );
- HAL_NVIC_SetPriority( SysTick_IRQn, 1, 0 );
- HAL_NVIC_EnableIRQ(SysTick_IRQn);
- }
复制代码
|