2
2
******************************************************************************
3
3
* @file system_stm32h7xx.c
4
4
* @author MCD Application Team
5
- * @brief CMSIS Cortex-M7 Device Peripheral Access Layer System Source File.
6
- * This provides system initialization template function is case of
7
- * an application using a single core STM32H7 device
5
+ * @brief CMSIS Cortex-Mx Device Peripheral Access Layer System Source File.
8
6
*
9
7
* This file provides two functions and one global variable to be called from
10
8
* user application:
11
9
* - SystemInit(): This function is called at startup just after reset and
12
10
* before branch to main program. This call is made inside
13
11
* the "startup_stm32h7xx.s" file.
14
12
*
15
- * - SystemCoreClock variable: Contains the core clock (HCLK) , it can be used
13
+ * - SystemCoreClock variable: Contains the core clock, it can be used
16
14
* by the user application to setup the SysTick
17
15
* timer or configure other parameters.
18
16
*
67
65
*/
68
66
69
67
/************************* Miscellaneous Configuration ************************/
70
- /*!< Uncomment the following line if you need to use initialized data in D2 domain SRAM */
68
+ /*!< Uncomment the following line if you need to use initialized data in D2 domain SRAM (AHB SRAM) */
71
69
/* #define DATA_IN_D2_SRAM */
72
70
73
71
/*!< Uncomment the following line if you need to relocate your vector Table in
@@ -149,6 +147,7 @@ void SystemInit (void)
149
147
/* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */
150
148
RCC -> CR &= 0xEAF6ED7FU ;
151
149
150
+ #if defined(D3_SRAM_BASE )
152
151
/* Reset D1CFGR register */
153
152
RCC -> D1CFGR = 0x00000000 ;
154
153
@@ -157,7 +156,16 @@ void SystemInit (void)
157
156
158
157
/* Reset D3CFGR register */
159
158
RCC -> D3CFGR = 0x00000000 ;
159
+ #else
160
+ /* Reset CDCFGR1 register */
161
+ RCC -> CDCFGR1 = 0x00000000 ;
162
+
163
+ /* Reset CDCFGR2 register */
164
+ RCC -> CDCFGR2 = 0x00000000 ;
160
165
166
+ /* Reset SRDCFGR register */
167
+ RCC -> SRDCFGR = 0x00000000 ;
168
+ #endif
161
169
/* Reset PLLCKSELR register */
162
170
RCC -> PLLCKSELR = 0x00000000 ;
163
171
@@ -186,27 +194,48 @@ void SystemInit (void)
186
194
/* Disable all interrupts */
187
195
RCC -> CIER = 0x00000000 ;
188
196
197
+ #if (STM32H7_DEV_ID == 0x450UL )
198
+ /* dual core CM7 or single core line */
189
199
if ((DBGMCU -> IDCODE & 0xFFFF0000U ) < 0x20000000U )
190
200
{
191
201
/* if stm32h7 revY*/
192
202
/* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
193
203
* ((__IO uint32_t * )0x51008108 ) = 0x000000001U ;
194
204
}
205
+ #endif
195
206
196
207
#if defined (DATA_IN_D2_SRAM )
197
- /* in case of initialized data in D2 SRAM , enable the D2 SRAM clock */
208
+ /* in case of initialized data in D2 SRAM (AHB SRAM) , enable the D2 SRAM clock (AHB SRAM clock) */
209
+ #if defined(RCC_AHB2ENR_D2SRAM3EN )
198
210
RCC -> AHB2ENR |= (RCC_AHB2ENR_D2SRAM1EN | RCC_AHB2ENR_D2SRAM2EN | RCC_AHB2ENR_D2SRAM3EN );
211
+ #elif defined(RCC_AHB2ENR_D2SRAM2EN )
212
+ RCC -> AHB2ENR |= (RCC_AHB2ENR_D2SRAM1EN | RCC_AHB2ENR_D2SRAM2EN );
213
+ #else
214
+ RCC -> AHB2ENR |= (RCC_AHB2ENR_AHBSRAM1EN | RCC_AHB2ENR_AHBSRAM2EN );
215
+ #endif /* RCC_AHB2ENR_D2SRAM3EN */
216
+
199
217
tmpreg = RCC -> AHB2ENR ;
200
218
(void ) tmpreg ;
201
219
#endif /* DATA_IN_D2_SRAM */
202
220
203
- /* Configure the Vector Table location add offset address ------------------*/
221
+ #if defined(DUAL_CORE ) && defined(CORE_CM4 )
222
+ /* Configure the Vector Table location add offset address for cortex-M4 ------------------*/
223
+ #ifdef VECT_TAB_SRAM
224
+ SCB -> VTOR = D2_AHBSRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal SRAM */
225
+ #else
226
+ SCB -> VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH */
227
+ #endif /* VECT_TAB_SRAM */
228
+
229
+ #else
230
+
231
+ /* Configure the Vector Table location add offset address for cortex-M7 ------------------*/
204
232
#ifdef VECT_TAB_SRAM
205
- SCB -> VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal SRAM */
233
+ SCB -> VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal AXI-RAM */
206
234
#else
207
235
SCB -> VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH */
208
236
#endif
209
237
238
+ #endif /*DUAL_CORE && CORE_CM4*/
210
239
211
240
}
212
241
@@ -250,22 +279,24 @@ void SystemInit (void)
250
279
void SystemCoreClockUpdate (void )
251
280
{
252
281
uint32_t pllp , pllsource , pllm , pllfracen , hsivalue , tmp ;
282
+ uint32_t common_system_clock ;
253
283
float_t fracn1 , pllvco ;
254
284
285
+
255
286
/* Get SYSCLK source -------------------------------------------------------*/
256
287
257
288
switch (RCC -> CFGR & RCC_CFGR_SWS )
258
289
{
259
290
case RCC_CFGR_SWS_HSI : /* HSI used as system clock source */
260
- SystemCoreClock = (uint32_t ) (HSI_VALUE >> ((RCC -> CR & RCC_CR_HSIDIV )>> 3 ));
291
+ common_system_clock = (uint32_t ) (HSI_VALUE >> ((RCC -> CR & RCC_CR_HSIDIV )>> 3 ));
261
292
break ;
262
293
263
294
case RCC_CFGR_SWS_CSI : /* CSI used as system clock source */
264
- SystemCoreClock = CSI_VALUE ;
295
+ common_system_clock = CSI_VALUE ;
265
296
break ;
266
297
267
298
case RCC_CFGR_SWS_HSE : /* HSE used as system clock source */
268
- SystemCoreClock = HSE_VALUE ;
299
+ common_system_clock = HSE_VALUE ;
269
300
break ;
270
301
271
302
case RCC_CFGR_SWS_PLL1 : /* PLL1 used as system clock source */
@@ -302,29 +333,48 @@ void SystemCoreClockUpdate (void)
302
333
break ;
303
334
}
304
335
pllp = (((RCC -> PLL1DIVR & RCC_PLL1DIVR_P1 ) >>9 ) + 1U ) ;
305
- SystemCoreClock = (uint32_t )(float_t )(pllvco /(float_t )pllp );
336
+ common_system_clock = (uint32_t )(float_t )(pllvco /(float_t )pllp );
306
337
}
307
338
else
308
339
{
309
- SystemCoreClock = 0U ;
340
+ common_system_clock = 0U ;
310
341
}
311
342
break ;
312
343
313
344
default :
314
- SystemCoreClock = CSI_VALUE ;
345
+ common_system_clock = CSI_VALUE ;
315
346
break ;
316
347
}
317
348
318
349
/* Compute SystemClock frequency --------------------------------------------------*/
350
+ #if defined (RCC_D1CFGR_D1CPRE )
319
351
tmp = D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_D1CPRE )>> RCC_D1CFGR_D1CPRE_Pos ];
320
352
321
- /* SystemCoreClock frequency : CM7 CPU frequency */
322
- SystemCoreClock >>= tmp ;
353
+ /* common_system_clock frequency : CM7 CPU frequency */
354
+ common_system_clock >>= tmp ;
355
+
356
+ /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency */
357
+ SystemD2Clock = (common_system_clock >> ((D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_HPRE )>> RCC_D1CFGR_HPRE_Pos ]) & 0x1FU ));
358
+
359
+ #else
360
+ tmp = D1CorePrescTable [(RCC -> CDCFGR1 & RCC_CDCFGR1_CDCPRE )>> RCC_CDCFGR1_CDCPRE_Pos ];
361
+
362
+ /* common_system_clock frequency : CM7 CPU frequency */
363
+ common_system_clock >>= tmp ;
323
364
324
365
/* SystemD2Clock frequency : AXI and AHBs Clock frequency */
325
- SystemD2Clock = (SystemCoreClock >> ((D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_HPRE )>> RCC_D1CFGR_HPRE_Pos ]) & 0x1FU ));
366
+ SystemD2Clock = (common_system_clock >> ((D1CorePrescTable [(RCC -> CDCFGR1 & RCC_CDCFGR1_HPRE )>> RCC_CDCFGR1_HPRE_Pos ]) & 0x1FU ));
367
+
368
+ #endif
369
+
370
+ #if defined(DUAL_CORE ) && defined(CORE_CM4 )
371
+ SystemCoreClock = SystemD2Clock ;
372
+ #else
373
+ SystemCoreClock = common_system_clock ;
374
+ #endif /* DUAL_CORE && CORE_CM4 */
326
375
}
327
376
377
+
328
378
/**
329
379
* @}
330
380
*/
0 commit comments