stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c
Go to the documentation of this file.
1 
48 #include "stm32h7xx.h"
49 #include <math.h>
50 #if !defined (HSE_VALUE)
51 #define HSE_VALUE ((uint32_t)25000000)
52 #endif /* HSE_VALUE */
53 
54 #if !defined (CSI_VALUE)
55  #define CSI_VALUE ((uint32_t)4000000)
56 #endif /* CSI_VALUE */
57 
58 #if !defined (HSI_VALUE)
59  #define HSI_VALUE ((uint32_t)64000000)
60 #endif /* HSI_VALUE */
61 
62 
79 /************************* Miscellaneous Configuration ************************/
81 /* #define DATA_IN_D2_SRAM */
82 
85 /* #define VECT_TAB_SRAM */
86 #define VECT_TAB_OFFSET 0x00000000UL
88 /******************************************************************************/
89 
105  /* This variable is updated in three ways:
106  1) by calling CMSIS function SystemCoreClockUpdate()
107  2) by calling HAL API function HAL_RCC_GetHCLKFreq()
108  3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
109  Note: If you use this function to configure the system clock; then there
110  is no need to call the 2 first functions listed above, since SystemCoreClock
111  variable is updated automatically.
112  */
113  uint32_t SystemCoreClock = 64000000;
114  uint32_t SystemD2Clock = 64000000;
115  const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
116 
140 void SystemInit (void)
141 {
142 #if defined (DATA_IN_D2_SRAM)
143  __IO uint32_t tmpreg;
144 #endif /* DATA_IN_D2_SRAM */
145 
146  /* FPU settings ------------------------------------------------------------*/
147  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
148  SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */
149  #endif
150  /* Reset the RCC clock configuration to the default reset state ------------*/
151 
152  /* Increasing the CPU frequency */
154  {
155  /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
157  }
158 
159  /* Set HSION bit */
160  RCC->CR |= RCC_CR_HSION;
161 
162  /* Reset CFGR register */
163  RCC->CFGR = 0x00000000;
164 
165  /* Reset HSEON, HSECSSON, CSION, HSI48ON, CSIKERON, PLL1ON, PLL2ON and PLL3ON bits */
166  RCC->CR &= 0xEAF6ED7FU;
167 
168  /* Decreasing the number of wait states because of lower CPU frequency */
170  {
171  /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
173  }
174 
175 #if defined(D3_SRAM_BASE)
176  /* Reset D1CFGR register */
177  RCC->D1CFGR = 0x00000000;
178 
179  /* Reset D2CFGR register */
180  RCC->D2CFGR = 0x00000000;
181 
182  /* Reset D3CFGR register */
183  RCC->D3CFGR = 0x00000000;
184 #else
185  /* Reset CDCFGR1 register */
186  RCC->CDCFGR1 = 0x00000000;
187 
188  /* Reset CDCFGR2 register */
189  RCC->CDCFGR2 = 0x00000000;
190 
191  /* Reset SRDCFGR register */
192  RCC->SRDCFGR = 0x00000000;
193 #endif
194  /* Reset PLLCKSELR register */
195  RCC->PLLCKSELR = 0x02020200;
196 
197  /* Reset PLLCFGR register */
198  RCC->PLLCFGR = 0x01FF0000;
199  /* Reset PLL1DIVR register */
200  RCC->PLL1DIVR = 0x01010280;
201  /* Reset PLL1FRACR register */
202  RCC->PLL1FRACR = 0x00000000;
203 
204  /* Reset PLL2DIVR register */
205  RCC->PLL2DIVR = 0x01010280;
206 
207  /* Reset PLL2FRACR register */
208 
209  RCC->PLL2FRACR = 0x00000000;
210  /* Reset PLL3DIVR register */
211  RCC->PLL3DIVR = 0x01010280;
212 
213  /* Reset PLL3FRACR register */
214  RCC->PLL3FRACR = 0x00000000;
215 
216  /* Reset HSEBYP bit */
217  RCC->CR &= 0xFFFBFFFFU;
218 
219  /* Disable all interrupts */
220  RCC->CIER = 0x00000000;
221 
222 #if (STM32H7_DEV_ID == 0x450UL)
223  /* dual core CM7 or single core line */
224  if((DBGMCU->IDCODE & 0xFFFF0000U) < 0x20000000U)
225  {
226  /* if stm32h7 revY*/
227  /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
228  *((__IO uint32_t*)0x51008108) = 0x000000001U;
229  }
230 #endif
231 
232 #if defined (DATA_IN_D2_SRAM)
233  /* in case of initialized data in D2 SRAM (AHB SRAM) , enable the D2 SRAM clock (AHB SRAM clock) */
234 #if defined(RCC_AHB2ENR_D2SRAM3EN)
236 #elif defined(RCC_AHB2ENR_D2SRAM2EN)
238 #else
239  RCC->AHB2ENR |= (RCC_AHB2ENR_AHBSRAM1EN | RCC_AHB2ENR_AHBSRAM2EN);
240 #endif /* RCC_AHB2ENR_D2SRAM3EN */
241 
242  tmpreg = RCC->AHB2ENR;
243  (void) tmpreg;
244 #endif /* DATA_IN_D2_SRAM */
245 
246 #if defined(DUAL_CORE) && defined(CORE_CM4)
247  /* Configure the Vector Table location add offset address for cortex-M4 ------------------*/
248 #ifdef VECT_TAB_SRAM
249  SCB->VTOR = D2_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
250 #else
251  SCB->VTOR = FLASH_BANK2_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
252 #endif /* VECT_TAB_SRAM */
253 
254 #else
255 
256  /*
257  * Disable the FMC bank1 (enabled after reset).
258  * This, prevents CPU speculation access on this bank which blocks the use of FMC during
259  * 24us. During this time the others FMC master (such as LTDC) cannot use it!
260  */
261  FMC_Bank1_R->BTCR[0] = 0x000030D2;
262 
263  /* Configure the Vector Table location add offset address for cortex-M7 ------------------*/
264 #ifdef VECT_TAB_SRAM
265  SCB->VTOR = D1_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal AXI-RAM */
266 #else
267  SCB->VTOR = FLASH_BANK1_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
268 #endif
269 
270 #endif /*DUAL_CORE && CORE_CM4*/
271 
272 }
273 
312 {
313  uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp;
314  uint32_t common_system_clock;
315  float_t fracn1, pllvco;
316 
317 
318  /* Get SYSCLK source -------------------------------------------------------*/
319 
320  switch (RCC->CFGR & RCC_CFGR_SWS)
321  {
322  case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
323  common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
324  break;
325 
326  case RCC_CFGR_SWS_CSI: /* CSI used as system clock source */
327  common_system_clock = CSI_VALUE;
328  break;
329 
330  case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
331  common_system_clock = HSE_VALUE;
332  break;
333 
334  case RCC_CFGR_SWS_PLL1: /* PLL1 used as system clock source */
335 
336  /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
337  SYSCLK = PLL_VCO / PLLR
338  */
339  pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
340  pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4) ;
341  pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
342  fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
343 
344  if (pllm != 0U)
345  {
346  switch (pllsource)
347  {
348  case RCC_PLLCKSELR_PLLSRC_HSI: /* HSI used as PLL clock source */
349 
350  hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
351  pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
352 
353  break;
354 
355  case RCC_PLLCKSELR_PLLSRC_CSI: /* CSI used as PLL clock source */
356  pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
357  break;
358 
359  case RCC_PLLCKSELR_PLLSRC_HSE: /* HSE used as PLL clock source */
360  pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
361  break;
362 
363  default:
364  hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
365  pllvco = ((float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
366  break;
367  }
368  pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
369  common_system_clock = (uint32_t)(float_t)(pllvco/(float_t)pllp);
370  }
371  else
372  {
373  common_system_clock = 0U;
374  }
375  break;
376 
377  default:
378  common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
379  break;
380  }
381 
382  /* Compute SystemClock frequency --------------------------------------------------*/
383 #if defined (RCC_D1CFGR_D1CPRE)
385 
386  /* common_system_clock frequency : CM7 CPU frequency */
387  common_system_clock >>= tmp;
388 
389  /* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency */
390  SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
391 
392 #else
393  tmp = D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos];
394 
395  /* common_system_clock frequency : CM7 CPU frequency */
396  common_system_clock >>= tmp;
397 
398  /* SystemD2Clock frequency : AXI and AHBs Clock frequency */
399  SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
400 
401 #endif
402 
403 #if defined(DUAL_CORE) && defined(CORE_CM4)
405 #else
406  SystemCoreClock = common_system_clock;
407 #endif /* DUAL_CORE && CORE_CM4 */
408 }
409 
410 
422 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
SCB
#define SCB
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:1778
RCC_CR_HSIDIV
#define RCC_CR_HSIDIV
Definition: stm32h735xx.h:14805
RCC_D1CFGR_HPRE_Pos
#define RCC_D1CFGR_HPRE_Pos
Definition: stm32h735xx.h:15037
FLASH_BANK2_BASE
#define FLASH_BANK2_BASE
Definition: stm32h747xx.h:2142
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
RCC_AHB2ENR_D2SRAM3EN
#define RCC_AHB2ENR_D2SRAM3EN
Definition: stm32h747xx.h:18944
RCC_D1CFGR_D1CPRE_Pos
#define RCC_D1CFGR_D1CPRE_Pos
Definition: stm32h735xx.h:15094
RCC_PLLCFGR_PLL1FRACEN_Pos
#define RCC_PLLCFGR_PLL1FRACEN_Pos
Definition: stm32h735xx.h:15245
DBGMCU
#define DBGMCU
Definition: stm32f407xx.h:1140
SystemCoreClockUpdate
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:311
D1CorePrescTable
const uint8_t D1CorePrescTable[16]
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:115
FLASH_LATENCY_DEFAULT
#define FLASH_LATENCY_DEFAULT
Definition: stm32h735xx.h:11056
RCC_AHB2ENR_D2SRAM1EN
#define RCC_AHB2ENR_D2SRAM1EN
Definition: stm32h735xx.h:15780
RCC_PLLCKSELR_PLLSRC_HSI
#define RCC_PLLCKSELR_PLLSRC_HSI
Definition: stm32h735xx.h:15202
RCC_PLLCFGR_PLL1FRACEN
#define RCC_PLLCFGR_PLL1FRACEN
Definition: stm32h735xx.h:15247
RCC_PLLCKSELR_PLLSRC_CSI
#define RCC_PLLCKSELR_PLLSRC_CSI
Definition: stm32h735xx.h:15205
RCC_D1CFGR_HPRE
#define RCC_D1CFGR_HPRE
Definition: stm32h735xx.h:15039
RCC_AHB2ENR_D2SRAM2EN
#define RCC_AHB2ENR_D2SRAM2EN
Definition: stm32h735xx.h:15783
VECT_TAB_OFFSET
#define VECT_TAB_OFFSET
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:86
RCC_CFGR_SWS
#define RCC_CFGR_SWS
Definition: stm32f407xx.h:9546
RCC_PLLCKSELR_DIVM1
#define RCC_PLLCKSELR_DIVM1
Definition: stm32h735xx.h:15215
FLASH_ACR_LATENCY
#define FLASH_ACR_LATENCY
Definition: stm32f407xx.h:6678
RCC_CFGR_SWS_PLL1
#define RCC_CFGR_SWS_PLL1
Definition: stm32h735xx.h:14977
MODIFY_REG
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:224
RCC_CR_HSION
#define RCC_CR_HSION
Definition: stm32f407xx.h:9428
RCC_CFGR_SWS_HSE
#define RCC_CFGR_SWS_HSE
Definition: stm32f407xx.h:9551
READ_BIT
#define READ_BIT(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:216
RCC_D1CFGR_D1CPRE
#define RCC_D1CFGR_D1CPRE
Definition: stm32h735xx.h:15096
FMC_Bank1_R
#define FMC_Bank1_R
Definition: stm32h735xx.h:2765
HSE_VALUE
#define HSE_VALUE
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:51
RCC_PLL1DIVR_P1
#define RCC_PLL1DIVR_P1
Definition: stm32h735xx.h:15324
D1_AXISRAM_BASE
#define D1_AXISRAM_BASE
Definition: stm32h735xx.h:2169
RCC
#define RCC
Definition: stm32f407xx.h:1113
HSI_VALUE
#define HSI_VALUE
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:59
FLASH_BANK1_BASE
#define FLASH_BANK1_BASE
Definition: stm32h735xx.h:2182
RCC_PLL1DIVR_N1
#define RCC_PLL1DIVR_N1
Definition: stm32h735xx.h:15321
RCC_PLLCKSELR_PLLSRC
#define RCC_PLLCKSELR_PLLSRC
Definition: stm32h735xx.h:15200
RCC_CFGR_SWS_HSI
#define RCC_CFGR_SWS_HSI
Definition: stm32f407xx.h:9550
FLASH
#define FLASH
Definition: stm32f407xx.h:1114
RCC_PLLCKSELR_PLLSRC_HSE
#define RCC_PLLCKSELR_PLLSRC_HSE
Definition: stm32h735xx.h:15208
RCC_CFGR_SWS_CSI
#define RCC_CFGR_SWS_CSI
Definition: stm32h735xx.h:14975
SystemCoreClock
uint32_t SystemCoreClock
System clock frequency (core clock)
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:113
RCC_PLL1FRACR_FRACN1
#define RCC_PLL1FRACR_FRACN1
Definition: stm32h735xx.h:15335
CSI_VALUE
#define CSI_VALUE
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:55
SystemD2Clock
uint32_t SystemD2Clock
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:114
SystemInit
void SystemInit(void)
Setup the microcontroller system Initialize the FPU setting and vector table location configuration.
Definition: stm32h735/stm32h735g-dk/Src/system_stm32h7xx.c:140
D2_AXISRAM_BASE
#define D2_AXISRAM_BASE
Definition: stm32h747xx.h:2132


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:55