@@ -43,13 +43,17 @@ static const scg_sys_clk_config_t scg_sys_clk_config = {
43
43
.src = kSCG_SysClkSrcSirc ,
44
44
#elif DT_SAME_NODE (DT_CLOCKS_CTLR (SCG_CLOCK_NODE (core_clk )), SCG_CLOCK_NODE (firc_clk ))
45
45
.src = kSCG_SysClkSrcFirc ,
46
+ #elif DT_SAME_NODE (DT_CLOCKS_CTLR (SCG_CLOCK_NODE (core_clk )), SCG_CLOCK_NODE (lpfll_clk ))
47
+ .src = kSCG_SysClkSrcLpFll ,
48
+ #else
49
+ #error Invalid SCG core clock selected
46
50
#endif
47
51
};
48
52
49
53
/* Slow Internal Reference Clock (SIRC) configuration */
50
54
ASSERT_ASYNC_CLK_DIV_VALID (SCG_CLOCK_DIV (sircdiv2_clk ),
51
55
"Invalid SCG SIRC divider 2 value" );
52
- static const scg_sirc_config_t scg_sirc_config = {
56
+ static scg_sirc_config_t scg_sirc_config = {
53
57
.enableMode = kSCG_SircEnable ,
54
58
.div2 = TO_ASYNC_CLK_DIV (SCG_CLOCK_DIV (sircdiv2_clk )),
55
59
#if MHZ (2 ) == DT_PROP (SCG_CLOCK_NODE (sirc_clk ), clock_frequency )
@@ -66,7 +70,7 @@ ASSERT_ASYNC_CLK_DIV_VALID(SCG_CLOCK_DIV(fircdiv2_clk),
66
70
"Invalid SCG FIRC divider 2 value" );
67
71
static const scg_firc_config_t scg_firc_config = {
68
72
.enableMode = kSCG_FircEnable ,
69
- .div2 = TO_ASYNC_CLK_DIV (SCG_CLOCK_DIV (fircdiv2_clk )), /* b20253 */
73
+ .div2 = TO_ASYNC_CLK_DIV (SCG_CLOCK_DIV (fircdiv2_clk )),
70
74
#if MHZ (48 ) == DT_PROP (SCG_CLOCK_NODE (firc_clk ), clock_frequency )
71
75
.range = kSCG_FircRange48M ,
72
76
#elif MHZ (52 ) == DT_PROP (SCG_CLOCK_NODE (firc_clk ), clock_frequency )
@@ -81,31 +85,82 @@ static const scg_firc_config_t scg_firc_config = {
81
85
.trimConfig = NULL
82
86
};
83
87
84
- __weak void clk_init (void )
88
+ const scg_sosc_config_t scgSysOscConfig = {
89
+ .freq = 8000000U , /* System Oscillator frequency: 8000000Hz */
90
+ .enableMode = kSCG_SysOscEnable |
91
+ kSCG_SysOscEnableInLowPower , /* Enable System OSC clock in low power mode */
92
+ .monitorMode = kSCG_SysOscMonitorDisable , /* Monitor disabled */
93
+ .div2 = kSCG_AsyncClkDivBy1 , /* System OSC Clock Divider 2: divided by 1 */
94
+ .workMode = kSCG_SysOscModeOscLowPower , /* Oscillator low power */
95
+ };
96
+ const scg_sirc_config_t scgSircConfig = {
97
+ .enableMode = kSCG_SircEnable , /* Enable SIRC clock */
98
+ .div2 = kSCG_AsyncClkDivBy2 , /* Slow IRC Clock Divider 2: divided by 2 */
99
+ .range = kSCG_SircRangeHigh , /* Slow IRC high range clock (8 MHz) */
100
+ };
101
+ const scg_firc_config_t scgFircConfig = {
102
+ .enableMode = kSCG_FircEnable , /* Enable FIRC clock */
103
+ .div2 = kSCG_AsyncClkDivBy1 , /* Fast IRC Clock Divider 2: divided by 1 */
104
+ .range = kSCG_FircRange48M , /* Fast IRC is trimmed to 48MHz */
105
+ .trimConfig = NULL , /* Fast IRC Trim disabled */
106
+ };
107
+ const scg_lpfll_config_t scgLpFllConfig = {
108
+ .enableMode = kSCG_LpFllEnable , /* Enable LPFLL clock */
109
+ .div2 = kSCG_AsyncClkDivBy2 , /* Low Power FLL Clock Divider 2: divided by 2 */
110
+ .range = kSCG_LpFllRange72M , /* LPFLL is trimmed to 72MHz */
111
+ .trimConfig = NULL ,
112
+ };
113
+
114
+ static void CLOCK_CONFIG_FircSafeConfig (const scg_firc_config_t * fircConfig )
85
115
{
86
- const scg_sys_clk_config_t scg_sys_clk_config_safe = {
87
- .divSlow = kSCG_SysClkDivBy4 ,
88
- .divCore = kSCG_SysClkDivBy1 ,
89
- .src = kSCG_SysClkSrcSirc
90
- };
91
- scg_sys_clk_config_t current ;
92
-
93
- /* Configure SIRC */
94
- CLOCK_InitSirc (& scg_sirc_config );
95
-
96
- /* Temporary switch to safe SIRC in order to configure FIRC */
97
- CLOCK_SetRunModeSysClkConfig (& scg_sys_clk_config_safe );
98
- do {
99
- CLOCK_GetCurSysClkConfig (& current );
100
- } while (current .src != scg_sys_clk_config_safe .src );
101
- CLOCK_InitFirc (& scg_firc_config );
116
+ scg_sys_clk_config_t curConfig ;
117
+ const scg_sirc_config_t scgSircConfig = {.enableMode = kSCG_SircEnable ,
118
+ .div2 = kSCG_AsyncClkDivBy2 ,
119
+ .range = kSCG_SircRangeHigh };
120
+ scg_sys_clk_config_t sysClkSafeConfigSource = {
121
+ .divSlow = kSCG_SysClkDivBy4 , /* Slow clock divider */
122
+ .divCore = kSCG_SysClkDivBy1 , /* Core clock divider */
123
+ .src = kSCG_SysClkSrcSirc /* System clock source */
124
+ };
125
+ /* Init Sirc. */
126
+ CLOCK_InitSirc (& scgSircConfig );
127
+ /* Change to use SIRC as system clock source to prepare to change FIRCCFG register. */
128
+ CLOCK_SetRunModeSysClkConfig (& sysClkSafeConfigSource );
129
+ /* Wait for clock source switch finished. */
130
+ do {
131
+ CLOCK_GetCurSysClkConfig (& curConfig );
132
+ } while (curConfig .src != sysClkSafeConfigSource .src );
133
+
134
+ /* Init Firc. */
135
+ CLOCK_InitFirc (fircConfig );
136
+ /* Change back to use FIRC as system clock source in order to configure SIRC if needed. */
137
+ sysClkSafeConfigSource .src = kSCG_SysClkSrcFirc ;
138
+ CLOCK_SetRunModeSysClkConfig (& sysClkSafeConfigSource );
139
+ /* Wait for clock source switch finished. */
140
+ do {
141
+ CLOCK_GetCurSysClkConfig (& curConfig );
142
+ } while (curConfig .src != sysClkSafeConfigSource .src );
143
+ }
144
+
102
145
103
- /* Only RUN mode supported for now */
104
- CLOCK_SetRunModeSysClkConfig (& scg_sys_clk_config );
146
+ __weak void clk_init (void )
147
+ {
148
+ scg_sys_clk_config_t current ;
149
+
150
+ /* Init SOSC according to board configuration. */
151
+ /* Init FIRC. */
152
+ CLOCK_CONFIG_FircSafeConfig (& scgFircConfig );
153
+ /* Init SIRC. */
154
+ CLOCK_InitSirc (& scgSircConfig );
155
+ /* Init LPFLL. */
156
+ CLOCK_InitLpFll (& scgLpFllConfig );
157
+ /* Finally init the App desired clock */
158
+ CLOCK_SetRunModeSysClkConfig (& scg_sys_clk_config );
105
159
do {
106
- CLOCK_GetCurSysClkConfig (& current );
160
+ CLOCK_GetCurSysClkConfig (& current );
107
161
} while (current .src != scg_sys_clk_config .src );
108
162
163
+
109
164
#if DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (lpuart0 ))
110
165
CLOCK_SetIpSrc (kCLOCK_Lpuart0 ,
111
166
DT_CLOCKS_CELL (DT_NODELABEL (lpuart0 ), ip_source ));
0 commit comments