diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1011/system_MIMXRT1011.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1011/system_MIMXRT1011.c | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1011/system_MIMXRT1011.c b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1011/system_MIMXRT1011.c new file mode 100644 index 000000000..90ec4868e --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1011/system_MIMXRT1011.c | |||
@@ -0,0 +1,227 @@ | |||
1 | /* | ||
2 | ** ################################################################### | ||
3 | ** Processors: MIMXRT1011CAE4A | ||
4 | ** MIMXRT1011DAE5A | ||
5 | ** | ||
6 | ** Compilers: Freescale C/C++ for Embedded ARM | ||
7 | ** GNU C Compiler | ||
8 | ** IAR ANSI C/C++ Compiler for ARM | ||
9 | ** Keil ARM C/C++ Compiler | ||
10 | ** MCUXpresso Compiler | ||
11 | ** | ||
12 | ** Reference manual: IMXRT1010RM Rev.0, 09/2019 | ||
13 | ** Version: rev. 1.1, 2019-08-06 | ||
14 | ** Build: b201016 | ||
15 | ** | ||
16 | ** Abstract: | ||
17 | ** Provides a system configuration function and a global variable that | ||
18 | ** contains the system frequency. It configures the device and initializes | ||
19 | ** the oscillator (PLL) that is part of the microcontroller device. | ||
20 | ** | ||
21 | ** Copyright 2016 Freescale Semiconductor, Inc. | ||
22 | ** Copyright 2016-2020 NXP | ||
23 | ** All rights reserved. | ||
24 | ** | ||
25 | ** SPDX-License-Identifier: BSD-3-Clause | ||
26 | ** | ||
27 | ** http: www.nxp.com | ||
28 | ** mail: [email protected] | ||
29 | ** | ||
30 | ** Revisions: | ||
31 | ** - rev. 0.1 (2019-02-14) | ||
32 | ** Initial version. | ||
33 | ** - rev. 1.0 (2019-08-01) | ||
34 | ** Rev.0 Header GA | ||
35 | ** - rev. 1.1 (2019-08-06) | ||
36 | ** Update header files to align with IMXRT1010RM Rev.B. | ||
37 | ** | ||
38 | ** ################################################################### | ||
39 | */ | ||
40 | |||
41 | /*! | ||
42 | * @file MIMXRT1011 | ||
43 | * @version 1.1 | ||
44 | * @date 2019-08-06 | ||
45 | * @brief Device specific configuration file for MIMXRT1011 (implementation file) | ||
46 | * | ||
47 | * Provides a system configuration function and a global variable that contains | ||
48 | * the system frequency. It configures the device and initializes the oscillator | ||
49 | * (PLL) that is part of the microcontroller device. | ||
50 | */ | ||
51 | |||
52 | #include <stdint.h> | ||
53 | #include "fsl_device_registers.h" | ||
54 | |||
55 | |||
56 | |||
57 | /* ---------------------------------------------------------------------------- | ||
58 | -- Core clock | ||
59 | ---------------------------------------------------------------------------- */ | ||
60 | |||
61 | uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK; | ||
62 | |||
63 | /* ---------------------------------------------------------------------------- | ||
64 | -- SystemInit() | ||
65 | ---------------------------------------------------------------------------- */ | ||
66 | |||
67 | void SystemInit (void) { | ||
68 | #if ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) | ||
69 | SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access in Secure mode */ | ||
70 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) | ||
71 | SCB_NS->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access in Non-secure mode */ | ||
72 | #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ | ||
73 | #endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */ | ||
74 | |||
75 | #if defined(__MCUXPRESSO) | ||
76 | extern uint32_t g_pfnVectors[]; // Vector table defined in startup code | ||
77 | SCB->VTOR = (uint32_t)g_pfnVectors; | ||
78 | #endif | ||
79 | |||
80 | /* Disable Watchdog Power Down Counter */ | ||
81 | WDOG1->WMCR &= ~(uint16_t) WDOG_WMCR_PDE_MASK; | ||
82 | WDOG2->WMCR &= ~(uint16_t) WDOG_WMCR_PDE_MASK; | ||
83 | |||
84 | /* Watchdog disable */ | ||
85 | |||
86 | #if (DISABLE_WDOG) | ||
87 | if ((WDOG1->WCR & WDOG_WCR_WDE_MASK) != 0U) | ||
88 | { | ||
89 | WDOG1->WCR &= ~(uint16_t) WDOG_WCR_WDE_MASK; | ||
90 | } | ||
91 | if ((WDOG2->WCR & WDOG_WCR_WDE_MASK) != 0U) | ||
92 | { | ||
93 | WDOG2->WCR &= ~(uint16_t) WDOG_WCR_WDE_MASK; | ||
94 | } | ||
95 | if ((RTWDOG->CS & RTWDOG_CS_CMD32EN_MASK) != 0U) | ||
96 | { | ||
97 | RTWDOG->CNT = 0xD928C520U; /* 0xD928C520U is the update key */ | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | RTWDOG->CNT = 0xC520U; | ||
102 | RTWDOG->CNT = 0xD928U; | ||
103 | } | ||
104 | RTWDOG->TOVAL = 0xFFFF; | ||
105 | RTWDOG->CS = (uint32_t) ((RTWDOG->CS) & ~RTWDOG_CS_EN_MASK) | RTWDOG_CS_UPDATE_MASK; | ||
106 | #endif /* (DISABLE_WDOG) */ | ||
107 | |||
108 | /* Disable Systick which might be enabled by bootrom */ | ||
109 | if ((SysTick->CTRL & SysTick_CTRL_ENABLE_Msk) != 0U) | ||
110 | { | ||
111 | SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; | ||
112 | } | ||
113 | |||
114 | /* Enable instruction and data caches */ | ||
115 | #if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT | ||
116 | if (SCB_CCR_IC_Msk != (SCB_CCR_IC_Msk & SCB->CCR)) { | ||
117 | SCB_EnableICache(); | ||
118 | } | ||
119 | #endif | ||
120 | #if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT | ||
121 | if (SCB_CCR_DC_Msk != (SCB_CCR_DC_Msk & SCB->CCR)) { | ||
122 | SCB_EnableDCache(); | ||
123 | } | ||
124 | #endif | ||
125 | |||
126 | SystemInitHook(); | ||
127 | } | ||
128 | |||
129 | /* ---------------------------------------------------------------------------- | ||
130 | -- SystemCoreClockUpdate() | ||
131 | ---------------------------------------------------------------------------- */ | ||
132 | |||
133 | void SystemCoreClockUpdate (void) { | ||
134 | |||
135 | uint32_t freq; | ||
136 | uint32_t PLL2MainClock; | ||
137 | uint32_t PLL3MainClock; | ||
138 | |||
139 | /* Check if system pll is bypassed */ | ||
140 | if((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_BYPASS_MASK) != 0U) | ||
141 | { | ||
142 | PLL2MainClock = CPU_XTAL_CLK_HZ; | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | PLL2MainClock = (CPU_XTAL_CLK_HZ * (((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK) != 0U) ? 22U : 20U)); | ||
147 | } | ||
148 | PLL2MainClock += (uint32_t)(((uint64_t)CPU_XTAL_CLK_HZ * ((uint64_t)(CCM_ANALOG->PLL_SYS_NUM))) / ((uint64_t)(CCM_ANALOG->PLL_SYS_DENOM))); | ||
149 | |||
150 | /* Check if usb1 pll is bypassed */ | ||
151 | if((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_BYPASS_MASK) != 0U) | ||
152 | { | ||
153 | PLL3MainClock = CPU_XTAL_CLK_HZ; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | PLL3MainClock = (CPU_XTAL_CLK_HZ * (((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) != 0U) ? 22U : 20U)); | ||
158 | } | ||
159 | |||
160 | /* Periph_clk2_clk ---> Periph_clk */ | ||
161 | if ((CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK) != 0U) | ||
162 | { | ||
163 | switch (CCM->CBCMR & CCM_CBCMR_PERIPH_CLK2_SEL_MASK) | ||
164 | { | ||
165 | /* Pll3_sw_clk ---> Periph_clk2_clk ---> Periph_clk ---> Core_clock */ | ||
166 | case CCM_CBCMR_PERIPH_CLK2_SEL(0U): | ||
167 | freq = PLL3MainClock; | ||
168 | break; | ||
169 | |||
170 | /* Osc_clk ---> Periph_clk2_clk ---> Periph_clk ---> Core_clock */ | ||
171 | case CCM_CBCMR_PERIPH_CLK2_SEL(1U): | ||
172 | freq = CPU_XTAL_CLK_HZ; | ||
173 | break; | ||
174 | |||
175 | /* Pll2_bypass_clk ---> Periph_clk2_clk ---> Periph_clk ---> Core_clock */ | ||
176 | case CCM_CBCMR_PERIPH_CLK2_SEL(2U): | ||
177 | freq = CPU_XTAL_CLK_HZ; | ||
178 | break; | ||
179 | |||
180 | case CCM_CBCMR_PERIPH_CLK2_SEL(3U): | ||
181 | default: | ||
182 | freq = 0U; | ||
183 | break; | ||
184 | } | ||
185 | } | ||
186 | /* Pre_Periph_clk ---> Periph_clk */ | ||
187 | else | ||
188 | { | ||
189 | switch (CCM->CBCMR & CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK) | ||
190 | { | ||
191 | /* PLL2 ---> Pre_Periph_clk ---> Periph_clk ---> Core_clock */ | ||
192 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(0U): | ||
193 | freq = PLL2MainClock; | ||
194 | break; | ||
195 | |||
196 | /* PLL3 PFD3 ---> Pre_Periph_clk ---> Periph_clk ---> Core_clock */ | ||
197 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(1U): | ||
198 | freq = PLL3MainClock / ((CCM_ANALOG->PFD_480 & CCM_ANALOG_PFD_480_PFD3_FRAC_MASK) >> CCM_ANALOG_PFD_480_PFD3_FRAC_SHIFT) * 18U; | ||
199 | break; | ||
200 | |||
201 | /* PLL2 PFD3 ---> Pre_Periph_clk ---> Periph_clk ---> Core_clock */ | ||
202 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(2U): | ||
203 | freq = PLL2MainClock / ((CCM_ANALOG->PFD_528 & CCM_ANALOG_PFD_528_PFD3_FRAC_MASK) >> CCM_ANALOG_PFD_528_PFD3_FRAC_SHIFT) * 18U; | ||
204 | break; | ||
205 | |||
206 | /* PLL6 ---> Pre_Periph_clk ---> Periph_clk ---> Core_clock */ | ||
207 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(3U): | ||
208 | freq = 500000000U; | ||
209 | break; | ||
210 | |||
211 | default: | ||
212 | freq = 0U; | ||
213 | break; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | SystemCoreClock = (freq / (((CCM->CBCDR & CCM_CBCDR_AHB_PODF_MASK) >> CCM_CBCDR_AHB_PODF_SHIFT) + 1U)); | ||
218 | |||
219 | } | ||
220 | |||
221 | /* ---------------------------------------------------------------------------- | ||
222 | -- SystemInitHook() | ||
223 | ---------------------------------------------------------------------------- */ | ||
224 | |||
225 | __attribute__ ((weak)) void SystemInitHook (void) { | ||
226 | /* Void implementation of the weak function. */ | ||
227 | } | ||