diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1061/system_MIMXRT1061.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1061/system_MIMXRT1061.c | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1061/system_MIMXRT1061.c b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1061/system_MIMXRT1061.c new file mode 100644 index 000000000..c18072d3b --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1061/system_MIMXRT1061.c | |||
@@ -0,0 +1,245 @@ | |||
1 | /* | ||
2 | ** ################################################################### | ||
3 | ** Processors: MIMXRT1061CVJ5A | ||
4 | ** MIMXRT1061CVL5A | ||
5 | ** MIMXRT1061DVJ6A | ||
6 | ** MIMXRT1061DVL6A | ||
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: IMXRT1060RM Rev.1, 12/2018 | IMXRT1060SRM Rev.3 | ||
15 | ** Version: rev. 1.2, 2019-04-29 | ||
16 | ** Build: b201012 | ||
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-2020 NXP | ||
25 | ** All rights reserved. | ||
26 | ** | ||
27 | ** SPDX-License-Identifier: BSD-3-Clause | ||
28 | ** | ||
29 | ** http: www.nxp.com | ||
30 | ** mail: [email protected] | ||
31 | ** | ||
32 | ** Revisions: | ||
33 | ** - rev. 0.1 (2017-01-10) | ||
34 | ** Initial version. | ||
35 | ** - rev. 1.0 (2018-11-16) | ||
36 | ** Update header files to align with IMXRT1060RM Rev.0. | ||
37 | ** - rev. 1.1 (2018-11-27) | ||
38 | ** Update header files to align with IMXRT1060RM Rev.1. | ||
39 | ** - rev. 1.2 (2019-04-29) | ||
40 | ** Add SET/CLR/TOG register group to register CTRL, STAT, CHANNELCTRL, CH0STAT, CH0OPTS, CH1STAT, CH1OPTS, CH2STAT, CH2OPTS, CH3STAT, CH3OPTS of DCP module. | ||
41 | ** | ||
42 | ** ################################################################### | ||
43 | */ | ||
44 | |||
45 | /*! | ||
46 | * @file MIMXRT1061 | ||
47 | * @version 1.2 | ||
48 | * @date 2019-04-29 | ||
49 | * @brief Device specific configuration file for MIMXRT1061 (implementation file) | ||
50 | * | ||
51 | * Provides a system configuration function and a global variable that contains | ||
52 | * the system frequency. It configures the device and initializes the oscillator | ||
53 | * (PLL) that is part of the microcontroller device. | ||
54 | */ | ||
55 | |||
56 | #include <stdint.h> | ||
57 | #include "fsl_device_registers.h" | ||
58 | |||
59 | |||
60 | |||
61 | /* ---------------------------------------------------------------------------- | ||
62 | -- Core clock | ||
63 | ---------------------------------------------------------------------------- */ | ||
64 | |||
65 | uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK; | ||
66 | |||
67 | /* ---------------------------------------------------------------------------- | ||
68 | -- SystemInit() | ||
69 | ---------------------------------------------------------------------------- */ | ||
70 | |||
71 | void SystemInit (void) { | ||
72 | #if ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) | ||
73 | SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access in Secure mode */ | ||
74 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) | ||
75 | SCB_NS->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access in Non-secure mode */ | ||
76 | #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ | ||
77 | #endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */ | ||
78 | |||
79 | #if defined(__MCUXPRESSO) | ||
80 | extern uint32_t g_pfnVectors[]; // Vector table defined in startup code | ||
81 | SCB->VTOR = (uint32_t)g_pfnVectors; | ||
82 | #endif | ||
83 | |||
84 | /* Disable Watchdog Power Down Counter */ | ||
85 | WDOG1->WMCR &= ~(uint16_t) WDOG_WMCR_PDE_MASK; | ||
86 | WDOG2->WMCR &= ~(uint16_t) WDOG_WMCR_PDE_MASK; | ||
87 | |||
88 | /* Watchdog disable */ | ||
89 | |||
90 | #if (DISABLE_WDOG) | ||
91 | if ((WDOG1->WCR & WDOG_WCR_WDE_MASK) != 0U) | ||
92 | { | ||
93 | WDOG1->WCR &= ~(uint16_t) WDOG_WCR_WDE_MASK; | ||
94 | } | ||
95 | if ((WDOG2->WCR & WDOG_WCR_WDE_MASK) != 0U) | ||
96 | { | ||
97 | WDOG2->WCR &= ~(uint16_t) WDOG_WCR_WDE_MASK; | ||
98 | } | ||
99 | if ((RTWDOG->CS & RTWDOG_CS_CMD32EN_MASK) != 0U) | ||
100 | { | ||
101 | RTWDOG->CNT = 0xD928C520U; /* 0xD928C520U is the update key */ | ||
102 | } | ||
103 | else | ||
104 | { | ||
105 | RTWDOG->CNT = 0xC520U; | ||
106 | RTWDOG->CNT = 0xD928U; | ||
107 | } | ||
108 | RTWDOG->TOVAL = 0xFFFF; | ||
109 | RTWDOG->CS = (uint32_t) ((RTWDOG->CS) & ~RTWDOG_CS_EN_MASK) | RTWDOG_CS_UPDATE_MASK; | ||
110 | #endif /* (DISABLE_WDOG) */ | ||
111 | |||
112 | /* Disable Systick which might be enabled by bootrom */ | ||
113 | if ((SysTick->CTRL & SysTick_CTRL_ENABLE_Msk) != 0U) | ||
114 | { | ||
115 | SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; | ||
116 | } | ||
117 | |||
118 | /* Enable instruction and data caches */ | ||
119 | #if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT | ||
120 | if (SCB_CCR_IC_Msk != (SCB_CCR_IC_Msk & SCB->CCR)) { | ||
121 | SCB_EnableICache(); | ||
122 | } | ||
123 | #endif | ||
124 | #if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT | ||
125 | if (SCB_CCR_DC_Msk != (SCB_CCR_DC_Msk & SCB->CCR)) { | ||
126 | SCB_EnableDCache(); | ||
127 | } | ||
128 | #endif | ||
129 | |||
130 | SystemInitHook(); | ||
131 | } | ||
132 | |||
133 | /* ---------------------------------------------------------------------------- | ||
134 | -- SystemCoreClockUpdate() | ||
135 | ---------------------------------------------------------------------------- */ | ||
136 | |||
137 | void SystemCoreClockUpdate (void) { | ||
138 | |||
139 | uint32_t freq; | ||
140 | uint32_t PLL1MainClock; | ||
141 | uint32_t PLL2MainClock; | ||
142 | |||
143 | /* Periph_clk2_clk ---> Periph_clk */ | ||
144 | if ((CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK) != 0U) | ||
145 | { | ||
146 | switch (CCM->CBCMR & CCM_CBCMR_PERIPH_CLK2_SEL_MASK) | ||
147 | { | ||
148 | /* Pll3_sw_clk ---> Periph_clk2_clk ---> Periph_clk */ | ||
149 | case CCM_CBCMR_PERIPH_CLK2_SEL(0U): | ||
150 | if((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_BYPASS_MASK) != 0U) | ||
151 | { | ||
152 | freq = (((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_BYPASS_CLK_SRC_MASK) >> CCM_ANALOG_PLL_USB1_BYPASS_CLK_SRC_SHIFT) == 0U) ? | ||
153 | CPU_XTAL_CLK_HZ : CPU_CLK1_HZ; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | freq = (CPU_XTAL_CLK_HZ * (((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) != 0U) ? 22U : 20U)); | ||
158 | } | ||
159 | break; | ||
160 | |||
161 | /* Osc_clk ---> Periph_clk2_clk ---> Periph_clk */ | ||
162 | case CCM_CBCMR_PERIPH_CLK2_SEL(1U): | ||
163 | freq = CPU_XTAL_CLK_HZ; | ||
164 | break; | ||
165 | |||
166 | case CCM_CBCMR_PERIPH_CLK2_SEL(2U): | ||
167 | freq = (((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_MASK) >> CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_SHIFT) == 0U) ? | ||
168 | CPU_XTAL_CLK_HZ : CPU_CLK1_HZ; | ||
169 | break; | ||
170 | |||
171 | case CCM_CBCMR_PERIPH_CLK2_SEL(3U): | ||
172 | default: | ||
173 | freq = 0U; | ||
174 | break; | ||
175 | } | ||
176 | |||
177 | freq /= (((CCM->CBCDR & CCM_CBCDR_PERIPH_CLK2_PODF_MASK) >> CCM_CBCDR_PERIPH_CLK2_PODF_SHIFT) + 1U); | ||
178 | } | ||
179 | /* Pre_Periph_clk ---> Periph_clk */ | ||
180 | else | ||
181 | { | ||
182 | /* check if pll is bypassed */ | ||
183 | if((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_BYPASS_MASK) != 0U) | ||
184 | { | ||
185 | PLL1MainClock = (((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_BYPASS_CLK_SRC_MASK) >> CCM_ANALOG_PLL_ARM_BYPASS_CLK_SRC_SHIFT) == 0U) ? | ||
186 | CPU_XTAL_CLK_HZ : CPU_CLK1_HZ; | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | PLL1MainClock = ((CPU_XTAL_CLK_HZ * ((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK) >> | ||
191 | CCM_ANALOG_PLL_ARM_DIV_SELECT_SHIFT)) >> 1U); | ||
192 | } | ||
193 | |||
194 | /* check if pll is bypassed */ | ||
195 | if((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_BYPASS_MASK) != 0U) | ||
196 | { | ||
197 | PLL2MainClock = (((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_MASK) >> CCM_ANALOG_PLL_SYS_BYPASS_CLK_SRC_SHIFT) == 0U) ? | ||
198 | CPU_XTAL_CLK_HZ : CPU_CLK1_HZ; | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | PLL2MainClock = (CPU_XTAL_CLK_HZ * (((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK) != 0U) ? 22U : 20U)); | ||
203 | } | ||
204 | PLL2MainClock += (uint32_t)(((uint64_t)CPU_XTAL_CLK_HZ * ((uint64_t)(CCM_ANALOG->PLL_SYS_NUM))) / ((uint64_t)(CCM_ANALOG->PLL_SYS_DENOM))); | ||
205 | |||
206 | |||
207 | switch (CCM->CBCMR & CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK) | ||
208 | { | ||
209 | /* PLL2 ---> Pre_Periph_clk ---> Periph_clk */ | ||
210 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(0U): | ||
211 | freq = PLL2MainClock; | ||
212 | break; | ||
213 | |||
214 | /* PLL2 PFD2 ---> Pre_Periph_clk ---> Periph_clk */ | ||
215 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(1U): | ||
216 | freq = PLL2MainClock / ((CCM_ANALOG->PFD_528 & CCM_ANALOG_PFD_528_PFD2_FRAC_MASK) >> CCM_ANALOG_PFD_528_PFD2_FRAC_SHIFT) * 18U; | ||
217 | break; | ||
218 | |||
219 | /* PLL2 PFD0 ---> Pre_Periph_clk ---> Periph_clk */ | ||
220 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(2U): | ||
221 | freq = PLL2MainClock / ((CCM_ANALOG->PFD_528 & CCM_ANALOG_PFD_528_PFD0_FRAC_MASK) >> CCM_ANALOG_PFD_528_PFD0_FRAC_SHIFT) * 18U; | ||
222 | break; | ||
223 | |||
224 | /* PLL1 divided(/2) ---> Pre_Periph_clk ---> Periph_clk */ | ||
225 | case CCM_CBCMR_PRE_PERIPH_CLK_SEL(3U): | ||
226 | freq = PLL1MainClock / (((CCM->CACRR & CCM_CACRR_ARM_PODF_MASK) >> CCM_CACRR_ARM_PODF_SHIFT) + 1U); | ||
227 | break; | ||
228 | |||
229 | default: | ||
230 | freq = 0U; | ||
231 | break; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | SystemCoreClock = (freq / (((CCM->CBCDR & CCM_CBCDR_AHB_PODF_MASK) >> CCM_CBCDR_AHB_PODF_SHIFT) + 1U)); | ||
236 | |||
237 | } | ||
238 | |||
239 | /* ---------------------------------------------------------------------------- | ||
240 | -- SystemInitHook() | ||
241 | ---------------------------------------------------------------------------- */ | ||
242 | |||
243 | __attribute__ ((weak)) void SystemInitHook (void) { | ||
244 | /* Void implementation of the weak function. */ | ||
245 | } | ||