aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stm-init.c43
-rw-r--r--stm-init.h2
2 files changed, 45 insertions, 0 deletions
diff --git a/stm-init.c b/stm-init.c
index 051a755..0c0fd0f 100644
--- a/stm-init.c
+++ b/stm-init.c
@@ -48,6 +48,9 @@
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
+#ifdef CRYPTECH_USE_HSE_CLOCK
+static void SystemClock_Config(void);
+#endif
#ifdef HAL_GPIO_MODULE_ENABLED
static void MX_GPIO_Init(void);
#endif
@@ -61,6 +64,10 @@ void stm_init(void)
/* MCU Configuration----------------------------------------------------------*/
+#ifdef CRYPTECH_USE_HSE_CLOCK
+ SystemClock_Config();
+#endif
+
/* System interrupt init*/
/* Sets the priority grouping field */
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
@@ -76,6 +83,42 @@ void stm_init(void)
#endif
}
+#ifdef CRYPTECH_USE_HSE_CLOCK
+/** System Clock Configuration
+ *
+ * HSE crystal at 25 MHz, end result is 180 MHz clock.
+ */
+void SystemClock_Config(void)
+{
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+
+ __PWR_CLK_ENABLE();
+
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+ 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;
+ RCC_OscInitStruct.PLL.PLLM = 25;
+ RCC_OscInitStruct.PLL.PLLN = 360;
+ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
+ RCC_OscInitStruct.PLL.PLLQ = 4;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ HAL_PWREx_ActivateOverDrive();
+
+ RCC_ClkInitStruct.ClockType = 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;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
+}
+#endif
+
+
#ifdef HAL_UART_MODULE_ENABLED
/* USART1 init function */
static void MX_USART1_UART_Init(void)
diff --git a/stm-init.h b/stm-init.h
index ed80d01..489a2c6 100644
--- a/stm-init.h
+++ b/stm-init.h
@@ -43,4 +43,6 @@ extern void Error_Handler(void);
#define HAL_Delay osDelay
+#define CRYPTECH_USE_HSE_CLOCK
+
#endif /* __STM_INIT_H */