|
@@ -115,11 +115,11 @@ extern "C" {
|
115
|
115
|
* AHB Prescaler = 1
|
116
|
116
|
* APB1 Prescaler = 1
|
117
|
117
|
* PLL_M = 1
|
118
|
|
- * PLL_N = 16
|
119
|
|
- * PLL_R = 2
|
|
118
|
+ * PLL_N = 24
|
|
119
|
+ * PLL_R = 3
|
120
|
120
|
* PLL_P = 2
|
121
|
|
- * PLL_Q = 2
|
122
|
|
- * USB(Hz) = 48000000 (HSI48M)
|
|
121
|
+ * PLL_Q = 4
|
|
122
|
+ * USB(Hz) = 48000000 (PLLQ)
|
123
|
123
|
* @param None
|
124
|
124
|
* @retval None
|
125
|
125
|
*/
|
|
@@ -129,22 +129,31 @@ WEAK void SystemClock_Config(void)
|
129
|
129
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
130
|
130
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
131
|
131
|
|
|
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
|
+
|
132
|
142
|
/** Configure the main internal regulator output voltage
|
133
|
143
|
*/
|
134
|
144
|
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
135
|
145
|
/** Initializes the RCC Oscillators according to the specified parameters
|
136
|
146
|
* in the RCC_OscInitTypeDef structure.
|
137
|
147
|
*/
|
138
|
|
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_HSI48;
|
|
148
|
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
139
|
149
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
140
|
|
- RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
|
141
|
150
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
142
|
151
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
143
|
152
|
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
|
144
|
|
- RCC_OscInitStruct.PLL.PLLN = 16;
|
|
153
|
+ RCC_OscInitStruct.PLL.PLLN = 24;
|
145
|
154
|
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;
|
148
|
157
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
149
|
158
|
{
|
150
|
159
|
Error_Handler();
|
|
@@ -164,7 +173,7 @@ WEAK void SystemClock_Config(void)
|
164
|
173
|
/** Initializes the peripherals clocks
|
165
|
174
|
*/
|
166
|
175
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
167
|
|
- PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
|
|
176
|
+ PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
|
168
|
177
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
169
|
178
|
{
|
170
|
179
|
Error_Handler();
|