@@ -98,26 +98,33 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
98
98
__HAL_RCC_PWR_CLK_ENABLE ();
99
99
__HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE2 );
100
100
101
- // Enable HSE oscillator and activate PLL with HSE as source
102
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSE ;
103
- if (bypass == 0 ) {
104
- RCC_OscInitStruct .HSEState = RCC_HSE_ON ; // External 8 MHz xtal on OSC_IN/OSC_OUT
105
- } else {
106
- RCC_OscInitStruct .HSEState = RCC_HSE_BYPASS ; // External 8 MHz clock on OSC_IN
107
- }
101
+ /* Get the Clocks configuration according to the internal RCC registers */
102
+ HAL_RCC_GetOscConfig (& RCC_OscInitStruct );
103
+
104
+ /* PLL could be already configured by bootlader */
105
+ if (RCC_OscInitStruct .PLL .PLLState != RCC_PLL_ON ) {
106
+
107
+ // Enable HSE oscillator and activate PLL with HSE as source
108
+ RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSE ;
109
+ if (bypass == 0 ) {
110
+ RCC_OscInitStruct .HSEState = RCC_HSE_ON ; // External 8 MHz xtal on OSC_IN/OSC_OUT
111
+ } else {
112
+ RCC_OscInitStruct .HSEState = RCC_HSE_BYPASS ; // External 8 MHz clock on OSC_IN
113
+ }
108
114
109
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_ON ;
110
- RCC_OscInitStruct .PLL .PLLSource = RCC_PLLSOURCE_HSE ;
111
- RCC_OscInitStruct .PLL .PLLM = 4 ; // VCO input clock = 2 MHz (8 MHz / 4)
115
+ RCC_OscInitStruct .PLL .PLLState = RCC_PLL_ON ;
116
+ RCC_OscInitStruct .PLL .PLLSource = RCC_PLLSOURCE_HSE ;
117
+ RCC_OscInitStruct .PLL .PLLM = 4 ; // VCO input clock = 2 MHz (8 MHz / 4)
112
118
#if (DEVICE_USBDEVICE )
113
- RCC_OscInitStruct .PLL .PLLN = 192 ; // VCO output clock = 384 MHz (2 MHz * 192)
119
+ RCC_OscInitStruct .PLL .PLLN = 192 ; // VCO output clock = 384 MHz (2 MHz * 192)
114
120
#else /* DEVICE_USBDEVICE */
115
- RCC_OscInitStruct .PLL .PLLN = 200 ; // VCO output clock = 400 MHz (2 MHz * 200)
121
+ RCC_OscInitStruct .PLL .PLLN = 200 ; // VCO output clock = 400 MHz (2 MHz * 200)
116
122
#endif /* DEVICE_USBDEVICE */
117
- RCC_OscInitStruct .PLL .PLLP = RCC_PLLP_DIV4 ; // PLLCLK = 100 MHz or 96 MHz (depending on DEVICE_USBDEVICE)
118
- RCC_OscInitStruct .PLL .PLLQ = 8 ; // USB clock = 48 MHz (DEVICE_USBDEVICE=1)
119
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
120
- return 0 ; // FAIL
123
+ RCC_OscInitStruct .PLL .PLLP = RCC_PLLP_DIV4 ; // PLLCLK = 100 MHz or 96 MHz (depending on DEVICE_USBDEVICE)
124
+ RCC_OscInitStruct .PLL .PLLQ = 8 ; // USB clock = 48 MHz (DEVICE_USBDEVICE=1)
125
+ if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
126
+ return 0 ; // FAIL
127
+ }
121
128
}
122
129
123
130
// Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers
0 commit comments