MINI55_BSP V3.02.004
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 *----------------------------------------------------------------------------*/
21uint32_t __HSI = __IRC44M_DIV2;
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
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
91void 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. ***/
Mini55 series peripheral access layer header file. This file contains all the peripheral register's d...
#define FMC_ISPCTL_ISPEN_Msk
#define FMC_ISPTRG_ISPGO_Msk
#define FMC_CONFIG_BASE
Definition: fmc.h:38
#define FMC_ISPCMD_READ
Definition: fmc.h:47
#define CLK_CLKSEL0_HCLKSEL_Msk
#define CLK_CLKDIV_HCLKDIV_Msk
#define CLK
Pointer to CLK register structure.
#define FMC
Pointer to FMC register structure.
int32_t SystemInit(void)
Check HIRC clock rate feed to HCLK.
uint32_t __HSI
uint32_t CyclesPerUs
uint32_t SystemCoreClock
uint32_t gau32HIRCTbl[4]
void SystemCoreClockUpdate(void)
This function is used to update the variable SystemCoreClock and must be called whenever the core clo...
#define __IRC44M
#define __IRC10K
#define __SYSTEM_CLOCK
#define __IRC48M_DIV2
#define __XTAL
#define __IRC48M
#define __IRC44M_DIV2