1 /*
2 ** ###################################################################
3 ** Processor: MCXC243VFT
4 ** Compilers: Freescale C/C++ for Embedded ARM
5 ** GNU C Compiler
6 ** IAR ANSI C/C++ Compiler for ARM
7 ** Keil ARM C/C++ Compiler
8 ** MCUXpresso Compiler
9 **
10 ** Reference manual: MCXC444RM, Rev.1, Mar 2024
11 ** Version: rev. 1.0, 2024-03-11
12 ** Build: b240401
13 **
14 ** Abstract:
15 ** Provides a system configuration function and a global variable that
16 ** contains the system frequency. It configures the device and initializes
17 ** the oscillator (PLL) that is part of the microcontroller device.
18 **
19 ** Copyright 2016 Freescale Semiconductor, Inc.
20 ** Copyright 2016-2024 NXP
21 ** SPDX-License-Identifier: BSD-3-Clause
22 **
23 ** http: www.nxp.com
24 ** mail: support@nxp.com
25 **
26 ** Revisions:
27 ** - rev. 1.0 (2024-03-11)
28 ** Initial version.
29 **
30 ** ###################################################################
31 */
32
33 /*!
34 * @file MCXC243
35 * @version 1.0
36 * @date 2024-03-11
37 * @brief Device specific configuration file for MCXC243 (implementation file)
38 *
39 * Provides a system configuration function and a global variable that contains
40 * the system frequency. It configures the device and initializes the oscillator
41 * (PLL) that is part of the microcontroller device.
42 */
43
44 #include <stdint.h>
45 #include "fsl_device_registers.h"
46
47
48
49 /* ----------------------------------------------------------------------------
50 -- Core clock
51 ---------------------------------------------------------------------------- */
52
53 uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK;
54
55 /* ----------------------------------------------------------------------------
56 -- SystemInit()
57 ---------------------------------------------------------------------------- */
58
SystemInit(void)59 void SystemInit (void) {
60
61 #if (ACK_ISOLATION)
62 if((PMC->REGSC & PMC_REGSC_ACKISO_MASK) != 0U) {
63 PMC->REGSC |= PMC_REGSC_ACKISO_MASK; /* VLLSx recovery */
64 }
65 #endif
66
67 #if (DISABLE_WDOG)
68 /* SIM->COPC: ?=0,COPCLKSEL=0,COPDBGEN=0,COPSTPEN=0,COPT=0,COPCLKS=0,COPW=0 */
69 SIM->COPC = (uint32_t)0x00U;
70 #endif /* (DISABLE_WDOG) */
71
72 SystemInitHook();
73 }
74
75 /* ----------------------------------------------------------------------------
76 -- SystemCoreClockUpdate()
77 ---------------------------------------------------------------------------- */
78
SystemCoreClockUpdate(void)79 void SystemCoreClockUpdate (void) {
80
81 uint32_t MCGOUTClock; /* Variable to store output clock frequency of the MCG module */
82 uint16_t Divider;
83
84 if ((MCG->S & MCG_S_CLKST_MASK) == 0x00U) {
85 /* High internal reference clock is selected */
86 MCGOUTClock = CPU_INT_FAST_CLK_HZ; /* Fast internal reference clock selected */
87 } else if ((MCG->S & MCG_S_CLKST_MASK) == 0x04U) {
88 /* Internal reference clock is selected */
89 Divider = (uint16_t)(0x01LU << ((MCG->SC & MCG_SC_FCRDIV_MASK) >> MCG_SC_FCRDIV_SHIFT));
90 MCGOUTClock = (uint32_t) (CPU_INT_SLOW_CLK_HZ / Divider); /* Slow internal reference clock 8MHz selected */
91 } else if ((MCG->S & MCG_S_CLKST_MASK) == 0x08U) {
92 /* External reference clock is selected */
93 MCGOUTClock = CPU_XTAL_CLK_HZ;
94 } else {
95 /* Reserved value */
96 return;
97 } /* (!((MCG->S & MCG_S_CLKST_MASK) == 0x08U)) */
98 SystemCoreClock = (MCGOUTClock / (0x01U + ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV1_MASK) >> SIM_CLKDIV1_OUTDIV1_SHIFT)));
99 }
100
101 /* ----------------------------------------------------------------------------
102 -- SystemInitHook()
103 ---------------------------------------------------------------------------- */
104
SystemInitHook(void)105 __attribute__ ((weak)) void SystemInitHook (void) {
106 /* Void implementation of the weak function. */
107 }
108