[bsp] update RCC initial for system

* set internal oscillator trimming value to default
  * replace integer constant by macro from HAL library
  * remove SystemCoreClockUpdate() because "SystemCoreClock" updated in HAL_RCC_ClockConfig()
  * remove delay()
This commit is contained in:
tanek liang 2017-06-13 23:44:45 +08:00
parent a453b3318b
commit f537194d01
1 changed files with 18 additions and 22 deletions

View File

@ -40,18 +40,10 @@ void NVIC_Configuration(void)
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
} }
/** void error_handler(void)
* @brief Inserts a delay time.
* @param nCount: specifies the delay time length.
* @retval None
*/
static void Delay(__IO uint32_t nCount)
{ {
/* Decrement nCount value */ rt_kprintf("error_handler\n");
while (nCount != 0) while(1);
{
nCount--;
}
} }
/** /**
@ -63,32 +55,36 @@ static void Delay(__IO uint32_t nCount)
*/ */
static void RCC_Configuration(void) static void RCC_Configuration(void)
{ {
RCC_ClkInitTypeDef ClkInit = {0};
RCC_OscInitTypeDef OscInit = {0};
RCC_OscInitTypeDef OscInit;
HAL_RCC_DeInit(); HAL_RCC_DeInit();
/* Enable HSI Oscillator and Activate PLL with HSI as source */
OscInit.OscillatorType = RCC_OSCILLATORTYPE_HSI; OscInit.OscillatorType = RCC_OSCILLATORTYPE_HSI;
OscInit.HSIState = RCC_HSI_ON; OscInit.HSIState = RCC_HSI_ON;
OscInit.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
OscInit.PLL.PLLState = RCC_PLL_ON; OscInit.PLL.PLLState = RCC_PLL_ON;
OscInit.PLL.PLLDIV = RCC_PLLDIV_2; OscInit.PLL.PLLDIV = RCC_PLLDIV_2;
OscInit.PLL.PLLMUL = RCC_PLLMUL_4; OscInit.PLL.PLLMUL = RCC_PLLMUL_4;
OscInit.PLL.PLLSource = RCC_PLLSOURCE_HSI; OscInit.PLL.PLLSource = RCC_PLLSOURCE_HSI;
HAL_RCC_OscConfig(&OscInit); HAL_RCC_OscConfig(&OscInit);
RCC_ClkInitTypeDef ClkInit; /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
ClkInit.ClockType = RCC_CLOCKTYPE_SYSCLK | ClkInit.ClockType = RCC_CLOCKTYPE_SYSCLK |
RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2; RCC_CLOCKTYPE_PCLK2;
ClkInit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; ClkInit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
ClkInit.AHBCLKDivider = 0; ClkInit.AHBCLKDivider = RCC_SYSCLK_DIV1;
ClkInit.APB1CLKDivider = 0; ClkInit.APB1CLKDivider = RCC_HCLK_DIV1;
ClkInit.APB2CLKDivider = 0; ClkInit.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&ClkInit, 1); if (HAL_RCC_ClockConfig(&ClkInit, FLASH_LATENCY_1) != HAL_OK)
{
Delay(0x3FFFF); error_handler();
/* Update SystemCoreClock value from RCC configure */ }
SystemCoreClockUpdate();
} }
#ifdef PRINT_RCC_FREQ_INFO #ifdef PRINT_RCC_FREQ_INFO