@@ -115,11 +115,11 @@ extern "C" {
115115 * AHB Prescaler = 1
116116 * APB1 Prescaler = 1
117117 * PLL_M = 1
118- * PLL_N = 16
119- * PLL_R = 2
118+ * PLL_N = 24
119+ * PLL_R = 3
120120 * PLL_P = 2
121- * PLL_Q = 2
122- * USB(Hz) = 48000000 (HSI48M )
121+ * PLL_Q = 4
122+ * USB(Hz) = 48000000 (PLLQ )
123123 * @param None
124124 * @retval None
125125 */
@@ -129,22 +129,31 @@ WEAK void SystemClock_Config(void)
129129 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0 };
130130 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0 };
131131
132+ // Reset clock registers (in case bootloader has changed them)
133+ RCC->CR |= RCC_CR_HSION;
134+ while (!(RCC->CR & RCC_CR_HSIRDY))
135+ ;
136+ RCC->CFGR = 0x00000000 ;
137+ RCC->CR = RCC_CR_HSION;
138+ while (RCC->CR & RCC_CR_PLLRDY)
139+ ;
140+ RCC->PLLCFGR = 0x00001000 ;
141+
132142 /* * Configure the main internal regulator output voltage
133143 */
134144 HAL_PWREx_ControlVoltageScaling (PWR_REGULATOR_VOLTAGE_SCALE1);
135145 /* * Initializes the RCC Oscillators according to the specified parameters
136146 * in the RCC_OscInitTypeDef structure.
137147 */
138- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_HSI48 ;
148+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
139149 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
140- RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
141150 RCC_OscInitStruct.PLL .PLLState = RCC_PLL_ON;
142151 RCC_OscInitStruct.PLL .PLLSource = RCC_PLLSOURCE_HSE;
143152 RCC_OscInitStruct.PLL .PLLM = RCC_PLLM_DIV1;
144- RCC_OscInitStruct.PLL .PLLN = 16 ;
153+ RCC_OscInitStruct.PLL .PLLN = 24 ;
145154 RCC_OscInitStruct.PLL .PLLP = RCC_PLLP_DIV2;
146- RCC_OscInitStruct.PLL .PLLQ = RCC_PLLQ_DIV2 ;
147- RCC_OscInitStruct.PLL .PLLR = RCC_PLLR_DIV2 ;
155+ RCC_OscInitStruct.PLL .PLLQ = RCC_PLLQ_DIV4 ;
156+ RCC_OscInitStruct.PLL .PLLR = RCC_PLLR_DIV3 ;
148157 if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK)
149158 {
150159 Error_Handler ();
@@ -164,7 +173,7 @@ WEAK void SystemClock_Config(void)
164173 /* * Initializes the peripherals clocks
165174 */
166175 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
167- PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48 ;
176+ PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL ;
168177 if (HAL_RCCEx_PeriphCLKConfig (&PeriphClkInit) != HAL_OK)
169178 {
170179 Error_Handler ();
0 commit comments