1 /**************************************************************************//**
2  * @file     system_M2354.h
3  * @version  V3.00
4  * @brief    System Setting Header File
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8  ******************************************************************************/
9 #ifndef __SYSTEM_M2354_H__
10 #define __SYSTEM_M2354_H__
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 /*---------------------------------------------------------------------------------------------------------*/
16 /* Macro Definition                                                                                        */
17 /*---------------------------------------------------------------------------------------------------------*/
18 #ifndef DEBUG_PORT
19 # define DEBUG_PORT      UART0       /*!< Select Debug Port which is used for retarget.c to output debug message to UART */
20 #endif
21 
22 
23 /* Init ETM Interface Multi-function Pins */
24 #define ETM_INIT()  { \
25     SYS->GPC_MFPL &= ~(SYS_GPC_MFPL_PC0MFP_ETM_TRACE_Msk | SYS_GPC_MFPL_PC1MFP_ETM_TRACE_Msk | \
26     SYS_GPC_MFPL_PC2MFP_ETM_TRACE_Msk | SYS_GPC_MFPL_PC3MFP_ETM_TRACE_Msk | \
27                      SYS_GPC_MFPL_PC4MFP_ETM_TRACE_Msk); \
28     SYS->GPC_MFPL |= SYS_GPC_MFPL_PC0MFP_ETM_TRACE_CLK | SYS_GPC_MFPL_PC1MFP_ETM_TRACE_DATA0 | \
29                      SYS_GPC_MFPL_PC2MFP_ETM_TRACE_DATA1 | SYS_GPC_MFPL_PC3MFP_ETM_TRACE_DATA2 | \
30                      SYS_GPC_MFPL_PC4MFP_ETM_TRACE_DATA3;}
31 
32 
33 
34 
35 
36 /**
37  *
38  * @details    This is used to enable PLL to speed up booting at startup. Remove it will cause system using
39  *             default clock source (External crystal or internal 22.1184MHz IRC).
40  *             Enable this option will cause system booting in 72MHz(By XTAL) or 71.8848MHz(By IRC22M) according to
41  *             user configuration setting in CONFIG0
42  *
43  */
44 
45 /*
46 #define INIT_SYSCLK_AT_BOOTING
47 */
48 
49 /*----------------------------------------------------------------------------
50   Define SYSCLK
51  *----------------------------------------------------------------------------*/
52 #define __HXT       (12000000UL)    /*!< External Crystal Clock Frequency     */
53 #define __LIRC      (32000UL)       /*!< Internal 32K RC Oscillator Frequency */
54 #define __HIRC      (12000000UL)    /*!< Internal 12M RC Oscillator Frequency */
55 #define __LXT       (32768UL)       /*!< External Crystal Clock Frequency 32.768KHz */
56 #define __HSI       (48000000UL)    /*!< PLL Output Clock Frequency */
57 #define __HIRC48    (48000000UL)    /*!< Internal 48M RC Oscillator Frequency */
58 #define __LIRC32    (32000UL)       /*!< Internal 32K RC Oscillator Frequency */
59 #define __MIRC      (4000000UL)     /*!< Internal 4M RC Oscillator Frequency */
60 
61 
62 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3L)
63 # if defined (__ICCARM__)
64 #  define __NONSECURE_ENTRY       __cmse_nonsecure_entry
65 #  define __NONSECURE_ENTRY_WEAK  __cmse_nonsecure_entry //__weak
66 #  define __NONSECURE_CALL        __cmse_nonsecure_call
67 # else
68 #  define __NONSECURE_ENTRY       __attribute__((cmse_nonsecure_entry))
69 #  define __NONSECURE_ENTRY_WEAK  __attribute__((cmse_nonsecure_entry,weak))
70 #  define __NONSECURE_CALL        __attribute__((cmse_nonsecure_call))
71 # endif
72 #else
73 # define __NONSECURE_ENTRY
74 # define __NONSECURE_ENTRY_WEAK
75 # define __NONSECURE_CALL
76 #endif
77 
78 
79 
80 extern uint32_t SystemCoreClock;    /*!< System Clock Frequency (Core Clock)  */
81 extern uint32_t CyclesPerUs;        /*!< Cycles per micro second              */
82 extern uint32_t PllClock;           /*!< PLL Output Clock Frequency           */
83 extern uint32_t __PC(void);         /*!< Return the current program counter value */
84 
85 #if USE_ASSERT
86 /**
87  * @brief      Assert Function
88  *
89  * @param[in]  expr  Expression to be evaluated
90  *
91  * @details    If the expression is false, an error message will be printed out
92  *             from debug port (UART0 or UART1).
93  */
94 #define ASSERT_PARAM(expr)  { if (!(expr)) { AssertError((uint8_t*)__FILE__, __LINE__); } }
95 
96 void AssertError(uint8_t* file, uint32_t line);
97 #else
98 #define ASSERT_PARAM(expr)
99 #endif
100 
101 #define assert_param(expr)  ASSERT_PARAM(expr)
102 
103 
104 /**
105  * @brief    System Initialization
106  *
107  * @details  The necessary initialization of system.
108  */
109 extern void SystemInit(void);
110 
111 
112 /**
113  * @brief    Update the Variable SystemCoreClock
114  *
115  * @details  This function is used to update the variable SystemCoreClock
116  *           and must be called whenever the core clock is changed.
117  */
118 extern void SystemCoreClockUpdate(void);
119 
120 
121 
122 
123 #if (defined(__ICCARM__) && (__VER__ >= 7080000) && (__VER__ < 8020000))
124 uint32_t __TZ_get_PSP_NS(void);
125 void __TZ_set_PSP_NS(uint32_t topOfProcStack);
126 int32_t __TZ_get_MSP_NS(void);
127 void __TZ_set_MSP_NS(uint32_t topOfMainStack);
128 uint32_t __TZ_get_PRIMASK_NS(void);
129 void __TZ_set_PRIMASK_NS(uint32_t priMask);
130 #endif
131 
132 
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif /* __SYSTEM_M2354_H__ */
139