Skip to content

Commit d81f520

Browse files
committed
Divide HSE by 2 if the external XTAL used is 16 MHz
1 parent a36d006 commit d81f520

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

targets/TARGET_STM/TARGET_STM32F1/TARGET_STM32F103xE/system_clock.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
105105
/* Enable HSE oscillator and activate PLL with HSE as source */
106106
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
107107
if (bypass == 0) {
108-
RCC_OscInitStruct.HSEState = RCC_HSE_ON; /* External 8 MHz xtal on OSC_IN/OSC_OUT */
108+
RCC_OscInitStruct.HSEState = RCC_HSE_ON; /* External xtal on OSC_IN/OSC_OUT */
109109
} else {
110110
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; /* External 8 MHz clock on OSC_IN */
111111
}
112-
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
112+
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; // 8 MHz external xtal (8 MHz = 8 MHz / 1)
113+
#if (HSE_VALUE == 16000000)
114+
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV2; // 16 MHz external xtal (8 MHz = 16 MHz / 2)
115+
#endif
113116
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
114117
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
115118
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; // 72 MHz (8 MHz * 9)

0 commit comments

Comments
 (0)