17
17
* by the user application to setup the SysTick
18
18
* timer or configure other parameters.
19
19
*
20
- * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
21
- * be called whenever the core clock is changed
20
+ * - SystemCoreClockUpdate(): Updates the variables SystemD1Clock and SystemD2Clock
21
+ * and must be called whenever the core clock is changed
22
22
* during program execution.
23
23
*
24
24
*
50
50
51
51
#include "stm32h7xx.h"
52
52
#include <math.h>
53
+ #include "nvic_addr.h" // MBED PATCH for Bootloader
53
54
54
55
#if !defined (HSE_VALUE )
55
56
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
111
112
is no need to call the 2 first functions listed above, since SystemCoreClock
112
113
variable is updated automatically.
113
114
*/
114
- uint32_t SystemCoreClock = 64000000 ;
115
+ #if defined(CORE_CM7 )
116
+ #define SystemCoreClock SystemD1Clock
117
+ #elif defined(CORE_CM4 )
118
+ #define SystemCoreClock SystemD2Clock
119
+ #else
120
+ #error "Wrong core selection"
121
+ #endif
122
+ uint32_t SystemD1Clock = 64000000 ;
115
123
uint32_t SystemD2Clock = 64000000 ;
116
124
const uint8_t D1CorePrescTable [16 ] = {0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 };
117
125
@@ -216,7 +224,7 @@ void SystemInit (void)
216
224
#ifdef VECT_TAB_SRAM
217
225
SCB -> VTOR = D2_AHBSRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal SRAM */
218
226
#else
219
- SCB -> VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH */
227
+ SCB -> VTOR = NVIC_FLASH_VECTOR_ADDRESS ; /* Vector Table Relocation in Internal FLASH */ // MBED PATCH for Bootloader
220
228
#endif
221
229
222
230
#else
@@ -226,7 +234,7 @@ void SystemInit (void)
226
234
#ifdef VECT_TAB_SRAM
227
235
SCB -> VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal D1 AXI-RAM */
228
236
#else
229
- SCB -> VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET ; /* Vector Table Relocation in Internal FLASH */
237
+ SCB -> VTOR = NVIC_FLASH_VECTOR_ADDRESS ; /* Vector Table Relocation in Internal FLASH */ // MBED PATCH for Bootloader
230
238
#endif
231
239
232
240
#else
@@ -237,7 +245,7 @@ void SystemInit (void)
237
245
}
238
246
239
247
/**
240
- * @brief Update SystemCoreClock variable according to Clock Register Values.
248
+ * @brief Update SystemD1Clock and SystemD2Clock variables according to Clock Register Values.
241
249
* The SystemCoreClock variable contains the core clock , it can
242
250
* be used by the user application to setup the SysTick timer or configure
243
251
* other parameters.
@@ -250,10 +258,10 @@ void SystemInit (void)
250
258
* frequency in the chip. It is calculated based on the predefined
251
259
* constant and the selected clock source:
252
260
*
253
- * - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)
254
- * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
255
- * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
256
- * - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*),
261
+ * - If SYSCLK source is CSI, SystemD1Clock will contain the CSI_VALUE(*)
262
+ * - If SYSCLK source is HSI, SystemD1Clock will contain the HSI_VALUE(**)
263
+ * - If SYSCLK source is HSE, SystemD1Clock will contain the HSE_VALUE(***)
264
+ * - If SYSCLK source is PLL, SystemD1Clock will contain the CSI_VALUE(*),
257
265
* HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
258
266
*
259
267
* (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
@@ -283,16 +291,16 @@ void SystemCoreClockUpdate (void)
283
291
switch (RCC -> CFGR & RCC_CFGR_SWS )
284
292
{
285
293
case RCC_CFGR_SWS_HSI : /* HSI used as system clock source */
286
- SystemCoreClock = (uint32_t ) (HSI_VALUE >> ((RCC -> CR & RCC_CR_HSIDIV )>> 3 ));
294
+ SystemD1Clock = (uint32_t ) (HSI_VALUE >> ((RCC -> CR & RCC_CR_HSIDIV )>> 3 ));
287
295
288
296
break ;
289
297
290
298
case RCC_CFGR_SWS_CSI : /* CSI used as system clock source */
291
- SystemCoreClock = CSI_VALUE ;
299
+ SystemD1Clock = CSI_VALUE ;
292
300
break ;
293
301
294
302
case RCC_CFGR_SWS_HSE : /* HSE used as system clock source */
295
- SystemCoreClock = HSE_VALUE ;
303
+ SystemD1Clock = HSE_VALUE ;
296
304
break ;
297
305
298
306
case RCC_CFGR_SWS_PLL1 : /* PLL1 used as system clock source */
@@ -329,27 +337,27 @@ void SystemCoreClockUpdate (void)
329
337
break ;
330
338
}
331
339
pllp = (((RCC -> PLL1DIVR & RCC_PLL1DIVR_P1 ) >>9 ) + 1U ) ;
332
- SystemCoreClock = (uint32_t )(float_t )(pllvco /(float_t )pllp );
340
+ SystemD1Clock = (uint32_t )(float_t )(pllvco /(float_t )pllp );
333
341
}
334
342
else
335
343
{
336
- SystemCoreClock = 0U ;
344
+ SystemD1Clock = 0U ;
337
345
}
338
346
break ;
339
347
340
348
default :
341
- SystemCoreClock = CSI_VALUE ;
349
+ SystemD1Clock = CSI_VALUE ;
342
350
break ;
343
351
}
344
352
345
353
/* Compute SystemClock frequency --------------------------------------------------*/
346
354
tmp = D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_D1CPRE )>> RCC_D1CFGR_D1CPRE_Pos ];
347
355
348
- /* SystemCoreClock frequency : CM7 CPU frequency */
349
- SystemCoreClock >>= tmp ;
356
+ /* SystemD1Clock frequency : CM7 CPU frequency */
357
+ SystemD1Clock >>= tmp ;
350
358
351
359
/* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency */
352
- SystemD2Clock = (SystemCoreClock >> ((D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_HPRE )>> RCC_D1CFGR_HPRE_Pos ]) & 0x1FU ));
360
+ SystemD2Clock = (SystemD1Clock >> ((D1CorePrescTable [(RCC -> D1CFGR & RCC_D1CFGR_HPRE )>> RCC_D1CFGR_HPRE_Pos ]) & 0x1FU ));
353
361
354
362
}
355
363
0 commit comments