@@ -128,14 +128,132 @@ extern "C" {
128
128
* @param None
129
129
* @retval None
130
130
*/
131
- WEAK void SystemClock_Config (void )
131
+ void SystemClock_Config (void )
132
132
{
133
- // Here copy the desired System Clock Configuration
134
- // It could be generated thanks STM32CubeMX after code generation for Toolchain/IDE: 'SW4STM32',
135
- // available in src/main.c
136
- // or
137
- // copied from a STM32CubeYY project examples
138
- // where 'YY' could be F0, F1, F2, F3, F4, F7, G0, H7, L0, L1, L4, WB
133
+ /* *
134
+ * NOTE: Because of the limitation of STM32MP1xx, unlike other MCUs this is
135
+ * NOT a WEAK function, preventing being overriden.
136
+ * In STM32MP1 series, SystemClock_Config()) is "done" by running the FSBL
137
+ * (First Stage Boot Loader) on Cortex-A. This function call shall NOT be
138
+ * executed in production mode. SystemClock_Config() shall be under
139
+ * if(IS_ENGINEERING_BOOT_MODE()).
140
+ *
141
+ * NOTE:
142
+ * * Production mode: Both CA7 and CM4 core running, BOOT0 and BOOT2 are ON.
143
+ * * Engineering mode: Only CM4 running, BOOT0 = OFF, BOOT2 = ON.
144
+ * See:
145
+ * https://wiki.st.com/stm32mpu/wiki/STM32CubeMP1_development_guidelines
146
+ */
147
+ if (!IS_ENGINEERING_BOOT_MODE ()) {
148
+ return ;
149
+ }
150
+
151
+ RCC_OscInitTypeDef RCC_OscInitStruct = {0 };
152
+ RCC_ClkInitTypeDef RCC_ClkInitStruct = {0 };
153
+
154
+ /* *Configure LSE Drive Capability
155
+ */
156
+ HAL_PWR_EnableBkUpAccess ();
157
+ __HAL_RCC_LSEDRIVE_CONFIG (RCC_LSEDRIVE_MEDIUMHIGH);
158
+
159
+ /* *Initializes the CPU, AHB and APB busses clocks
160
+ */
161
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE
162
+ | RCC_OSCILLATORTYPE_LSE;
163
+ RCC_OscInitStruct.HSEState = RCC_HSE_ON;
164
+ RCC_OscInitStruct.LSEState = RCC_LSE_ON;
165
+ RCC_OscInitStruct.HSIState = RCC_HSI_ON;
166
+ RCC_OscInitStruct.HSICalibrationValue = 16 ;
167
+ RCC_OscInitStruct.HSIDivValue = RCC_HSI_DIV1;
168
+
169
+ /* *PLL1 Config
170
+ */
171
+ RCC_OscInitStruct.PLL .PLLState = RCC_PLL_ON;
172
+ RCC_OscInitStruct.PLL .PLLSource = RCC_PLL12SOURCE_HSE;
173
+ RCC_OscInitStruct.PLL .PLLM = 3 ;
174
+ RCC_OscInitStruct.PLL .PLLN = 81 ;
175
+ RCC_OscInitStruct.PLL .PLLP = 1 ;
176
+ RCC_OscInitStruct.PLL .PLLQ = 1 ;
177
+ RCC_OscInitStruct.PLL .PLLR = 1 ;
178
+ RCC_OscInitStruct.PLL .PLLFRACV = 0x800 ;
179
+ RCC_OscInitStruct.PLL .PLLMODE = RCC_PLL_FRACTIONAL;
180
+ RCC_OscInitStruct.PLL .RPDFN_DIS = RCC_RPDFN_DIS_DISABLED;
181
+ RCC_OscInitStruct.PLL .TPDFN_DIS = RCC_TPDFN_DIS_DISABLED;
182
+
183
+ /* *PLL2 Config
184
+ */
185
+ RCC_OscInitStruct.PLL2 .PLLState = RCC_PLL_ON;
186
+ RCC_OscInitStruct.PLL2 .PLLSource = RCC_PLL12SOURCE_HSE;
187
+ RCC_OscInitStruct.PLL2 .PLLM = 3 ;
188
+ RCC_OscInitStruct.PLL2 .PLLN = 66 ;
189
+ RCC_OscInitStruct.PLL2 .PLLP = 2 ;
190
+ RCC_OscInitStruct.PLL2 .PLLQ = 1 ;
191
+ RCC_OscInitStruct.PLL2 .PLLR = 1 ;
192
+ RCC_OscInitStruct.PLL2 .PLLFRACV = 0x1400 ;
193
+ RCC_OscInitStruct.PLL2 .PLLMODE = RCC_PLL_FRACTIONAL;
194
+ RCC_OscInitStruct.PLL2 .RPDFN_DIS = RCC_RPDFN_DIS_DISABLED;
195
+ RCC_OscInitStruct.PLL2 .TPDFN_DIS = RCC_TPDFN_DIS_DISABLED;
196
+
197
+ /* *PLL3 Config
198
+ */
199
+ RCC_OscInitStruct.PLL3 .PLLState = RCC_PLL_ON;
200
+ RCC_OscInitStruct.PLL3 .PLLSource = RCC_PLL3SOURCE_HSE;
201
+ RCC_OscInitStruct.PLL3 .PLLM = 2 ;
202
+ RCC_OscInitStruct.PLL3 .PLLN = 34 ;
203
+ RCC_OscInitStruct.PLL3 .PLLP = 2 ;
204
+ RCC_OscInitStruct.PLL3 .PLLQ = 17 ;
205
+ RCC_OscInitStruct.PLL3 .PLLR = 37 ;
206
+ RCC_OscInitStruct.PLL3 .PLLRGE = RCC_PLL3IFRANGE_1;
207
+ RCC_OscInitStruct.PLL3 .PLLFRACV = 0x1A04 ;
208
+ RCC_OscInitStruct.PLL3 .PLLMODE = RCC_PLL_FRACTIONAL;
209
+ RCC_OscInitStruct.PLL3 .RPDFN_DIS = RCC_RPDFN_DIS_DISABLED;
210
+ RCC_OscInitStruct.PLL3 .TPDFN_DIS = RCC_TPDFN_DIS_DISABLED;
211
+
212
+ /* *PLL4 Config
213
+ */
214
+ RCC_OscInitStruct.PLL4 .PLLState = RCC_PLL_ON;
215
+ RCC_OscInitStruct.PLL4 .PLLSource = RCC_PLL4SOURCE_HSE;
216
+ RCC_OscInitStruct.PLL4 .PLLM = 4 ;
217
+ RCC_OscInitStruct.PLL4 .PLLN = 99 ;
218
+ RCC_OscInitStruct.PLL4 .PLLP = 6 ;
219
+ RCC_OscInitStruct.PLL4 .PLLQ = 8 ;
220
+ RCC_OscInitStruct.PLL4 .PLLR = 8 ;
221
+ RCC_OscInitStruct.PLL4 .PLLRGE = RCC_PLL4IFRANGE_0;
222
+ RCC_OscInitStruct.PLL4 .PLLFRACV = 0 ;
223
+ RCC_OscInitStruct.PLL4 .PLLMODE = RCC_PLL_INTEGER;
224
+ RCC_OscInitStruct.PLL4 .RPDFN_DIS = RCC_RPDFN_DIS_DISABLED;
225
+ RCC_OscInitStruct.PLL4 .TPDFN_DIS = RCC_TPDFN_DIS_DISABLED;
226
+
227
+ if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK) {
228
+ /* Initialization Error */
229
+ while (1 );
230
+ }
231
+ /* *RCC Clock Config
232
+ */
233
+ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_ACLK
234
+ | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2
235
+ | RCC_CLOCKTYPE_PCLK3 | RCC_CLOCKTYPE_PCLK4
236
+ | RCC_CLOCKTYPE_PCLK5 | RCC_CLOCKTYPE_MPU;
237
+ RCC_ClkInitStruct.MPUInit .MPU_Clock = RCC_MPUSOURCE_PLL1;
238
+ RCC_ClkInitStruct.MPUInit .MPU_Div = RCC_MPU_DIV2;
239
+ RCC_ClkInitStruct.AXISSInit .AXI_Clock = RCC_AXISSOURCE_PLL2;
240
+ RCC_ClkInitStruct.AXISSInit .AXI_Div = RCC_AXI_DIV1;
241
+ RCC_ClkInitStruct.MCUInit .MCU_Clock = RCC_MCUSSOURCE_PLL3;
242
+ RCC_ClkInitStruct.MCUInit .MCU_Div = RCC_MCU_DIV1;
243
+ RCC_ClkInitStruct.APB4_Div = RCC_APB4_DIV2;
244
+ RCC_ClkInitStruct.APB5_Div = RCC_APB5_DIV4;
245
+ RCC_ClkInitStruct.APB1_Div = RCC_APB1_DIV2;
246
+ RCC_ClkInitStruct.APB2_Div = RCC_APB2_DIV2;
247
+ RCC_ClkInitStruct.APB3_Div = RCC_APB3_DIV2;
248
+
249
+ if (HAL_RCC_ClockConfig (&RCC_ClkInitStruct) != HAL_OK) {
250
+ /* Initialization Error */
251
+ while (1 );
252
+ }
253
+
254
+ /* *Set the HSE division factor for RTC clock
255
+ */
256
+ __HAL_RCC_RTC_HSEDIV (24 );
139
257
}
140
258
141
259
#ifdef __cplusplus
0 commit comments