| MINI58_BSP V3.01.003 The Board Support Package for Mini58 Series MCU

system_Mini58Series.c
Go to the documentation of this file.
1/**************************************************************************/
13#include <stdint.h>
14#include "Mini58Series.h"
15
16
17/*----------------------------------------------------------------------------
18 Clock Variable definitions
19 *----------------------------------------------------------------------------*/
20uint32_t SystemCoreClock = __HIRC;
21uint32_t __HSI = __HIRC;
22uint32_t PllClock = __HIRC;
23uint32_t CyclesPerUs;
31 void SystemInit (void)
32{
33
34}
35
43 void SystemCoreClockUpdate (void)
44{
45 uint32_t u32CoreFreq, u32ClkSrc;
46
47 /* Update PLL Clock */
48 PllClock = CLK_GetPLLClockFreq();
49
50 u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLKSEL_Msk;
51
52 if (u32ClkSrc == 0)
53 u32CoreFreq = __XTAL; /* External crystal clock */
54 else if (u32ClkSrc ==2)
55 u32CoreFreq = PllClock; /* PLL clock */
56 else if (u32ClkSrc == 3)
57 u32CoreFreq = __IRC10K; /* Internal 10K crystal clock */
58 else if (u32ClkSrc == 7)
59 u32CoreFreq = __HIRC; /* Factory Default is internal RC */
60 else
61 u32CoreFreq = __HIRC; /* unknown value, use Factory Default is internal RC */
62
63 SystemCoreClock = (u32CoreFreq/((CLK->CLKDIV & CLK_CLKDIV_HCLKDIV_Msk) + 1));
64 CyclesPerUs = (SystemCoreClock + 500000) / 1000000;
65}
66
67#if USE_ASSERT
68
80 void AssertError(uint8_t * file, uint32_t line)
81{
82
83 printf("[%s] line %d : wrong parameters.\r\n", file, line);
84
85 /* Infinite loop */
86 while(1) ;
87}
88#endif
89
90/*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
Mini58Series.h
Mini58 series peripheral access layer header file. This file contains all the peripheral register's d...
CLK_GetPLLClockFreq
__STATIC_INLINE uint32_t CLK_GetPLLClockFreq(void)
Get PLL clock frequency.
Definition: clk.h:197
CLK_CLKSEL0_HCLKSEL_Msk
#define CLK_CLKSEL0_HCLKSEL_Msk
Definition: Mini58Series.h:1260
CLK_CLKDIV_HCLKDIV_Msk
#define CLK_CLKDIV_HCLKDIV_Msk
Definition: Mini58Series.h:1290
CLK
#define CLK
Pointer to CLK register structure.
Definition: Mini58Series.h:11730
__HSI
uint32_t __HSI
Definition: system_Mini58Series.c:21
CyclesPerUs
uint32_t CyclesPerUs
Definition: system_Mini58Series.c:23
SystemInit
void SystemInit(void)
Check HIRC clock rate feed to HCLK.
Definition: system_Mini58Series.c:31
PllClock
uint32_t PllClock
Definition: system_Mini58Series.c:22
SystemCoreClock
uint32_t SystemCoreClock
Definition: system_Mini58Series.c:20
SystemCoreClockUpdate
void SystemCoreClockUpdate(void)
This function is used to update the variable SystemCoreClock and must be called whenever the core clo...
Definition: system_Mini58Series.c:43
__HIRC
#define __HIRC
Definition: system_Mini58Series.h:33
__IRC10K
#define __IRC10K
Definition: system_Mini58Series.h:30
__XTAL
#define __XTAL
Definition: system_Mini58Series.h:31