]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Nuvoton_Code/Device/Nuvoton/M2351/Source/system_M2351.c
Add Cortex M23 GCC and IAR ports. Add demo projects for Nuvoton NuMaker-PFM-2351.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC / Nuvoton_Code / Device / Nuvoton / M2351 / Source / system_M2351.c
1 /**************************************************************************//**\r
2  * @file     system_M2351.c\r
3  * @version  V2.00\r
4  * @brief    System Setting Source File\r
5  *\r
6  * @note\r
7  * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.\r
8  *\r
9  ******************************************************************************/\r
10 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)       /* ARM Compiler 6 */\r
11 #include <arm_cmse.h>\r
12 #endif\r
13 \r
14 #include <stdio.h>\r
15 #include <stdint.h>\r
16 #include "NuMicro.h"\r
17 \r
18 #if defined (__ARM_FEATURE_CMSE) &&  (__ARM_FEATURE_CMSE == 3U)\r
19 #include "partition_M2351.h"\r
20 #endif\r
21 \r
22 extern void *__Vectors;                   /* see startup file */\r
23 \r
24 \r
25 /*----------------------------------------------------------------------------\r
26   Clock Variable definitions\r
27  *----------------------------------------------------------------------------*/\r
28 uint32_t SystemCoreClock  = __HSI;              /*!< System Clock Frequency (Core Clock) */\r
29 uint32_t CyclesPerUs      = (__HSI / 1000000UL);/*!< Cycles per micro second             */\r
30 uint32_t PllClock         = __HSI;              /*!< PLL Output Clock Frequency          */\r
31 const uint32_t gau32ClkSrcTbl[] = {__HXT, __LXT, 0UL, __LIRC, 0UL, __HIRC48, 0UL, __HIRC};\r
32 \r
33 \r
34 /**\r
35  * @brief    Update the Variable SystemCoreClock\r
36  *\r
37  * @param    None\r
38  *\r
39  * @return   None\r
40  *\r
41  * @details  This function is used to update the variable SystemCoreClock\r
42  *           and must be called whenever the core clock is changed.\r
43  */\r
44 void SystemCoreClockUpdate(void)\r
45 {\r
46     /* Update PLL Clock */\r
47     PllClock = CLK_GetPLLClockFreq();\r
48 \r
49     /* Update System Core Clock */\r
50     SystemCoreClock = CLK_GetCPUFreq();\r
51 \r
52     /* Update Cycles per micro second */\r
53     CyclesPerUs = (SystemCoreClock + 500000UL) / 1000000UL;\r
54 }\r
55 \r
56 \r
57 \r
58 /**\r
59  * @brief    System Initialization\r
60  *\r
61  * @param    None\r
62  *\r
63  * @return   None\r
64  *\r
65  * @details  The necessary initialization of system. Global variables are forbidden here.\r
66  */\r
67 void SystemInit(void)\r
68 {\r
69 #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)\r
70     SCB->VTOR = (uint32_t) &__Vectors;\r
71 #endif\r
72 \r
73 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)\r
74     TZ_SAU_Setup();\r
75     SCU_Setup();\r
76     FMC_NSBA_Setup();\r
77 #endif\r
78 \r
79 #ifdef INIT_SYSCLK_AT_BOOTING\r
80 \r
81 #endif\r
82 \r
83 }\r
84 \r
85 \r
86 #if USE_ASSERT\r
87 \r
88 /**\r
89  * @brief      Assert Error Message\r
90  *\r
91  * @param[in]  file  the source file name\r
92  * @param[in]  line  line number\r
93  *\r
94  * @return     None\r
95  *\r
96  * @details    The function prints the source file name and line number where\r
97  *             the ASSERT_PARAM() error occurs, and then stops in an infinite loop.\r
98  */\r
99 void AssertError(uint8_t * file, uint32_t line)\r
100 {\r
101 \r
102     printf("[%s] line %d : wrong parameters.\r\n", file, line);\r
103 \r
104     /* Infinite loop */\r
105     while(1) ;\r
106 }\r
107 #endif\r
108 \r
109 \r
110 #if (defined(__ICCARM__) && (__VER__ >= 7080000) && (__VER__ < 8020000))\r
111 \r
112 #if  (__ARM_FEATURE_CMSE == 3U)\r
113 /**\r
114   \brief   Get Process Stack Pointer (non-secure)\r
115   \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.\r
116   \return               PSP Register value\r
117  */\r
118 uint32_t __TZ_get_PSP_NS(void)\r
119 {\r
120     register uint32_t result;\r
121 \r
122     __ASM volatile("MRS %0, psp_ns"  : "=r"(result));\r
123     return(result);\r
124 }\r
125 \r
126 \r
127 /**\r
128   \brief   Set Process Stack Pointer (non-secure)\r
129   \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.\r
130   \param [in]    topOfProcStack  Process Stack Pointer value to set\r
131  */\r
132 void __TZ_set_PSP_NS(uint32_t topOfProcStack)\r
133 {\r
134     __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack));\r
135 }\r
136 \r
137 \r
138 \r
139 /**\r
140   \brief   Get Main Stack Pointer (non-secure)\r
141   \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.\r
142   \return               MSP Register value\r
143  */\r
144 int32_t __TZ_get_MSP_NS(void)\r
145 {\r
146     register uint32_t result;\r
147 \r
148     __ASM volatile("MRS %0, msp_ns" : "=r"(result));\r
149     return(result);\r
150 }\r
151 \r
152 \r
153 \r
154 /**\r
155   \brief   Set Main Stack Pointer (non-secure)\r
156   \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.\r
157   \param [in]    topOfMainStack  Main Stack Pointer value to set\r
158  */\r
159 void __TZ_set_MSP_NS(uint32_t topOfMainStack)\r
160 {\r
161     __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack));\r
162 }\r
163 \r
164 \r
165 \r
166 /**\r
167   \brief   Get Priority Mask (non-secure)\r
168   \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.\r
169   \return               Priority Mask value\r
170  */\r
171 uint32_t __TZ_get_PRIMASK_NS(void)\r
172 {\r
173     uint32_t result;\r
174 \r
175     __ASM volatile("MRS %0, primask_ns" : "=r"(result));\r
176     return(result);\r
177 }\r
178 \r
179 \r
180 \r
181 /**\r
182   \brief   Set Priority Mask (non-secure)\r
183   \details Assigns the given value to the non-secure Priority Mask Register when in secure state.\r
184   \param [in]    priMask  Priority Mask\r
185  */\r
186 void __TZ_set_PRIMASK_NS(uint32_t priMask)\r
187 {\r
188     __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory");\r
189 }\r
190 \r
191 \r
192 #endif\r
193 \r
194 \r
195 #endif\r
196 \r
197 \r
198 \r