@@ -98,6 +98,7 @@ WEAK void SystemClock_Config(void)
98
98
RCC_OscInitTypeDef RCC_OscInitStruct = {};
99
99
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
100
100
#ifdef USBCON
101
+ RCC_CRSInitTypeDef RCC_CRSInitStruct = {};
101
102
RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
102
103
#endif
103
104
@@ -113,7 +114,7 @@ WEAK void SystemClock_Config(void)
113
114
RCC_OscInitStruct.PLL .PLLState = RCC_PLL_ON;
114
115
RCC_OscInitStruct.PLL .PLLM = RCC_PLLM_DIV2;
115
116
RCC_OscInitStruct.PLL .PLLSource = RCC_PLLSOURCE_HSE;
116
- RCC_OscInitStruct.PLL .PLLN = 72 ;
117
+ RCC_OscInitStruct.PLL .PLLN = 85 ;
117
118
RCC_OscInitStruct.PLL .PLLP = RCC_PLLP_DIV2;
118
119
RCC_OscInitStruct.PLL .PLLQ = RCC_PLLQ_DIV6;
119
120
RCC_OscInitStruct.PLL .PLLR = RCC_PLLR_DIV2;
@@ -133,9 +134,22 @@ WEAK void SystemClock_Config(void)
133
134
}
134
135
135
136
#ifdef USBCON
137
+ /* Enable the SYSCFG APB clock */
138
+ __HAL_RCC_CRS_CLK_ENABLE ();
139
+
140
+ /* Configures CRS */
141
+ RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
142
+ RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
143
+ RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
144
+ RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE (48000000 , 1000 );
145
+ RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
146
+ RCC_CRSInitStruct.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT;
147
+
148
+ HAL_RCCEx_CRSConfig (&RCC_CRSInitStruct);
149
+
136
150
/* Initializes the peripherals clocks */
137
151
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
138
- PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL ;
152
+ PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48 ;
139
153
if (HAL_RCCEx_PeriphCLKConfig (&PeriphClkInit) != HAL_OK) {
140
154
Error_Handler ();
141
155
}
0 commit comments