system_MIMXRT1052.c
Go to the documentation of this file.
1 /*
2 ** ###################################################################
3 ** Processors: MIMXRT1052CVJ5B
4 ** MIMXRT1052CVL5B
5 ** MIMXRT1052DVJ6B
6 ** MIMXRT1052DVL6B
7 **
8 ** Compilers: Freescale C/C++ for Embedded ARM
9 ** GNU C Compiler
10 ** IAR ANSI C/C++ Compiler for ARM
11 ** Keil ARM C/C++ Compiler
12 ** MCUXpresso Compiler
13 **
14 ** Reference manual: IMXRT1050RM Rev.2.1, 12/2018 | IMXRT1050SRM Rev.2
15 ** Version: rev. 1.3, 2019-04-29
16 ** Build: b191113
17 **
18 ** Abstract:
19 ** Provides a system configuration function and a global variable that
20 ** contains the system frequency. It configures the device and initializes
21 ** the oscillator (PLL) that is part of the microcontroller device.
22 **
23 ** Copyright 2016 Freescale Semiconductor, Inc.
24 ** Copyright 2016-2019 NXP
25 ** All rights reserved.
26 **
27 ** SPDX-License-Identifier: BSD-3-Clause
28 **
29 ** http: www.nxp.com
30 ** mail: support@nxp.com
31 **
32 ** Revisions:
33 ** - rev. 0.1 (2017-01-10)
34 ** Initial version.
35 ** - rev. 1.0 (2018-09-21)
36 ** Update interrupt vector table and dma request source.
37 ** Update register BEE_ADDR_OFFSET1's bitfield name to ADDR_OFFSET1.
38 ** Split GPIO_COMBINED_IRQS to GPIO_COMBINED_LOW_IRQS and GPIO_COMBINED_HIGH_IRQS.
39 ** - rev. 1.1 (2018-11-16)
40 ** Update header files to align with IMXRT1050RM Rev.1.
41 ** - rev. 1.2 (2018-11-27)
42 ** Update header files to align with IMXRT1050RM Rev.2.1.
43 ** - rev. 1.3 (2019-04-29)
44 ** Add SET/CLR/TOG register group to register CTRL, STAT, CHANNELCTRL, CH0STAT, CH0OPTS, CH1STAT, CH1OPTS, CH2STAT, CH2OPTS, CH3STAT, CH3OPTS of DCP module.
45 **
46 ** ###################################################################
47 */
48 
60 #include <stdint.h>
61 #include "fsl_device_registers.h"
62 
63 
64 
65 /* ----------------------------------------------------------------------------
66  -- Core clock
67  ---------------------------------------------------------------------------- */
68 
70 
71 /* ----------------------------------------------------------------------------
72  -- SystemInit()
73  ---------------------------------------------------------------------------- */
74 
75 void SystemInit (void) {
76 #if ((__FPU_PRESENT == 1) && (__FPU_USED == 1))
77  SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access */
78 #endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */
79 
80 #if defined(__MCUXPRESSO)
81  extern uint32_t g_pfnVectors[]; // Vector table defined in startup code
82  SCB->VTOR = (uint32_t)g_pfnVectors;
83 #endif
84 
85 /* Disable Watchdog Power Down Counter */
86 WDOG1->WMCR &= ~WDOG_WMCR_PDE_MASK;
87 WDOG2->WMCR &= ~WDOG_WMCR_PDE_MASK;
88 
89 /* Watchdog disable */
90 
91 #if (DISABLE_WDOG)
92  if ((WDOG1->WCR & WDOG_WCR_WDE_MASK) != 0U)
93  {
94  WDOG1->WCR &= ~WDOG_WCR_WDE_MASK;
95  }
96  if ((WDOG2->WCR & WDOG_WCR_WDE_MASK) != 0U)
97  {
98  WDOG2->WCR &= ~WDOG_WCR_WDE_MASK;
99  }
100  if ((RTWDOG->CS & RTWDOG_CS_CMD32EN_MASK) != 0U)
101  {
102  RTWDOG->CNT = 0xD928C520U; /* 0xD928C520U is the update key */
103  }
104  else
105  {
106  RTWDOG->CNT = 0xC520U;
107  RTWDOG->CNT = 0xD928U;
108  }
109  RTWDOG->TOVAL = 0xFFFF;
110  RTWDOG->CS = (uint32_t) ((RTWDOG->CS) & ~RTWDOG_CS_EN_MASK) | RTWDOG_CS_UPDATE_MASK;
111 #endif /* (DISABLE_WDOG) */
112 
113  /* Disable Systick which might be enabled by bootrom */
114  if ((SysTick->CTRL & SysTick_CTRL_ENABLE_Msk) != 0U)
115  {
117  }
118 
119 /* Enable instruction and data caches */
120 #if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT
121  if (SCB_CCR_IC_Msk != (SCB_CCR_IC_Msk & SCB->CCR)) {
123  }
124 #endif
125 #if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT
126  if (SCB_CCR_DC_Msk != (SCB_CCR_DC_Msk & SCB->CCR)) {
128  }
129 #endif
130 
131  SystemInitHook();
132 }
133 
134 /* ----------------------------------------------------------------------------
135  -- SystemCoreClockUpdate()
136  ---------------------------------------------------------------------------- */
137 
139 
140  uint32_t freq;
141  uint32_t PLL1MainClock;
142  uint32_t PLL2MainClock;
143 
144  /* Periph_clk2_clk ---> Periph_clk */
145  if ((CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK) != 0U)
146  {
147  switch (CCM->CBCMR & CCM_CBCMR_PERIPH_CLK2_SEL_MASK)
148  {
149  /* Pll3_sw_clk ---> Periph_clk2_clk ---> Periph_clk */
150  case CCM_CBCMR_PERIPH_CLK2_SEL(0U):
151  if((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_BYPASS_MASK) != 0U)
152  {
155  }
156  else
157  {
158  freq = (CPU_XTAL_CLK_HZ * (((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) != 0U) ? 22U : 20U));
159  }
160  break;
161 
162  /* Osc_clk ---> Periph_clk2_clk ---> Periph_clk */
163  case CCM_CBCMR_PERIPH_CLK2_SEL(1U):
164  freq = CPU_XTAL_CLK_HZ;
165  break;
166 
167  case CCM_CBCMR_PERIPH_CLK2_SEL(2U):
170  break;
171 
172  case CCM_CBCMR_PERIPH_CLK2_SEL(3U):
173  default:
174  freq = 0U;
175  break;
176  }
177 
179  }
180  /* Pre_Periph_clk ---> Periph_clk */
181  else
182  {
183  /* check if pll is bypassed */
184  if((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_BYPASS_MASK) != 0U)
185  {
188  }
189  else
190  {
191  PLL1MainClock = ((CPU_XTAL_CLK_HZ * ((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK) >>
193  }
194 
195  /* check if pll is bypassed */
196  if((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_BYPASS_MASK) != 0U)
197  {
200  }
201  else
202  {
203  PLL2MainClock = (CPU_XTAL_CLK_HZ * (((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK) != 0U) ? 22U : 20U));
204  }
205  PLL2MainClock += (uint32_t)(((uint64_t)CPU_XTAL_CLK_HZ * ((uint64_t)(CCM_ANALOG->PLL_SYS_NUM))) / ((uint64_t)(CCM_ANALOG->PLL_SYS_DENOM)));
206 
207 
208  switch (CCM->CBCMR & CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
209  {
210  /* PLL2 ---> Pre_Periph_clk ---> Periph_clk */
212  freq = PLL2MainClock;
213  break;
214 
215  /* PLL2 PFD2 ---> Pre_Periph_clk ---> Periph_clk */
217  freq = PLL2MainClock / ((CCM_ANALOG->PFD_528 & CCM_ANALOG_PFD_528_PFD2_FRAC_MASK) >> CCM_ANALOG_PFD_528_PFD2_FRAC_SHIFT) * 18U;
218  break;
219 
220  /* PLL2 PFD0 ---> Pre_Periph_clk ---> Periph_clk */
222  freq = PLL2MainClock / ((CCM_ANALOG->PFD_528 & CCM_ANALOG_PFD_528_PFD0_FRAC_MASK) >> CCM_ANALOG_PFD_528_PFD0_FRAC_SHIFT) * 18U;
223  break;
224 
225  /* PLL1 divided(/2) ---> Pre_Periph_clk ---> Periph_clk */
227  freq = PLL1MainClock / (((CCM->CACRR & CCM_CACRR_ARM_PODF_MASK) >> CCM_CACRR_ARM_PODF_SHIFT) + 1U);
228  break;
229 
230  default:
231  freq = 0U;
232  break;
233  }
234  }
235 
236  SystemCoreClock = (freq / (((CCM->CBCDR & CCM_CBCDR_AHB_PODF_MASK) >> CCM_CBCDR_AHB_PODF_SHIFT) + 1U));
237 
238 }
239 
240 /* ----------------------------------------------------------------------------
241  -- SystemInitHook()
242  ---------------------------------------------------------------------------- */
243 
244 __attribute__ ((weak)) void SystemInitHook (void) {
245  /* Void implementation of the weak function. */
246 }
SCB
#define SCB
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:1778
CCM_ANALOG_PLL_USB1_BYPASS_CLK_SRC_SHIFT
#define CCM_ANALOG_PLL_USB1_BYPASS_CLK_SRC_SHIFT
Definition: MIMXRT1052.h:6290
CCM_ANALOG
#define CCM_ANALOG
Definition: MIMXRT1052.h:8520
CPU_XTAL_CLK_HZ
#define CPU_XTAL_CLK_HZ
Definition: system_MIMXRT1052.h:76
SystemCoreClockUpdate
void SystemCoreClockUpdate(void)
Update SystemCoreClock variable according to Clock Register Values. The SystemCoreClock variable cont...
Definition: system_MIMXRT1052.c:138
CCM_CBCDR_AHB_PODF_SHIFT
#define CCM_CBCDR_AHB_PODF_SHIFT
Definition: MIMXRT1052.h:4313
CCM_ANALOG_PLL_ARM_BYPASS_MASK
#define CCM_ANALOG_PLL_ARM_BYPASS_MASK
Definition: MIMXRT1052.h:6167
CCM_ANALOG_PFD_528_PFD0_FRAC_SHIFT
#define CCM_ANALOG_PFD_528_PFD0_FRAC_SHIFT
Definition: MIMXRT1052.h:7321
RTWDOG_CS_CMD32EN_MASK
#define RTWDOG_CS_CMD32EN_MASK
Definition: MIMXRT1052.h:34027
CCM_CBCDR_PERIPH_CLK_SEL_MASK
#define CCM_CBCDR_PERIPH_CLK_SEL_MASK
Definition: MIMXRT1052.h:4338
SCB_CCR_DC_Msk
#define SCB_CCR_DC_Msk
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:600
CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK
#define CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK
Definition: MIMXRT1052.h:4389
CCM_CBCDR_PERIPH_CLK2_PODF_MASK
#define CCM_CBCDR_PERIPH_CLK2_PODF_MASK
Definition: MIMXRT1052.h:4345
CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK
#define CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK
Definition: MIMXRT1052.h:6149
WDOG_WCR_WDE_MASK
#define WDOG_WCR_WDE_MASK
Definition: MIMXRT1052.h:43969
WDOG1
#define WDOG1
Definition: MIMXRT1052.h:44107
CCM_CBCMR_PERIPH_CLK2_SEL_MASK
#define CCM_CBCMR_PERIPH_CLK2_SEL_MASK
Definition: MIMXRT1052.h:4371
DEFAULT_SYSTEM_CLOCK
#define DEFAULT_SYSTEM_CLOCK
Definition: system_MIMXRT1052.h:81
RTWDOG
#define RTWDOG
Definition: MIMXRT1052.h:34102
CCM_ANALOG_PLL_ARM_BYPASS_CLK_SRC_MASK
#define CCM_ANALOG_PLL_ARM_BYPASS_CLK_SRC_MASK
Definition: MIMXRT1052.h:6158
SCB_EnableICache
__STATIC_FORCEINLINE void SCB_EnableICache(void)
Enable I-Cache.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:2241
SystemInit
void SystemInit(void)
Setup the microcontroller system Initialize the FPU setting, vector table location and External memor...
Definition: system_MIMXRT1052.c:75
__attribute__
__attribute__((weak))
Definition: system_MIMXRT1052.c:244
RTWDOG_CS_UPDATE_MASK
#define RTWDOG_CS_UPDATE_MASK
Definition: MIMXRT1052.h:33976
fsl_device_registers.h
CCM_CBCDR_AHB_PODF_MASK
#define CCM_CBCDR_AHB_PODF_MASK
Definition: MIMXRT1052.h:4312
CCM_CBCMR_PERIPH_CLK2_SEL
#define CCM_CBCMR_PERIPH_CLK2_SEL(x)
Definition: MIMXRT1052.h:4379
CCM_ANALOG_PLL_ARM_BYPASS_CLK_SRC_SHIFT
#define CCM_ANALOG_PLL_ARM_BYPASS_CLK_SRC_SHIFT
Definition: MIMXRT1052.h:6159
CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK
#define CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK
Definition: MIMXRT1052.h:6273
CPU_CLK1_HZ
#define CPU_CLK1_HZ
Definition: system_MIMXRT1052.h:78
CCM_ANALOG_PLL_USB1_BYPASS_MASK
#define CCM_ANALOG_PLL_USB1_BYPASS_MASK
Definition: MIMXRT1052.h:6296
CCM_CBCMR_PRE_PERIPH_CLK_SEL
#define CCM_CBCMR_PRE_PERIPH_CLK_SEL(x)
Definition: MIMXRT1052.h:4397
CCM
#define CCM
Definition: MIMXRT1052.h:6049
CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_MASK
#define CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_MASK
Definition: MIMXRT1052.h:6538
WDOG2
#define WDOG2
Definition: MIMXRT1052.h:44111
CCM_ANALOG_PFD_528_PFD2_FRAC_SHIFT
#define CCM_ANALOG_PFD_528_PFD2_FRAC_SHIFT
Definition: MIMXRT1052.h:7339
CCM_ANALOG_PLL_SYS_BYPASS_MASK
#define CCM_ANALOG_PLL_SYS_BYPASS_MASK
Definition: MIMXRT1052.h:6545
CCM_CACRR_ARM_PODF_SHIFT
#define CCM_CACRR_ARM_PODF_SHIFT
Definition: MIMXRT1052.h:4273
SCB_CCR_IC_Msk
#define SCB_CCR_IC_Msk
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:597
WDOG_WMCR_PDE_MASK
#define WDOG_WMCR_PDE_MASK
Definition: MIMXRT1052.h:44088
SCB_EnableDCache
__STATIC_FORCEINLINE void SCB_EnableDCache(void)
Enable D-Cache.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:2325
SysTick_CTRL_ENABLE_Msk
#define SysTick_CTRL_ENABLE_Msk
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:998
CCM_ANALOG_PFD_528_PFD0_FRAC_MASK
#define CCM_ANALOG_PFD_528_PFD0_FRAC_MASK
Definition: MIMXRT1052.h:7320
SystemInitHook
void SystemInitHook(void)
SystemInit function hook.
CCM_CACRR_ARM_PODF_MASK
#define CCM_CACRR_ARM_PODF_MASK
Definition: MIMXRT1052.h:4272
CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK
#define CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK
Definition: MIMXRT1052.h:6529
CCM_ANALOG_PLL_ARM_DIV_SELECT_SHIFT
#define CCM_ANALOG_PLL_ARM_DIV_SELECT_SHIFT
Definition: MIMXRT1052.h:6150
RTWDOG_CS_EN_MASK
#define RTWDOG_CS_EN_MASK
Definition: MIMXRT1052.h:33990
SysTick
#define SysTick
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:1779
CCM_ANALOG_PFD_528_PFD2_FRAC_MASK
#define CCM_ANALOG_PFD_528_PFD2_FRAC_MASK
Definition: MIMXRT1052.h:7338
CCM_ANALOG_PLL_USB1_BYPASS_CLK_SRC_MASK
#define CCM_ANALOG_PLL_USB1_BYPASS_CLK_SRC_MASK
Definition: MIMXRT1052.h:6289
CCM_CBCDR_PERIPH_CLK2_PODF_SHIFT
#define CCM_CBCDR_PERIPH_CLK2_PODF_SHIFT
Definition: MIMXRT1052.h:4346
CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_SHIFT
#define CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_SHIFT
Definition: MIMXRT1052.h:6539
SystemCoreClock
uint32_t SystemCoreClock
System clock frequency (core clock)
Definition: system_MIMXRT1052.c:69


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