22 ******************************************************************************
33 * @file system_stm32h7xx.c
44 * @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.
86 *
97 * This file provides two functions and one global variable to be called from
108 * user application:
119 * - SystemInit(): This function is called at startup just after reset and
1210 * before branch to main program. This call is made inside
1311 * the "startup_stm32h7xx.s" file.
1412 *
15- * - SystemCoreClock variable: Contains the core clock (HCLK) , it can be used
13+ * - SystemCoreClock variable: Contains the core clock, it can be used
1614 * by the user application to setup the SysTick
1715 * timer or configure other parameters.
1816 *
6765 */
6866
6967/************************* 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) */
7169/* #define DATA_IN_D2_SRAM */
7270
7371/*!< Uncomment the following line if you need to relocate your vector Table in
@@ -149,6 +147,7 @@ void SystemInit (void)
149147 /* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */
150148 RCC -> CR &= 0xEAF6ED7FU ;
151149
150+ #if defined(D3_SRAM_BASE )
152151 /* Reset D1CFGR register */
153152 RCC -> D1CFGR = 0x00000000 ;
154153
@@ -157,7 +156,16 @@ void SystemInit (void)
157156
158157 /* Reset D3CFGR register */
159158 RCC -> D3CFGR = 0x00000000 ;
159+ #else
160+ /* Reset CDCFGR1 register */
161+ RCC -> CDCFGR1 = 0x00000000 ;
162+
163+ /* Reset CDCFGR2 register */
164+ RCC -> CDCFGR2 = 0x00000000 ;
160165
166+ /* Reset SRDCFGR register */
167+ RCC -> SRDCFGR = 0x00000000 ;
168+ #endif
161169 /* Reset PLLCKSELR register */
162170 RCC -> PLLCKSELR = 0x00000000 ;
163171
@@ -186,27 +194,48 @@ void SystemInit (void)
186194 /* Disable all interrupts */
187195 RCC -> CIER = 0x00000000 ;
188196
197+ #if (STM32H7_DEV_ID == 0x450UL )
198+ /* dual core CM7 or single core line */
189199 if ((DBGMCU -> IDCODE & 0xFFFF0000U ) < 0x20000000U )
190200 {
191201 /* if stm32h7 revY*/
192202 /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
193203 * ((__IO uint32_t * )0x51008108 ) = 0x000000001U ;
194204 }
205+ #endif
195206
196207#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 )
198210 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+
199217 tmpreg = RCC -> AHB2ENR ;
200218 (void ) tmpreg ;
201219#endif /* DATA_IN_D2_SRAM */
202220
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 ------------------*/
204232#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 */
206234#else
207235 SCB -> VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH */
208236#endif
209237
238+ #endif /*DUAL_CORE && CORE_CM4*/
210239
211240}
212241
@@ -250,22 +279,24 @@ void SystemInit (void)
250279void SystemCoreClockUpdate (void )
251280{
252281 uint32_t pllp , pllsource , pllm , pllfracen , hsivalue , tmp ;
282+ uint32_t common_system_clock ;
253283 float_t fracn1 , pllvco ;
254284
285+
255286 /* Get SYSCLK source -------------------------------------------------------*/
256287
257288 switch (RCC -> CFGR & RCC_CFGR_SWS )
258289 {
259290 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 ));
261292 break ;
262293
263294 case RCC_CFGR_SWS_CSI : /* CSI used as system clock source */
264- SystemCoreClock = CSI_VALUE ;
295+ common_system_clock = CSI_VALUE ;
265296 break ;
266297
267298 case RCC_CFGR_SWS_HSE : /* HSE used as system clock source */
268- SystemCoreClock = HSE_VALUE ;
299+ common_system_clock = HSE_VALUE ;
269300 break ;
270301
271302 case RCC_CFGR_SWS_PLL1 : /* PLL1 used as system clock source */
@@ -302,29 +333,48 @@ void SystemCoreClockUpdate (void)
302333 break ;
303334 }
304335 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 );
306337 }
307338 else
308339 {
309- SystemCoreClock = 0U ;
340+ common_system_clock = 0U ;
310341 }
311342 break ;
312343
313344 default :
314- SystemCoreClock = CSI_VALUE ;
345+ common_system_clock = CSI_VALUE ;
315346 break ;
316347 }
317348
318349 /* Compute SystemClock frequency --------------------------------------------------*/
350+ #if defined (RCC_D1CFGR_D1CPRE )
319351 tmp = D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_D1CPRE )>> RCC_D1CFGR_D1CPRE_Pos ];
320352
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 ;
323364
324365 /* 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 */
326375}
327376
377+
328378/**
329379 * @}
330380 */
0 commit comments