Fix oscillator configuration. Lab tested with internal oscillator up to 1M.
This commit is contained in:
parent
f74e3c0c2a
commit
aaaf33735c
36
Src/main.c
36
Src/main.c
|
@ -128,14 +128,27 @@ void SystemClock_Config(void)
|
|||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
||||
|
||||
#ifdef EXTERNAL_OSCILLATOR
|
||||
#ifdef INTERNAL_OSCILLATOR
|
||||
// set up the oscillators
|
||||
// use external oscillator (16 MHz), enable 3x PLL (48 MHz)
|
||||
// use internal HSI48 (48 MHz), no PLL
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
|
||||
RCC_OscInitStruct.HSI48State = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
#elif defined INTERNAL_OSCILLATOR
|
||||
|
||||
// set sysclk, hclk, and pclk1 source to HSI48 (48 MHz)
|
||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
// set USB clock source to HSI48 (48 MHz)
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
|
||||
|
||||
|
||||
#elif defined EXTERNAL_OSCILLATOR
|
||||
// set up the oscillators
|
||||
// use external oscillator (16 MHz), enable 3x PLL (48 MHz)
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
|
@ -144,23 +157,24 @@ void SystemClock_Config(void)
|
|||
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 |
|
||||
RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
|
||||
|
||||
// set USB clock source to PLL (48 MHz)
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLCLK;
|
||||
|
||||
#else
|
||||
#error "Please define whether to use an internal or external oscillator"
|
||||
#endif
|
||||
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
||||
__SYSCFG_CLK_ENABLE();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue