1 /**************************************************************************//**
\r
2 * @file system_M2351.c
\r
4 * @brief System Setting Source File
\r
7 * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
\r
9 ******************************************************************************/
\r
10 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler 6 */
\r
11 #include <arm_cmse.h>
\r
16 #include "NuMicro.h"
\r
18 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
\r
19 #include "partition_M2351.h"
\r
22 extern void *__Vectors; /* see startup file */
\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
35 * @brief Update the Variable SystemCoreClock
\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
44 void SystemCoreClockUpdate(void)
\r
46 /* Update PLL Clock */
\r
47 PllClock = CLK_GetPLLClockFreq();
\r
49 /* Update System Core Clock */
\r
50 SystemCoreClock = CLK_GetCPUFreq();
\r
52 /* Update Cycles per micro second */
\r
53 CyclesPerUs = (SystemCoreClock + 500000UL) / 1000000UL;
\r
59 * @brief System Initialization
\r
65 * @details The necessary initialization of system. Global variables are forbidden here.
\r
67 void SystemInit(void)
\r
69 #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
\r
70 SCB->VTOR = (uint32_t) &__Vectors;
\r
73 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
\r
79 #ifdef INIT_SYSCLK_AT_BOOTING
\r
89 * @brief Assert Error Message
\r
91 * @param[in] file the source file name
\r
92 * @param[in] line line number
\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
99 void AssertError(uint8_t * file, uint32_t line)
\r
102 printf("[%s] line %d : wrong parameters.\r\n", file, line);
\r
104 /* Infinite loop */
\r
110 #if (defined(__ICCARM__) && (__VER__ >= 7080000) && (__VER__ < 8020000))
\r
112 #if (__ARM_FEATURE_CMSE == 3U)
\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
118 uint32_t __TZ_get_PSP_NS(void)
\r
120 register uint32_t result;
\r
122 __ASM volatile("MRS %0, psp_ns" : "=r"(result));
\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
132 void __TZ_set_PSP_NS(uint32_t topOfProcStack)
\r
134 __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack));
\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
144 int32_t __TZ_get_MSP_NS(void)
\r
146 register uint32_t result;
\r
148 __ASM volatile("MRS %0, msp_ns" : "=r"(result));
\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
159 void __TZ_set_MSP_NS(uint32_t topOfMainStack)
\r
161 __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack));
\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
171 uint32_t __TZ_get_PRIMASK_NS(void)
\r
175 __ASM volatile("MRS %0, primask_ns" : "=r"(result));
\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
186 void __TZ_set_PRIMASK_NS(uint32_t priMask)
\r
188 __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory");
\r