aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredrik Thulin <fredrik@thulin.net>2016-05-12 19:48:47 +0200
committerFredrik Thulin <fredrik@thulin.net>2016-05-12 19:48:47 +0200
commit7a4ca0d663390446b2e17d25352d14c0306beeab (patch)
tree65c4d1a6f0911408ab48709ff2ca73e43b9ef853
parent8a492acf7b856f0ab13a531a77ba9e64097ba007 (diff)
Enable HSE (external clock oscillator).
-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 */