1 /*
2 ** ###################################################################
3 **     Processors:          MIMXRT798SGAWAR_cm33_core0
4 **                          MIMXRT798SGFOA_cm33_core0
5 **
6 **     Compilers:           GNU C Compiler
7 **                          IAR ANSI C/C++ Compiler for ARM
8 **                          Keil ARM C/C++ Compiler
9 **                          MCUXpresso Compiler
10 **
11 **     Reference manual:    iMXRT700RM Rev.2 DraftA, 05/2024
12 **     Version:             rev. 2.0, 2024-05-28
13 **     Build:               b240528
14 **
15 **     Abstract:
16 **         Provides a system configuration function and a global variable that
17 **         contains the system frequency. It configures the device and initializes
18 **         the oscillator (PLL) that is part of the microcontroller device.
19 **
20 **     Copyright 2016 Freescale Semiconductor, Inc.
21 **     Copyright 2016-2024 NXP
22 **     SPDX-License-Identifier: BSD-3-Clause
23 **
24 **     http:                 www.nxp.com
25 **     mail:                 support@nxp.com
26 **
27 **     Revisions:
28 **     - rev. 1.0 (2022-09-15)
29 **         Initial version.
30 **     - rev. 2.0 (2024-05-28)
31 **         Rev2 DraftA.
32 **
33 ** ###################################################################
34 */
35 
36 /*!
37  * @file MIMXRT798S_cm33_core0
38  * @version 1.0
39  * @date 2024-05-28
40  * @brief Device specific configuration file for MIMXRT798S_cm33_core0 (header file)
41  *
42  * Provides a system configuration function and a global variable that contains
43  * the system frequency. It configures the device and initializes the oscillator
44  * (PLL) that is part of the microcontroller device.
45  */
46 
47 #ifndef _SYSTEM_MIMXRT798S_cm33_core0_H_
48 #define _SYSTEM_MIMXRT798S_cm33_core0_H_ /**< Symbol preventing repeated inclusion */
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 #include <stdint.h>
55 
56 #define DEFAULT_SYSTEM_CLOCK 192000000u /* Default System clock value */
57 #ifndef CLK_XTAL_OSC_CLK
58 #define CLK_XTAL_OSC_CLK 24000000u      /* Default XTAL OSC clock, set to 0 when external CLKIN is used */
59 #endif
60 #ifndef CLK_EXT_CLKIN
61 #define CLK_EXT_CLKIN 0u /* Default external CLKIN pin clock, set to 0 when XTAL OSC is used */
62 #endif
63 #define CLK_OSC_CLK ((CLK_XTAL_OSC_CLK != 0U) ? CLK_XTAL_OSC_CLK : CLK_EXT_CLKIN)
64 
65 #define CLK_RTC_32K_CLK      32768u     /* RTC oscillator 32 kHz (32k_clk) */
66 #define CLK_LPOSC_1MHZ       1000000u   /* Low power oscillator 1 MHz (1m_lposc) */
67 #define CLK_FRO0_DEFAULT_CLK 300000000u /* FRO0 default clock frequency (fro0_max) */
68 #define CLK_FRO1_MAX_CLK     192000000u /* FRO1 max clock frequency (fro1) */
69 #define CLK_FRO2_DEFAULT_CLK 196000000u /* FRO2 default clock frequency (fro2_max) */
70 
71 #define FRO_TUNER_USED(base) ((base->TEXPCNT.RW & FRO_TEXPCNT_TEXPCNT_MASK) != 0u)
72 /* FRO frequency = TRIMCNT * (divided ref clock frequency) / REFCLKCNT. */
73 #define FRO_FREQ_GET_FROM_TUNER(base)                                                       \
74     ((uint32_t)((uint64_t)(base->TRIMCNT.RW) *                                              \
75                 (uint64_t)(CLK_OSC_CLK / ((base->CNFG1.RW & FRO_CNFG1_REFDIV_MASK) + 1U)) / \
76                 ((base->CNFG1.RW & FRO_CNFG1_RFCLKCNT_MASK) >> FRO_CNFG1_RFCLKCNT_SHIFT)))
77 #define CLK_FRO0_CLK (FRO_TUNER_USED(FRO0) ? FRO_FREQ_GET_FROM_TUNER(FRO0) : CLK_FRO0_DEFAULT_CLK)
78 #define CLK_FRO2_CLK (FRO_TUNER_USED(FRO2) ? FRO_FREQ_GET_FROM_TUNER(FRO2) : CLK_FRO2_DEFAULT_CLK)
79 
80 #define STARTUP_XSPI_CACHE_POLICY_NON_CACHEABLE 0U
81 #define STARTUP_XSPI_CACHE_POLICY_WRITE_TRHOUGH 1U
82 #define STARTUP_XSPI_CACHE_POLICY_WRITE_BACK    2U
83 
84 #ifndef STARTUP_XSPI0_CACHE_POLICY
85 #define STARTUP_XSPI0_CACHE_POLICY STARTUP_XSPI_CACHE_POLICY_WRITE_BACK
86 #endif
87 
88 #ifndef STARTUP_XSPI1_CACHE_POLICY
89 #define STARTUP_XSPI1_CACHE_POLICY STARTUP_XSPI_CACHE_POLICY_WRITE_BACK
90 #endif
91 
92 /**
93  * @brief System clock frequency (core clock)
94  *
95  * The system clock frequency supplied to the SysTick timer and the processor
96  * core clock. This variable can be used by the user application to setup the
97  * SysTick timer or configure other parameters. It may also be used by debugger to
98  * query the frequency of the debug timer or configure the trace clock speed
99  * SystemCoreClock is initialized with a correct predefined value.
100  */
101 extern uint32_t SystemCoreClock;
102 
103 /**
104  * @brief Setup the microcontroller system.
105  *
106  * Typically this function configures the oscillator (PLL) that is part of the
107  * microcontroller device. For systems with variable clock speed it also updates
108  * the variable SystemCoreClock. SystemInit is called from startup_device file.
109  */
110 void SystemInit(void);
111 
112 /**
113  * @brief Updates the SystemCoreClock variable.
114  *
115  * It must be called whenever the core clock is changed during program
116  * execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates
117  * the current core clock.
118  */
119 void SystemCoreClockUpdate(void);
120 
121 /**
122  * @brief SystemInit function hook.
123  *
124  * This weak function allows to call specific initialization code during the
125  * SystemInit() execution.This can be used when an application specific code needs
126  * to be called as close to the reset entry as possible (for example the Multicore
127  * Manager MCMGR_EarlyInit() function call).
128  * NOTE: No global r/w variables can be used in this hook function because the
129  * initialization of these variables happens after this function.
130  */
131 void SystemInitHook(void);
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* _SYSTEM_MIMXRT798S_cm33_core0_H_ */
138