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