ISSDK  1.8
IoT Sensing Software Development Kit
clock_config.c
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2019 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "clock_config.h"
9 #include "fsl_iomuxc.h"
10 #include "board.h"
11 
12 /*******************************************************************************
13  * Definitions
14  ******************************************************************************/
15 
16 /*******************************************************************************
17  * Variables
18  ******************************************************************************/
19 /* System clock frequency. */
20 extern uint32_t SystemCoreClock;
21 
22 /*******************************************************************************
23  ************************ BOARD_InitBootClocks function ************************
24  ******************************************************************************/
26 {
28 }
29 
30 /*******************************************************************************
31  ********************** Configuration BOARD_BootClockRUN ***********************
32  ******************************************************************************/
33 
34 #ifndef SKIP_DCDC_ADJUSTMENT
35 #if __CORTEX_M == 4
36 #define SKIP_DCDC_ADJUSTMENT 1
37 #endif
38 #endif
39 
40 /* 1.0 v */
41 #define DCDC_TARGET_VOLTAGE_1V 1000
42 /* 1.15 v */
43 #define DCDC_TARGET_VOLTAGE_1P15V 1150
44 
45 #ifndef DCDC_TARGET_VOLTAGE
46 #define DCDC_TARGET_VOLTAGE DCDC_TARGET_VOLTAGE_1P15V
47 #endif
48 
49 /*
50  * TODO:
51  * replace the following two dcdc function with SDK DCDC driver when it's
52  * ready
53  */
54 /*******************************************************************************
55  * Code for getting current DCDC voltage setting
56  ******************************************************************************/
58 {
59  uint32_t temp = DCDC->CTRL1;
60  temp = (temp & DCDC_CTRL1_VDD1P0CTRL_TRG_MASK) >> DCDC_CTRL1_VDD1P0CTRL_TRG_SHIFT;
61  return (temp * 25 + 600);
62 }
63 
64 /*******************************************************************************
65  * Code for setting DCDC to target voltage
66  ******************************************************************************/
67 void dcdc_trim_target_1p0(uint32_t target_voltage)
68 {
69  uint8_t trim_value;
70  uint32_t temp;
71 
72  trim_value = (target_voltage - 600) / 25;
73  temp = DCDC->CTRL1;
74  if ((temp & DCDC_CTRL1_VDD1P0CTRL_TRG(trim_value)) == DCDC_CTRL1_VDD1P0CTRL_TRG(trim_value))
75  {
76  return;
77  }
78 
79  temp &= ~DCDC_CTRL1_VDD1P0CTRL_TRG_MASK;
80  temp |= DCDC_CTRL1_VDD1P0CTRL_TRG(trim_value);
81  DCDC->CTRL1 = temp;
82 }
83 
84 /*******************************************************************************
85  * Code for BOARD_BootClockRUN configuration
86  ******************************************************************************/
88 {
89  clock_root_config_t rootCfg = {0};
90 
91 #if !defined(SKIP_DCDC_ADJUSTMENT) || (!SKIP_DCDC_ADJUSTMENT)
93 #endif
94 
95 #if defined(BYPASS_LDO_LPSR) && BYPASS_LDO_LPSR
96  CLOCK_ANATOP_LdoLpsrAnaBypassOn();
97  CLOCK_ANATOP_LdoLpsrDigBypassOn();
98 #endif
99 
100 #if __CORTEX_M == 7
101  /* ARM PLL 996 MHz. */
102  const clock_arm_pll_config_t armPllConfig = {
103  .postDivider = kCLOCK_PllPostDiv2,
104  .loopDivider = 166,
105  };
106 #endif
107 
108  /* SYS PLL2 528MHz. */
109  const clock_sys_pll_config_t sysPllConfig = {
110  .loopDivider = 1,
111  /* Using 24Mhz OSC */
112  .mfn = 0,
113  .mfi = 22,
114  };
115 
116  const clock_sys_pll3_config_t sysPll3Config = {
117  .divSelect = 3,
118  };
119 
120  /* PLL LDO shall be enabled first before enable PLLs */
121  CLOCK_EnableOsc24M();
122 
123 #if __CORTEX_M == 7
124  rootCfg.mux = 0;
125  rootCfg.div = 0;
126  CLOCK_SetRootClock(kCLOCK_Root_M7, &rootCfg);
127  CLOCK_SetRootClock(kCLOCK_Root_M7_Systick, &rootCfg);
128 
129  /* ARMPll: 996M */
130  CLOCK_InitArmPll(&armPllConfig);
131  /* Configure M7 */
132  rootCfg.mux = 4;
133  rootCfg.div = 0;
134  CLOCK_SetRootClock(kCLOCK_Root_M7, &rootCfg);
135 
136  /* Configure M7 Systick running at 10K */
137  rootCfg.mux = 0;
138  rootCfg.div = 239;
139  CLOCK_SetRootClock(kCLOCK_Root_M7_Systick, &rootCfg);
140 #endif
141  CLOCK_InitSysPll2(&sysPllConfig);
142  CLOCK_InitSysPll3(&sysPll3Config);
143 
144 #if __CORTEX_M == 4
145  rootCfg.mux = 0;
146  rootCfg.div = 0;
147  CLOCK_SetRootClock(kCLOCK_Root_M4, &rootCfg);
148  CLOCK_SetRootClock(kCLOCK_Root_Bus_Lpsr, &rootCfg);
149 
150  CLOCK_InitPfd(kCLOCK_Pll_SysPll3, kCLOCK_Pfd3, 18);
151  /* Configure M4 using SysPll3Pfd3 divided by 1 */
152  rootCfg.mux = 4;
153  rootCfg.div = 0;
154  CLOCK_SetRootClock(kCLOCK_Root_M4, &rootCfg);
155 
156  /* SysPll3 divide by 4 */
157  rootCfg.mux = 5;
158  rootCfg.div = 3;
159  CLOCK_SetRootClock(kCLOCK_Root_Bus_Lpsr, &rootCfg);
160 #endif
161 
162 #if DEBUG_CONSOLE_UART_INDEX == 1
163  /* Configure Lpuart1 using SysPll2*/
164  rootCfg.mux = 6;
165  rootCfg.div = 21;
166  CLOCK_SetRootClock(kCLOCK_Root_Lpuart1, &rootCfg);
167 #else
168  /* Configure Lpuart2 using SysPll2*/
169  rootCfg.mux = 6;
170  rootCfg.div = 21;
171  CLOCK_SetRootClock(kCLOCK_Root_Lpuart2, &rootCfg);
172 #endif
173 
174 #ifndef SKIP_SEMC_INIT
175  CLOCK_EnableOscRc400M();
176  /* Configure Semc using OscRc400M divided by 2 */
177  rootCfg.mux = 2;
178  rootCfg.div = 1;
179  CLOCK_SetRootClock(kCLOCK_Root_Semc, &rootCfg);
180 #endif
181 
182  /* Configure Bus using SysPll3 divided by 4 */
183  rootCfg.mux = 4;
184  rootCfg.div = 1;
185  CLOCK_SetRootClock(kCLOCK_Root_Bus, &rootCfg);
186 
187  /* Configure Lpi2c1 using Osc48MDiv2 */
188  rootCfg.mux = 0;
189  rootCfg.div = 0;
190  CLOCK_SetRootClock(kCLOCK_Root_Lpi2c1, &rootCfg);
191 
192  /* Configure Lpi2c5 using Osc48MDiv2 */
193  rootCfg.mux = 0;
194  rootCfg.div = 0;
195  CLOCK_SetRootClock(kCLOCK_Root_Lpi2c5, &rootCfg);
196 
197  /* Configure gpt timer using Osc48MDiv2 */
198  rootCfg.mux = 0;
199  rootCfg.div = 0;
200  CLOCK_SetRootClock(kCLOCK_Root_Gpt1, &rootCfg);
201 
202  /* Configure gpt timer using Osc48MDiv2 */
203  rootCfg.mux = 0;
204  rootCfg.div = 0;
205  CLOCK_SetRootClock(kCLOCK_Root_Gpt2, &rootCfg);
206 
207  /* Configure lpspi using Osc48MDiv2 */
208  rootCfg.mux = 0;
209  rootCfg.div = 0;
210  CLOCK_SetRootClock(kCLOCK_Root_Lpspi1, &rootCfg);
211 
212  /* Configure flexio using Osc48MDiv2 */
213  rootCfg.mux = 0;
214  rootCfg.div = 0;
215  CLOCK_SetRootClock(kCLOCK_Root_Flexio2, &rootCfg);
216 
217  /* Configure emvsim using Osc48MDiv2 */
218  rootCfg.mux = 0;
219  rootCfg.div = 0;
220  CLOCK_SetRootClock(kCLOCK_Root_Emv1, &rootCfg);
221 
222 #if __CORTEX_M == 7
223  SystemCoreClock = CLOCK_GetRootClockFreq(kCLOCK_Root_M7);
224 #else
225  SystemCoreClock = CLOCK_GetRootClockFreq(kCLOCK_Root_M4);
226 #endif
227 }
#define DCDC_TARGET_VOLTAGE
Definition: clock_config.c:46
uint32_t dcdc_get_target_voltage()
Definition: clock_config.c:57
void dcdc_trim_target_1p0(uint32_t target_voltage)
Definition: clock_config.c:67
const clock_arm_pll_config_t armPllConfig
Definition: clock_config.c:15
void BOARD_InitBootClocks(void)
This function executes default configuration of clocks.
Definition: clock_config.c:52
uint32_t SystemCoreClock
void BOARD_BootClockRUN(void)
This function executes configuration of clocks.
Definition: clock_config.c:168
const clock_sys_pll_config_t sysPllConfig
Definition: clock_config.c:19