@@ -102,25 +102,32 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
102
102
regarding system frequency refer to product datasheet. */
103
103
__HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1 );
104
104
105
- /* Enable HSE oscillator and activate PLL with HSE as source */
106
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSE ;
107
- if (bypass == 0 ) {
108
- RCC_OscInitStruct .HSEState = RCC_HSE_ON ; /* External 8 MHz xtal on OSC_IN/OSC_OUT */
109
- } else {
110
- RCC_OscInitStruct .HSEState = RCC_HSE_BYPASS ; /* External 8 MHz clock on OSC_IN */
111
- }
105
+ /* Get the Clocks configuration according to the internal RCC registers */
106
+ HAL_RCC_GetOscConfig (& RCC_OscInitStruct );
112
107
113
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_ON ;
114
- RCC_OscInitStruct .PLL .PLLSource = RCC_PLLSOURCE_HSE ;
108
+ /* PLL could be already configured by bootlader */
109
+ if (RCC_OscInitStruct .PLL .PLLState != RCC_PLL_ON )
110
+ {
111
+ /* Enable HSE oscillator and activate PLL with HSE as source */
112
+ RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSE ;
113
+ if (bypass == 0 ) {
114
+ RCC_OscInitStruct .HSEState = RCC_HSE_ON ; /* External 8 MHz xtal on OSC_IN/OSC_OUT */
115
+ } else {
116
+ RCC_OscInitStruct .HSEState = RCC_HSE_BYPASS ; /* External 8 MHz clock on OSC_IN */
117
+ }
115
118
116
- RCC_OscInitStruct .PLL .PLLM = 8 ; // VCO input clock = 1 MHz (8 MHz / 8)
117
- RCC_OscInitStruct .PLL .PLLN = 200 ; // VCO output clock = 200 MHz (1 MHz * 200)
118
- RCC_OscInitStruct .PLL .PLLP = RCC_PLLP_DIV2 ; // PLLCLK = 100 MHz (200 MHz / 2)
119
- RCC_OscInitStruct .PLL .PLLQ = 7 ;
120
- RCC_OscInitStruct .PLL .PLLR = 2 ;
119
+ RCC_OscInitStruct .PLL .PLLState = RCC_PLL_ON ;
120
+ RCC_OscInitStruct .PLL .PLLSource = RCC_PLLSOURCE_HSE ;
121
121
122
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
123
- return 0 ; // FAIL
122
+ RCC_OscInitStruct .PLL .PLLM = 8 ; // VCO input clock = 1 MHz (8 MHz / 8)
123
+ RCC_OscInitStruct .PLL .PLLN = 200 ; // VCO output clock = 200 MHz (1 MHz * 200)
124
+ RCC_OscInitStruct .PLL .PLLP = RCC_PLLP_DIV2 ; // PLLCLK = 100 MHz (200 MHz / 2)
125
+ RCC_OscInitStruct .PLL .PLLQ = 7 ;
126
+ RCC_OscInitStruct .PLL .PLLR = 2 ;
127
+
128
+ if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
129
+ return 0 ; // FAIL
130
+ }
124
131
}
125
132
126
133
/* Select PLLSAI output as USB clock source */
0 commit comments