From f74e3c0c2a93a7f1486f4a5f68b1eeacbd1828f9 Mon Sep 17 00:00:00 2001 From: Ethan Zonca Date: Wed, 10 Jun 2015 08:33:37 -0400 Subject: [PATCH] Add defines to choose between internal and external oscillator --- Src/main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Src/main.c b/Src/main.c index 72a5634..06c0671 100644 --- a/Src/main.c +++ b/Src/main.c @@ -41,6 +41,9 @@ #include "can.h" #include "slcan.h" +#define INTERNAL_OSCILLATOR +//#define EXTERNAL_OSCILLATOR + /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ @@ -125,12 +128,25 @@ void SystemClock_Config(void) RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; +#ifdef EXTERNAL_OSCILLATOR // set up the oscillators // use external oscillator (16 MHz), enable 3x PLL (48 MHz) RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; RCC_OscInitStruct.HSI48State = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct); +#elif defined INTERNAL_OSCILLATOR + // set up the oscillators + // use external oscillator (16 MHz), enable 3x PLL (48 MHz) + 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.PLLMUL = RCC_PLL_MUL3; + RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; +#else + #error "Please define whether to use an internal or external oscillator" +#endif // set sysclk, hclk, and pclk1 source to PLL (48 MHz) RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK |