1 /**************************************************************************//**
\r
3 * @brief CMSIS Cortex-M3 Peripheral Access Layer for EFM32 devices
\r
5 * @author Energy Micro AS
\r
7 ******************************************************************************
\r
9 * <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
\r
10 ******************************************************************************
\r
12 * This source code is the property of Energy Micro AS. The source and compiled
\r
13 * code may only be used on Energy Micro "EFM32" microcontrollers.
\r
15 * This copyright notice may not be removed from the source code nor changed.
\r
17 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
\r
18 * obligation to support this Software. Energy Micro AS is providing the
\r
19 * Software "AS IS", with no express or implied warranties of any kind,
\r
20 * including, but not limited to, any implied warranties of merchantability
\r
21 * or fitness for any particular purpose or warranties against infringement
\r
22 * of any proprietary rights of a third party.
\r
24 * Energy Micro AS will not be liable for any consequential, incidental, or
\r
25 * special damages, or any other relief, or for any claim by any third party,
\r
26 * arising from your use of this Software.
\r
28 *****************************************************************************/
\r
33 uint32_t SystemCoreClock; /**< System Clock Frequency (Core Clock) */
\r
35 #ifndef EFM32_HFXO_FREQ
\r
36 #define EFM32_HFXO_FREQ 32000000
\r
38 #ifndef EFM32_LFXO_FREQ
\r
39 #define EFM32_LFXO_FREQ 32768
\r
41 #ifndef EFM32_LFRCO_FREQ
\r
42 #define EFM32_LFRCO_FREQ 32768
\r
45 /**************************************************************************//**
\r
46 * @brief Initialize the system
\r
51 * @brief Setup the microcontroller system.
\r
52 * Initialize the System and update the SystemCoreClock variable.
\r
53 *****************************************************************************/
\r
54 void SystemInit(void)
\r
56 #if EFM32_AUXHFROCO_ENABLE
\r
57 CMU_TypeDef *cmu = CMU;
\r
59 /* Enable clocks to debug modules in Cortex */
\r
60 /* This will enable Debug Trace and MSC Flash programming clocks */
\r
61 cmu->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
\r
65 /**************************************************************************//**
\r
66 * @brief Update SystemCoreClock variable
\r
71 * @brief Updates the SystemCoreClock with current core Clock
\r
72 * retrieved from cpu registers.
\r
73 *****************************************************************************/
\r
74 void SystemCoreClockUpdate(void)
\r
76 CMU_TypeDef *cmu = CMU;
\r
77 uint32_t inputClock;
\r
79 /* Check source for core clock */
\r
80 switch (cmu->STATUS &
\r
81 (CMU_STATUS_HFRCOSEL |
\r
82 CMU_STATUS_HFXOSEL |
\r
83 CMU_STATUS_LFRCOSEL |
\r
84 CMU_STATUS_LFXOSEL))
\r
86 case CMU_STATUS_HFXOSEL:
\r
87 inputClock = EFM32_HFXO_FREQ;
\r
89 case CMU_STATUS_LFRCOSEL:
\r
90 inputClock = EFM32_LFRCO_FREQ;
\r
92 case CMU_STATUS_LFXOSEL:
\r
93 inputClock = EFM32_LFXO_FREQ;
\r
95 case CMU_STATUS_HFRCOSEL:
\r
97 switch ((cmu->HFRCOCTRL & _CMU_HFRCOCTRL_BAND_MASK) >> _CMU_HFRCOCTRL_BAND_SHIFT)
\r
99 case _CMU_HFRCOCTRL_BAND_28MHZ:
\r
100 inputClock = 28000000;
\r
102 case _CMU_HFRCOCTRL_BAND_21MHZ:
\r
103 inputClock = 21000000;
\r
105 case _CMU_HFRCOCTRL_BAND_14MHZ:
\r
106 inputClock = 14000000;
\r
108 case _CMU_HFRCOCTRL_BAND_11MHZ:
\r
109 inputClock = 11000000;
\r
111 case _CMU_HFRCOCTRL_BAND_7MHZ:
\r
112 inputClock = 7000000;
\r
114 case _CMU_HFRCOCTRL_BAND_1MHZ:
\r
115 inputClock = 1500000;
\r
123 /* Adjust according to clock divisor */
\r
124 SystemCoreClock = inputClock / (1<<((cmu->HFCORECLKDIV & _CMU_HFCORECLKDIV_MASK)>>_CMU_HFCORECLKDIV_HFCORECLKDIV_SHIFT));
\r