diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mq/project_template/clock_config.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mq/project_template/clock_config.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mq/project_template/clock_config.c b/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mq/project_template/clock_config.c new file mode 100644 index 000000000..8f13460ee --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/boards/evkmimx8mq/project_template/clock_config.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | * Copyright 2017 NXP | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * SPDX-License-Identifier: BSD-3-Clause | ||
6 | */ | ||
7 | |||
8 | #include "fsl_common.h" | ||
9 | #include "clock_config.h" | ||
10 | |||
11 | /******************************************************************************* | ||
12 | * Definitions | ||
13 | ******************************************************************************/ | ||
14 | |||
15 | /* OSC 27M configuration */ | ||
16 | const osc_config_t g_osc27MConfig = { | ||
17 | .oscMode = kOSC_OscMode, | ||
18 | .oscDiv = 1U, | ||
19 | }; | ||
20 | |||
21 | /* OSC 25M configuration */ | ||
22 | const osc_config_t g_osc25MConfig = { | ||
23 | .oscMode = kOSC_OscMode, | ||
24 | .oscDiv = 1U, | ||
25 | }; | ||
26 | |||
27 | /* AUDIO PLL1 configuration */ | ||
28 | const ccm_analog_frac_pll_config_t g_audioPll1Config = { | ||
29 | .refSel = kANALOG_PllRefOsc25M, /*!< PLL reference OSC25M */ | ||
30 | .refDiv = 5U, /*!< PLL input = 25 / 5 = 5M */ | ||
31 | .fractionDiv = 0U, | ||
32 | .intDiv = 64U, /*!< Integer and fractional Divider output = 5 * (1 + 64) * 8 = 2600MHZ */ | ||
33 | .outDiv = 4U, /*!< Pll out frequency = 2600 / 4 = 650MHZ */ | ||
34 | }; | ||
35 | |||
36 | /* AUDIO PLL2 configuration */ | ||
37 | const ccm_analog_frac_pll_config_t g_audioPll2Config = { | ||
38 | .refSel = kANALOG_PllRefOsc25M, /*!< PLL reference OSC25M */ | ||
39 | .refDiv = 5U, /*!< PLL input = 25 / 5 = 5M */ | ||
40 | .fractionDiv = 0U, | ||
41 | .intDiv = 64U, /*!< Integer and fractional Divider output = 5 * (1 + 64) * 8 = 2600MHZ */ | ||
42 | .outDiv = 4U, /*!< Pll out frequency = 2600 / 4 = 650MHZ */ | ||
43 | }; | ||
44 | |||
45 | /* VIDEO PLL1 configuration */ | ||
46 | const ccm_analog_frac_pll_config_t g_videoPll1Config = { | ||
47 | .refSel = kANALOG_PllRefOsc25M, /*!< PLL reference OSC25M */ | ||
48 | .refDiv = 5U, /*!< PLL input = 25 / 5 = 5M */ | ||
49 | .fractionDiv = 0U, | ||
50 | .intDiv = 64U, /*!< Integer and fractional Divider output = 5 * (1 + 64) * 8 = 2600MHZ */ | ||
51 | .outDiv = 4U, /*!< Pll out frequency = 2600 / 4 = 650MHZ */ | ||
52 | }; | ||
53 | |||
54 | /* SYSTEM PLL1 configuration */ | ||
55 | const ccm_analog_sscg_pll_config_t g_sysPll1Config = { | ||
56 | .refSel = kANALOG_PllRefOsc25M, /*!< PLL reference OSC25M */ | ||
57 | .refDiv1 = 1U, /*!< PLL1 input = 25 / 1 = 25MHZ */ | ||
58 | .loopDivider1 = 32U, /*!< PLL1 output = 25 * 32 * 2 = 1600MHZ */ | ||
59 | .refDiv2 = 24U, /*!< PLL2 input = 1600 / 24 = 66.66MHZ */ | ||
60 | .loopDivider2 = 12U, /*!< PLL2 output = 12 * 66.66 * 2 = 1600MHZ */ | ||
61 | .outDiv = 1U, /*!< PLL output = 1600 / 2 / 1 = 800MHZ */ | ||
62 | }; | ||
63 | |||
64 | /* SYSTEM PLL2 configuration */ | ||
65 | const ccm_analog_sscg_pll_config_t g_sysPll2Config = { | ||
66 | .refSel = kANALOG_PllRefOsc25M, /*!< PLL reference OSC25M */ | ||
67 | .refDiv1 = 1U, /*!< PLL1 input = 25 / 1 = 25MHZ */ | ||
68 | .loopDivider1 = 32U, /*!< PLL1 output = 25 * 32 * 2 = 1600MHZ */ | ||
69 | .refDiv2 = 16U, /*!< PLL2 input = 1600 / 16 = 100MHZ */ | ||
70 | .loopDivider2 = 10U, /*!< PLL2 output = 10 * 100 * 2 = 2000MHZ */ | ||
71 | .outDiv = 1U, /*!< PLL output = 2000 / 2 / 1 = 1000MHZ */ | ||
72 | }; | ||
73 | |||
74 | /* SYSTEM PLL3 configuration */ | ||
75 | const ccm_analog_sscg_pll_config_t g_sysPll3Config = { | ||
76 | .refSel = kANALOG_PllRefOsc25M, /*!< PLL reference OSC25M */ | ||
77 | .refDiv1 = 1U, /*!< PLL1 input = 25 / 1 = 25MHZ */ | ||
78 | .loopDivider1 = 32U, /*!< PLL1 output = 25 * 32 * 2 = 1600MHZ */ | ||
79 | .refDiv2 = 16U, /*!< PLL2 input = 1600 / 16 = 100MHZ */ | ||
80 | .loopDivider2 = 10U, /*!< PLL2 output = 10 * 100 * 2 = 2000MHZ */ | ||
81 | .outDiv = 1U, /*!< PLL output = 2000 / 2 / 1 = 1000MHZ */ | ||
82 | }; | ||
83 | |||
84 | /******************************************************************************* | ||
85 | * Variables | ||
86 | ******************************************************************************/ | ||
87 | |||
88 | /******************************************************************************* | ||
89 | * Code | ||
90 | ******************************************************************************/ | ||
91 | void BOARD_BootClockRUN(void) | ||
92 | { | ||
93 | /* OSC configuration */ | ||
94 | CLOCK_InitOSC25M(&g_osc25MConfig); | ||
95 | CLOCK_InitOSC27M(&g_osc27MConfig); | ||
96 | |||
97 | /* The following steps just show how to configure the PLL clock sources using the clock driver on M4 core side . | ||
98 | * Please note that the ROM has already configured the SYSTEM PLL1 to 800Mhz when power up the SOC, meanwhile A core | ||
99 | * would also do configuration on the SYSTEM PLL1 to 800Mhz and SYSTEM PLL2 to 1000Mhz by U-Boot.*/ | ||
100 | |||
101 | /* switch AHB NOC root to 25M first in order to configure the SYSTEM PLL1. */ | ||
102 | CLOCK_SetRootMux(kCLOCK_RootAhb, kCLOCK_AhbRootmuxOsc25m); | ||
103 | CLOCK_SetRootMux(kCLOCK_RootNoc, kCLOCK_NocRootmuxOsc25m); | ||
104 | /* switch AXI M4 root to 25M first in order to configure the SYSTEM PLL2. */ | ||
105 | CLOCK_SetRootMux(kCLOCK_RootAxi, kCLOCK_AxiRootmuxOsc25m); | ||
106 | CLOCK_SetRootMux(kCLOCK_RootM4, kCLOCK_M4RootmuxOsc25m); | ||
107 | |||
108 | CLOCK_InitSysPll1(&g_sysPll1Config); /* init SYSTEM PLL1 run at 800MHZ */ | ||
109 | CLOCK_InitSysPll2(&g_sysPll2Config); /* init SYSTEM PLL2 run at 1000MHZ */ | ||
110 | CLOCK_InitSysPll3(&g_sysPll3Config); /* init SYSTEM PLL3 run at 1000MHZ */ | ||
111 | |||
112 | CLOCK_InitAudioPll1(&g_audioPll1Config); /* init AUDIO PLL1 run at 650MHZ */ | ||
113 | CLOCK_InitAudioPll2(&g_audioPll2Config); /* init AUDIO PLL2 run at 650MHZ */ | ||
114 | CLOCK_InitVideoPll1(&g_videoPll1Config); /* init VIDEO PLL1 run at 650MHZ */ | ||
115 | |||
116 | CLOCK_SetRootMux(kCLOCK_RootM4, kCLOCK_M4RootmuxSysPll1Div3); /* switch cortex-m4 to SYSTEM PLL1 DIV3 */ | ||
117 | CLOCK_SetRootMux(kCLOCK_RootNoc, kCLOCK_NocRootmuxSysPll1); /* change back to SYSTEM PLL1*/ | ||
118 | |||
119 | CLOCK_SetRootDivider(kCLOCK_RootAhb, 1U, 1U); | ||
120 | CLOCK_SetRootMux(kCLOCK_RootAhb, kCLOCK_AhbRootmuxSysPll1Div6); /* switch AHB to SYSTEM PLL1 DIV6 = 133MHZ */ | ||
121 | |||
122 | CLOCK_SetRootDivider(kCLOCK_RootAxi, 3U, 1U); | ||
123 | CLOCK_SetRootMux(kCLOCK_RootAxi, kCLOCK_AxiRootmuxSysPll1); /* switch AXI to SYSTEM PLL1 = 266MHZ */ | ||
124 | |||
125 | CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); /* Set UART source to SysPLL1 Div10 80MHZ */ | ||
126 | CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); /* Set root clock to 80MHZ/ 1= 80MHZ */ | ||
127 | |||
128 | CLOCK_EnableClock(kCLOCK_Rdc); /* Enable RDC clock */ | ||
129 | |||
130 | /* The purpose to enable the following modules clock is to make sure the M4 core could work normally when A53 core | ||
131 | * enters the low power status.*/ | ||
132 | CLOCK_EnableClock(kCLOCK_Sim_m); | ||
133 | CLOCK_EnableClock(kCLOCK_Sim_main); | ||
134 | CLOCK_EnableClock(kCLOCK_Sim_s); | ||
135 | CLOCK_EnableClock(kCLOCK_Sim_wakeup); | ||
136 | CLOCK_EnableClock(kCLOCK_Debug); | ||
137 | CLOCK_EnableClock(kCLOCK_Dram); | ||
138 | CLOCK_EnableClock(kCLOCK_Sec_Debug); | ||
139 | |||
140 | /* Disable unused PLL */ | ||
141 | CLOCK_DeinitSysPll3(); | ||
142 | CLOCK_DeinitVideoPll1(); | ||
143 | CLOCK_DeinitAudioPll1(); | ||
144 | CLOCK_DeinitAudioPll2(); | ||
145 | /* Update core clock */ | ||
146 | SystemCoreClockUpdate(); | ||
147 | } | ||