小白一枚,目前在配置时钟时出现问题,DEBUG之后发现执行时一直停在一个死循环中,请大佬帮帮忙指教一下。看了很多例程大家好像都是这么配置的,不知道哪里出现了问题。
void SystemClock_Config_HSE(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
__HAL_RCC_PWR_CLK_ENABLE(); //xdf使能PWR时钟
/* MSI is enabled after System reset, activate PLL with MSI as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;//RCC_OSCILLATORTYPE_MSI;//外部晶振
RCC_OscInitStruct.HSEState =RCC_HSE_BYPASS;//RCC_HSE_ON; //RCC_HSE_BYPASS;//RCC_HSE_ON外部采用了有源晶振
//RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
//RCC_OscInitStruct.MSICalibrationValue = 16;//RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;//RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLM = 1;//主PLL和音频PLL分频系数(PLL之前的分频),取值范围:2~63.
RCC_OscInitStruct.PLL.PLLN = 10;//40; //主PLL倍频系数(PLL倍频),取值范围:64~432.
RCC_OscInitStruct.PLL.PLLR = 3;
RCC_OscInitStruct.PLL.PLLP = 7;//系统时钟的主PLL分频系数(PLL之后的分频),取值范围:2,4,6,8.(仅限这4个值!)
RCC_OscInitStruct.PLL.PLLQ = 3;//4;//USB/SDIO/随机数产生器等的主PLL分频系数(PLL之后的分频),取值范围:2~15.
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
/* Initialization Error */
while(1);
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
/* Initialization Error */
while(1);
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if( HAL_RCCEx_PeriphCLKConfig( &PeriphClkInit ) != HAL_OK )
{
while(1);//Error_Handler( );
}
/**Configure the main internal regulator output voltage
*/
if( HAL_PWREx_ControlVoltageScaling( PWR_REGULATOR_VOLTAGE_SCALE1 ) != HAL_OK )
{
while(1); //Error_Handler( );
}
/**Configure the Systick interrupt time */
HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq( ) / 1000 );
/**Configure the Systick */
HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK );
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 );
}
一周热门 更多>