2018-12-10 21:39:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2019-01-22 10:00:45 +08:00
|
|
|
* 2018-11-06 SummerGift first version
|
2018-12-10 21:39:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
void SystemClock_Config(void)
|
|
|
|
{
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
2018-12-11 22:53:25 +08:00
|
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
2018-12-10 21:39:28 +08:00
|
|
|
|
|
|
|
/**Configure the main internal regulator output voltage
|
|
|
|
*/
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
|
|
/**Initializes the CPU, AHB and APB busses clocks
|
|
|
|
*/
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
2018-12-11 22:53:25 +08:00
|
|
|
RCC_OscInitStruct.PLL.PLLM = 25;
|
|
|
|
RCC_OscInitStruct.PLL.PLLN = 432;
|
2018-12-10 21:39:28 +08:00
|
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
2019-01-15 16:17:01 +08:00
|
|
|
RCC_OscInitStruct.PLL.PLLQ = 9;
|
2018-12-10 21:39:28 +08:00
|
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/**Activate the Over-Drive mode
|
|
|
|
*/
|
|
|
|
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/**Initializes the CPU, AHB and APB busses clocks
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
|
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
|
2018-12-11 22:53:25 +08:00
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
2019-01-15 16:17:01 +08:00
|
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_USART1
|
|
|
|
|RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_CLK48;
|
|
|
|
PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
|
|
|
|
PeriphClkInitStruct.PLLSAI.PLLSAIR = 3;
|
|
|
|
PeriphClkInitStruct.PLLSAI.PLLSAIQ = 2;
|
|
|
|
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV2;
|
|
|
|
PeriphClkInitStruct.PLLSAIDivQ = 1;
|
|
|
|
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
|
2018-12-11 22:53:25 +08:00
|
|
|
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
|
2019-01-15 16:17:01 +08:00
|
|
|
PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLL;
|
|
|
|
PeriphClkInitStruct.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_CLK48;
|
2018-12-11 22:53:25 +08:00
|
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
2018-12-10 21:39:28 +08:00
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
}
|