-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Copper280z/main
Add clock config with correct wait states and PLL settings.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "pins_arduino.h" | ||
|
||
/** | ||
* @brief System Clock Configuration | ||
* @retval None | ||
*/ | ||
void SystemClock_Config(void) | ||
{ | ||
RCC_OscInitTypeDef RCC_OscInitStruct = {0}; | ||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; | ||
#ifdef USBCON | ||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {}; | ||
#endif | ||
|
||
/** Configure the main internal regulator output voltage | ||
*/ | ||
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); | ||
|
||
/** Initializes the RCC Oscillators according to the specified parameters | ||
* in the RCC_OscInitTypeDef structure. | ||
*/ | ||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE; | ||
RCC_OscInitStruct.HSEState = RCC_HSE_ON; | ||
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; | ||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | ||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | ||
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2; | ||
RCC_OscInitStruct.PLL.PLLN = 85; | ||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; | ||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; | ||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; | ||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) | ||
{ | ||
Error_Handler(); | ||
} | ||
|
||
/** Initializes the CPU, AHB and APB buses 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_DIV1; | ||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | ||
|
||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) | ||
{ | ||
Error_Handler(); | ||
} | ||
|
||
#ifdef USBCON | ||
/* Initializes the peripherals clocks */ | ||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; | ||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; | ||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { | ||
Error_Handler(); | ||
} | ||
#endif | ||
} |