| MINI55_BSP V3.01.003 The Board Support Package for Mini55 Series MCU

system_Mini55Series.c
Go to the documentation of this file.
1/**************************************************************************/
13#include <stdint.h>
14#include "Mini55Series.h"
15
16
17/*----------------------------------------------------------------------------
18 Clock Variable definitions
19 *----------------------------------------------------------------------------*/
20uint32_t gau32HIRCTbl[4] = {__IRC48M, __IRC48M_DIV2, __IRC44M, __IRC44M_DIV2};
21uint32_t __HSI = __IRC44M_DIV2;
22uint32_t SystemCoreClock = __SYSTEM_CLOCK;
23uint32_t CyclesPerUs;
31int32_t SystemInit (void)
32{
33 uint32_t u32CoreFreq;
34 int32_t tout = ((SystemCoreClock/10)*2);
35
36 /* Read the User Configuration words. */
37 FMC->ISPCTL |= FMC_ISPCTL_ISPEN_Msk;
38 FMC->ISPCMD = FMC_ISPCMD_READ;
39 FMC->ISPADDR = FMC_CONFIG_BASE;
40 FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
41 while ((FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) && (tout-- > 0));
42 if (tout <= 0)
43 return -1;
44
45 u32CoreFreq = (FMC->ISPDAT >> 27) & 0x1; // 0 : Internal 48M 1: Internal 44M
46 u32CoreFreq = (u32CoreFreq << 1);
47 u32CoreFreq |= (FMC->ISPDAT >> 15) & 0x1; // 1: divided by 2
48 __HSI = gau32HIRCTbl[u32CoreFreq];
49 return 0;
50}
51
59 void SystemCoreClockUpdate (void)
60{
61 uint32_t u32CoreFreq, u32ClkSrc;
62
63 u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLKSEL_Msk;
64
65 if (u32ClkSrc == 0)
66 u32CoreFreq = __XTAL; /* External crystal clock */
67 else if (u32ClkSrc == 3)
68 u32CoreFreq = __IRC10K; /* Internal 10K crystal clock */
69 else if (u32ClkSrc == 7)
70 u32CoreFreq = __HSI; /* Factory Default is internal 44M divided by 2 */
71 else
72 u32CoreFreq = __HSI; /* unknown value, use Factory Default is internal 44M divided by 2 */
73
74 SystemCoreClock = (u32CoreFreq/((CLK->CLKDIV & CLK_CLKDIV_HCLKDIV_Msk) + 1));
75 CyclesPerUs = (SystemCoreClock + 500000) / 1000000;
76}
77
78#if USE_ASSERT
79
91 void AssertError(uint8_t * file, uint32_t line)
92{
93
94 printf("[%s] line %d : wrong parameters.\r\n", file, line);
95
96 /* Infinite loop */
97 while(1) ;
98}
99#endif
100
101/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
Mini55Series.h
Mini55 series peripheral access layer header file. This file contains all the peripheral register's d...
FMC_ISPCTL_ISPEN_Msk
#define FMC_ISPCTL_ISPEN_Msk
Definition: Mini55Series.h:1424
FMC_ISPTRG_ISPGO_Msk
#define FMC_ISPTRG_ISPGO_Msk
Definition: Mini55Series.h:1451
FMC_CONFIG_BASE
#define FMC_CONFIG_BASE
Definition: fmc.h:38
FMC_ISPCMD_READ
#define FMC_ISPCMD_READ
Definition: fmc.h:47
CLK_CLKSEL0_HCLKSEL_Msk
#define CLK_CLKSEL0_HCLKSEL_Msk
Definition: Mini55Series.h:1214
CLK_CLKDIV_HCLKDIV_Msk
#define CLK_CLKDIV_HCLKDIV_Msk
Definition: Mini55Series.h:1241
CLK
#define CLK
Pointer to CLK register structure.
Definition: Mini55Series.h:7010
FMC
#define FMC
Pointer to FMC register structure.
Definition: Mini55Series.h:7019
SystemInit
int32_t SystemInit(void)
Check HIRC clock rate feed to HCLK.
Definition: system_Mini55Series.c:31
__HSI
uint32_t __HSI
Definition: system_Mini55Series.c:21
CyclesPerUs
uint32_t CyclesPerUs
Definition: system_Mini55Series.c:23
SystemCoreClock
uint32_t SystemCoreClock
Definition: system_Mini55Series.c:22
gau32HIRCTbl
uint32_t gau32HIRCTbl[4]
Definition: system_Mini55Series.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_Mini55Series.c:59
__IRC44M
#define __IRC44M
Definition: system_Mini55Series.h:31
__IRC10K
#define __IRC10K
Definition: system_Mini55Series.h:35
__SYSTEM_CLOCK
#define __SYSTEM_CLOCK
Definition: system_Mini55Series.h:38
__IRC48M_DIV2
#define __IRC48M_DIV2
Definition: system_Mini55Series.h:34
__XTAL
#define __XTAL
Definition: system_Mini55Series.h:36
__IRC48M
#define __IRC48M
Definition: system_Mini55Series.h:32
__IRC44M_DIV2
#define __IRC44M_DIV2
Definition: system_Mini55Series.h:33