M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
system_M471M_R1_S.c
Go to the documentation of this file.
1/**************************************************************************/
9#include "NuMicro.h"
10
11
12/*----------------------------------------------------------------------------
13 DEFINES
14 *----------------------------------------------------------------------------*/
15
16
17/*----------------------------------------------------------------------------
18 Clock Variable definitions
19 *----------------------------------------------------------------------------*/
21uint32_t CyclesPerUs = (__HSI / 1000000); /* Cycles per micro second */
22uint32_t PllClock = __HSI;
23uint32_t gau32ClkSrcTbl[] = {__HXT, __LXT, 0, __LIRC, 0, 0, 0, __HIRC};
24
25/*----------------------------------------------------------------------------
26 Clock functions
27 *----------------------------------------------------------------------------*/
28void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
29{
30#if 1
31 uint32_t u32Freq, u32ClkSrc;
32 uint32_t u32HclkDiv;
33
34 /* Update PLL Clock */
36
37 u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLKSEL_Msk;
38
39 if(u32ClkSrc == CLK_CLKSEL0_HCLKSEL_PLL)
40 {
41 /* Use PLL clock */
42 u32Freq = PllClock;
43 }
44 else
45 {
46 /* Use the clock sources directly */
47 u32Freq = gau32ClkSrcTbl[u32ClkSrc];
48 }
49
50 u32HclkDiv = (CLK->CLKDIV0 & CLK_CLKDIV0_HCLKDIV_Msk) + 1;
51
52 /* Update System Core Clock */
53 SystemCoreClock = u32Freq / u32HclkDiv;
54
55
56 //if(SystemCoreClock == 0)
57 // __BKPT(0);
58
59 CyclesPerUs = (SystemCoreClock + 500000) / 1000000;
60#endif
61}
62
72void SystemInit(void)
73{
74 /* ToDo: add code to initialize the system
75 do not use global variables because this function is called before
76 reaching pre-main. RW section maybe overwritten afterwards. */
77
79 /* One-time POR18 */
80 if((SYS->PDID >> 12) == 0x945)
81 {
82 M32(GCR_BASE+0x14) |= BIT7;
83 }
84 /* Force to use INV type with HXT */
85 CLK->PWRCTL &= ~CLK_PWRCTL_HXTSELTYP_Msk;
87
88
89#ifdef EBI_INIT
90 extern void SYS_Init();
91 extern void EBI_Init();
92
94 SYS_Init();
95 EBI_Init();
97#endif
98
99 /* FPU settings ------------------------------------------------------------*/
100#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
101 SCB->CPACR |= ((3UL << 10 * 2) | /* set CP10 Full Access */
102 (3UL << 11 * 2)); /* set CP11 Full Access */
103#endif
104
105}
106
NuMicro peripheral access layer header file.
#define CLK_CLKSEL0_HCLKSEL_PLL
Definition: clk.h:43
__STATIC_INLINE uint32_t CLK_GetPLLClockFreq(void)
Get PLL clock frequency.
Definition: clk.h:326
#define CLK_CLKDIV0_HCLKDIV_Msk
Definition: M471M_R1_S.h:1619
#define CLK_CLKSEL0_HCLKSEL_Msk
Definition: M471M_R1_S.h:1562
#define GCR_BASE
Definition: M471M_R1_S.h:13766
#define CLK
Definition: M471M_R1_S.h:13818
#define BIT7
Definition: M471M_R1_S.h:13863
#define M32(adr)
Definition: M471M_R1_S.h:13937
#define SYS
Definition: M471M_R1_S.h:13816
__STATIC_INLINE void SYS_LockReg(void)
Enable register write-protection function.
Definition: sys.h:698
__STATIC_INLINE void SYS_UnlockReg(void)
Disable register write-protection function.
Definition: sys.h:680
uint32_t gau32ClkSrcTbl[]
uint32_t CyclesPerUs
void SystemInit(void)
Setup the microcontroller system. Initialize the System.
uint32_t PllClock
uint32_t SystemCoreClock
void SystemCoreClockUpdate(void)
Updates the SystemCoreClock with current core Clock retrieved from cpu registers.
#define __HIRC
#define __SYSTEM_CLOCK
#define __HXT
#define __LIRC
#define __LXT
#define __HSI