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