A simple 128x32 graphical LCD program to quickstart with LCD on ARM mbed IoT Starter Kit. This requires mbed Applciation Shield with FRDM-K64F platform.

Dependencies:   C12832

Committer:
tushki7
Date:
Sun Apr 12 15:45:52 2015 +0000
Revision:
1:eb68c94a8ee5
Parent:
0:60d829a0353a
A simple 128x32 LCD program with ARM mbed IoT Starter Kit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tushki7 0:60d829a0353a 1 /*
tushki7 0:60d829a0353a 2 ** ###################################################################
tushki7 0:60d829a0353a 3 ** Compilers: Keil ARM C/C++ Compiler
tushki7 0:60d829a0353a 4 ** Freescale C/C++ for Embedded ARM
tushki7 0:60d829a0353a 5 ** GNU C Compiler
tushki7 0:60d829a0353a 6 ** GNU C Compiler - CodeSourcery Sourcery G++
tushki7 0:60d829a0353a 7 ** IAR ANSI C/C++ Compiler for ARM
tushki7 0:60d829a0353a 8 **
tushki7 0:60d829a0353a 9 ** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
tushki7 0:60d829a0353a 10 ** Version: rev. 2.5, 2014-05-06
tushki7 0:60d829a0353a 11 ** Build: b140611
tushki7 0:60d829a0353a 12 **
tushki7 0:60d829a0353a 13 ** Abstract:
tushki7 0:60d829a0353a 14 ** Provides a system configuration function and a global variable that
tushki7 0:60d829a0353a 15 ** contains the system frequency. It configures the device and initializes
tushki7 0:60d829a0353a 16 ** the oscillator (PLL) that is part of the microcontroller device.
tushki7 0:60d829a0353a 17 **
tushki7 0:60d829a0353a 18 ** Copyright (c) 2014 Freescale Semiconductor, Inc.
tushki7 0:60d829a0353a 19 ** All rights reserved.
tushki7 0:60d829a0353a 20 **
tushki7 0:60d829a0353a 21 ** Redistribution and use in source and binary forms, with or without modification,
tushki7 0:60d829a0353a 22 ** are permitted provided that the following conditions are met:
tushki7 0:60d829a0353a 23 **
tushki7 0:60d829a0353a 24 ** o Redistributions of source code must retain the above copyright notice, this list
tushki7 0:60d829a0353a 25 ** of conditions and the following disclaimer.
tushki7 0:60d829a0353a 26 **
tushki7 0:60d829a0353a 27 ** o Redistributions in binary form must reproduce the above copyright notice, this
tushki7 0:60d829a0353a 28 ** list of conditions and the following disclaimer in the documentation and/or
tushki7 0:60d829a0353a 29 ** other materials provided with the distribution.
tushki7 0:60d829a0353a 30 **
tushki7 0:60d829a0353a 31 ** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
tushki7 0:60d829a0353a 32 ** contributors may be used to endorse or promote products derived from this
tushki7 0:60d829a0353a 33 ** software without specific prior written permission.
tushki7 0:60d829a0353a 34 **
tushki7 0:60d829a0353a 35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
tushki7 0:60d829a0353a 36 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
tushki7 0:60d829a0353a 37 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
tushki7 0:60d829a0353a 38 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
tushki7 0:60d829a0353a 39 ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
tushki7 0:60d829a0353a 40 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
tushki7 0:60d829a0353a 41 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
tushki7 0:60d829a0353a 42 ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
tushki7 0:60d829a0353a 43 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
tushki7 0:60d829a0353a 44 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tushki7 0:60d829a0353a 45 **
tushki7 0:60d829a0353a 46 ** http: www.freescale.com
tushki7 0:60d829a0353a 47 ** mail: support@freescale.com
tushki7 0:60d829a0353a 48 **
tushki7 0:60d829a0353a 49 ** Revisions:
tushki7 0:60d829a0353a 50 ** - rev. 1.0 (2013-07-23)
tushki7 0:60d829a0353a 51 ** Initial version.
tushki7 0:60d829a0353a 52 ** - rev. 1.1 (2013-09-17)
tushki7 0:60d829a0353a 53 ** RM rev. 0.4 update.
tushki7 0:60d829a0353a 54 ** - rev. 2.0 (2013-10-29)
tushki7 0:60d829a0353a 55 ** Register accessor macros added to the memory map.
tushki7 0:60d829a0353a 56 ** Symbols for Processor Expert memory map compatibility added to the memory map.
tushki7 0:60d829a0353a 57 ** Startup file for gcc has been updated according to CMSIS 3.2.
tushki7 0:60d829a0353a 58 ** System initialization updated.
tushki7 0:60d829a0353a 59 ** - rev. 2.1 (2013-10-30)
tushki7 0:60d829a0353a 60 ** Definition of BITBAND macros updated to support peripherals with 32-bit acces disabled.
tushki7 0:60d829a0353a 61 ** - rev. 2.2 (2013-12-20)
tushki7 0:60d829a0353a 62 ** Update according to reference manual rev. 0.6,
tushki7 0:60d829a0353a 63 ** - rev. 2.3 (2014-01-13)
tushki7 0:60d829a0353a 64 ** Update according to reference manual rev. 0.61,
tushki7 0:60d829a0353a 65 ** - rev. 2.4 (2014-02-10)
tushki7 0:60d829a0353a 66 ** The declaration of clock configurations has been moved to separate header file system_MK22F51212.h
tushki7 0:60d829a0353a 67 ** - rev. 2.5 (2014-05-06)
tushki7 0:60d829a0353a 68 ** Update according to reference manual rev. 1.0,
tushki7 0:60d829a0353a 69 ** Update of system and startup files.
tushki7 0:60d829a0353a 70 ** Module access macro module_BASES replaced by module_BASE_PTRS.
tushki7 0:60d829a0353a 71 **
tushki7 0:60d829a0353a 72 ** ###################################################################
tushki7 0:60d829a0353a 73 */
tushki7 0:60d829a0353a 74
tushki7 0:60d829a0353a 75 /*!
tushki7 0:60d829a0353a 76 * @file MK22F51212
tushki7 0:60d829a0353a 77 * @version 2.5
tushki7 0:60d829a0353a 78 * @date 2014-05-06
tushki7 0:60d829a0353a 79 * @brief Device specific configuration file for MK22F51212 (header file)
tushki7 0:60d829a0353a 80 *
tushki7 0:60d829a0353a 81 * Provides a system configuration function and a global variable that contains
tushki7 0:60d829a0353a 82 * the system frequency. It configures the device and initializes the oscillator
tushki7 0:60d829a0353a 83 * (PLL) that is part of the microcontroller device.
tushki7 0:60d829a0353a 84 */
tushki7 0:60d829a0353a 85
tushki7 0:60d829a0353a 86 #ifndef SYSTEM_MK22F51212_H_
tushki7 0:60d829a0353a 87 #define SYSTEM_MK22F51212_H_ /**< Symbol preventing repeated inclusion */
tushki7 0:60d829a0353a 88
tushki7 0:60d829a0353a 89 #ifdef __cplusplus
tushki7 0:60d829a0353a 90 extern "C" {
tushki7 0:60d829a0353a 91 #endif
tushki7 0:60d829a0353a 92
tushki7 0:60d829a0353a 93 #include <stdint.h>
tushki7 0:60d829a0353a 94
tushki7 0:60d829a0353a 95
tushki7 0:60d829a0353a 96 #define DISABLE_WDOG 1
tushki7 0:60d829a0353a 97
tushki7 0:60d829a0353a 98 #ifndef CLOCK_SETUP
tushki7 0:60d829a0353a 99 #define CLOCK_SETUP 4
tushki7 0:60d829a0353a 100 #endif
tushki7 0:60d829a0353a 101
tushki7 0:60d829a0353a 102 /* MCG mode constants */
tushki7 0:60d829a0353a 103
tushki7 0:60d829a0353a 104 #define MCG_MODE_FEI 0U
tushki7 0:60d829a0353a 105 #define MCG_MODE_FBI 1U
tushki7 0:60d829a0353a 106 #define MCG_MODE_BLPI 2U
tushki7 0:60d829a0353a 107 #define MCG_MODE_FEE 3U
tushki7 0:60d829a0353a 108 #define MCG_MODE_FBE 4U
tushki7 0:60d829a0353a 109 #define MCG_MODE_BLPE 5U
tushki7 0:60d829a0353a 110 #define MCG_MODE_PBE 6U
tushki7 0:60d829a0353a 111 #define MCG_MODE_PEE 7U
tushki7 0:60d829a0353a 112
tushki7 0:60d829a0353a 113 /* Predefined clock setups
tushki7 0:60d829a0353a 114 0 ... Default part configuration
tushki7 0:60d829a0353a 115 Multipurpose Clock Generator (MCG) in FEI mode.
tushki7 0:60d829a0353a 116 Reference clock source for MCG module: Slow internal reference clock
tushki7 0:60d829a0353a 117 Core clock = 20.97152MHz
tushki7 0:60d829a0353a 118 Bus clock = 20.97152MHz
tushki7 0:60d829a0353a 119 1 ... Maximum achievable clock frequency configuration
tushki7 0:60d829a0353a 120 Multipurpose Clock Generator (MCG) in PEE mode.
tushki7 0:60d829a0353a 121 Reference clock source for MCG module: System oscillator 0 reference clock
tushki7 0:60d829a0353a 122 Core clock = 120MHz
tushki7 0:60d829a0353a 123 Bus clock = 60MHz
tushki7 0:60d829a0353a 124 2 ... Chip internaly clocked, ready for Very Low Power Run mode.
tushki7 0:60d829a0353a 125 Multipurpose Clock Generator (MCG) in BLPI mode.
tushki7 0:60d829a0353a 126 Reference clock source for MCG module: Fast internal reference clock
tushki7 0:60d829a0353a 127 Core clock = 4MHz
tushki7 0:60d829a0353a 128 Bus clock = 4MHz
tushki7 0:60d829a0353a 129 3 ... Chip externally clocked, ready for Very Low Power Run mode.
tushki7 0:60d829a0353a 130 Multipurpose Clock Generator (MCG) in BLPE mode.
tushki7 0:60d829a0353a 131 Reference clock source for MCG module: System oscillator 0 reference clock
tushki7 0:60d829a0353a 132 Core clock = 4MHz
tushki7 0:60d829a0353a 133 Bus clock = 4MHz
tushki7 0:60d829a0353a 134 4 ... USB clock setup
tushki7 0:60d829a0353a 135 Multipurpose Clock Generator (MCG) in PEE mode.
tushki7 0:60d829a0353a 136 Reference clock source for MCG module: System oscillator 0 reference clock
tushki7 0:60d829a0353a 137 Core clock = 120MHz
tushki7 0:60d829a0353a 138 Bus clock = 60MHz
tushki7 0:60d829a0353a 139 5 ... Maximum achievable clock frequency configuration in RUN mode
tushki7 0:60d829a0353a 140 Multipurpose Clock Generator (MCG) in PEE mode.
tushki7 0:60d829a0353a 141 Reference clock source for MCG module: System oscillator 0 reference clock
tushki7 0:60d829a0353a 142 Core clock = 80MHz
tushki7 0:60d829a0353a 143 Bus clock = 40MHz
tushki7 0:60d829a0353a 144 */
tushki7 0:60d829a0353a 145
tushki7 0:60d829a0353a 146 /* Define clock source values */
tushki7 0:60d829a0353a 147
tushki7 0:60d829a0353a 148 #define CPU_XTAL_CLK_HZ 8000000u /* Value of the external crystal or oscillator clock frequency in Hz */
tushki7 0:60d829a0353a 149 #define CPU_XTAL32k_CLK_HZ 32768u /* Value of the external 32k crystal or oscillator clock frequency in Hz */
tushki7 0:60d829a0353a 150 #define CPU_INT_SLOW_CLK_HZ 32768u /* Value of the slow internal oscillator clock frequency in Hz */
tushki7 0:60d829a0353a 151 #define CPU_INT_FAST_CLK_HZ 4000000u /* Value of the fast internal oscillator clock frequency in Hz */
tushki7 0:60d829a0353a 152 #define CPU_INT_IRC_CLK_HZ 48000000u /* Value of the 48M internal oscillator clock frequency in Hz */
tushki7 0:60d829a0353a 153
tushki7 0:60d829a0353a 154 /* RTC oscillator setting */
tushki7 0:60d829a0353a 155 /* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0,CLKO=1,OSCE=1,WPS=0,UM=0,SUP=0,WPE=0,SWR=0 */
tushki7 0:60d829a0353a 156 #define SYSTEM_RTC_CR_VALUE 0x0300U /* RTC_CR */
tushki7 0:60d829a0353a 157
tushki7 0:60d829a0353a 158 /* Low power mode enable */
tushki7 0:60d829a0353a 159 /* SMC_PMPROT: AHSRUN=1,AVLP=1,ALLS=1,AVLLS=1 */
tushki7 0:60d829a0353a 160 #define SYSTEM_SMC_PMPROT_VALUE 0xAAU /* SMC_PMPROT */
tushki7 0:60d829a0353a 161
tushki7 0:60d829a0353a 162 /* Internal reference clock trim */
tushki7 0:60d829a0353a 163 /* #undef SLOW_TRIM_ADDRESS */ /* Slow oscillator not trimmed. Commented out for MISRA compliance. */
tushki7 0:60d829a0353a 164 /* #undef SLOW_FINE_TRIM_ADDRESS */ /* Slow oscillator not trimmed. Commented out for MISRA compliance. */
tushki7 0:60d829a0353a 165 /* #undef FAST_TRIM_ADDRESS */ /* Fast oscillator not trimmed. Commented out for MISRA compliance. */
tushki7 0:60d829a0353a 166 /* #undef FAST_FINE_TRIM_ADDRESS */ /* Fast oscillator not trimmed. Commented out for MISRA compliance. */
tushki7 0:60d829a0353a 167
tushki7 0:60d829a0353a 168 #if (CLOCK_SETUP == 0)
tushki7 0:60d829a0353a 169 #define DEFAULT_SYSTEM_CLOCK 20971520u /* Default System clock value */
tushki7 0:60d829a0353a 170 #define MCG_MODE MCG_MODE_FEI /* Clock generator mode */
tushki7 0:60d829a0353a 171 /* MCG_C1: CLKS=0,FRDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */
tushki7 0:60d829a0353a 172 #define SYSTEM_MCG_C1_VALUE 0x06U /* MCG_C1 */
tushki7 0:60d829a0353a 173 /* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
tushki7 0:60d829a0353a 174 #define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
tushki7 0:60d829a0353a 175 /* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
tushki7 0:60d829a0353a 176 #define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
tushki7 0:60d829a0353a 177 /* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
tushki7 0:60d829a0353a 178 #define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
tushki7 0:60d829a0353a 179 /* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=0 */
tushki7 0:60d829a0353a 180 #define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
tushki7 0:60d829a0353a 181 /* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV0=0 */
tushki7 0:60d829a0353a 182 #define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
tushki7 0:60d829a0353a 183 /* MCG_C7: OSCSEL=0 */
tushki7 0:60d829a0353a 184 #define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
tushki7 0:60d829a0353a 185 /* OSC_CR: ERCLKEN=0,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
tushki7 0:60d829a0353a 186 #define SYSTEM_OSC_CR_VALUE 0x00U /* OSC_CR */
tushki7 0:60d829a0353a 187 /* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
tushki7 0:60d829a0353a 188 #define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
tushki7 0:60d829a0353a 189 /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1 */
tushki7 0:60d829a0353a 190 #define SYSTEM_SIM_CLKDIV1_VALUE 0x00110000U /* SIM_CLKDIV1 */
tushki7 0:60d829a0353a 191 /* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,OSC32KOUT=0,RAMSIZE=0 */
tushki7 0:60d829a0353a 192 #define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
tushki7 0:60d829a0353a 193 /* SIM_SOPT2: LPUARTSRC=0,USBSRC=0,PLLFLLSEL=0,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
tushki7 0:60d829a0353a 194 #define SYSTEM_SIM_SOPT2_VALUE 0x00U /* SIM_SOPT2 */
tushki7 0:60d829a0353a 195 #elif (CLOCK_SETUP == 1)
tushki7 0:60d829a0353a 196 #define DEFAULT_SYSTEM_CLOCK 120000000u /* Default System clock value */
tushki7 0:60d829a0353a 197 #define MCG_MODE MCG_MODE_PEE /* Clock generator mode */
tushki7 0:60d829a0353a 198 /* MCG_C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
tushki7 0:60d829a0353a 199 #define SYSTEM_MCG_C1_VALUE 0x1AU /* MCG_C1 */
tushki7 0:60d829a0353a 200 /* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
tushki7 0:60d829a0353a 201 #define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
tushki7 0:60d829a0353a 202 /* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
tushki7 0:60d829a0353a 203 #define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
tushki7 0:60d829a0353a 204 /* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
tushki7 0:60d829a0353a 205 #define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
tushki7 0:60d829a0353a 206 /* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=1 */
tushki7 0:60d829a0353a 207 #define SYSTEM_MCG_C5_VALUE 0x01U /* MCG_C5 */
tushki7 0:60d829a0353a 208 /* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV0=6 */
tushki7 0:60d829a0353a 209 #define SYSTEM_MCG_C6_VALUE 0x46U /* MCG_C6 */
tushki7 0:60d829a0353a 210 /* MCG_C7: OSCSEL=0 */
tushki7 0:60d829a0353a 211 #define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
tushki7 0:60d829a0353a 212 /* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
tushki7 0:60d829a0353a 213 #define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
tushki7 0:60d829a0353a 214 /* SMC_PMCTRL: RUNM=3,STOPA=0,STOPM=0 */
tushki7 0:60d829a0353a 215 #define SYSTEM_SMC_PMCTRL_VALUE 0x60U /* SMC_PMCTRL */
tushki7 0:60d829a0353a 216 /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=1,OUTDIV3=1,OUTDIV4=4 */
tushki7 0:60d829a0353a 217 #define SYSTEM_SIM_CLKDIV1_VALUE 0x01140000U /* SIM_CLKDIV1 */
tushki7 0:60d829a0353a 218 /* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,OSC32KOUT=0,RAMSIZE=0 */
tushki7 0:60d829a0353a 219 #define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
tushki7 0:60d829a0353a 220 /* SIM_SOPT2: LPUARTSRC=0,USBSRC=0,PLLFLLSEL=1,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
tushki7 0:60d829a0353a 221 #define SYSTEM_SIM_SOPT2_VALUE 0x00010000U /* SIM_SOPT2 */
tushki7 0:60d829a0353a 222 #elif (CLOCK_SETUP == 2)
tushki7 0:60d829a0353a 223 #define DEFAULT_SYSTEM_CLOCK 4000000u /* Default System clock value */
tushki7 0:60d829a0353a 224 #define MCG_MODE MCG_MODE_BLPI /* Clock generator mode */
tushki7 0:60d829a0353a 225 /* MCG_C1: CLKS=1,FRDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */
tushki7 0:60d829a0353a 226 #define SYSTEM_MCG_C1_VALUE 0x46U /* MCG_C1 */
tushki7 0:60d829a0353a 227 /* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=1,IRCS=1 */
tushki7 0:60d829a0353a 228 #define SYSTEM_MCG_C2_VALUE 0x27U /* MCG_C2 */
tushki7 0:60d829a0353a 229 /* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
tushki7 0:60d829a0353a 230 #define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
tushki7 0:60d829a0353a 231 /* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
tushki7 0:60d829a0353a 232 #define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
tushki7 0:60d829a0353a 233 /* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=0 */
tushki7 0:60d829a0353a 234 #define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
tushki7 0:60d829a0353a 235 /* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV0=0 */
tushki7 0:60d829a0353a 236 #define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
tushki7 0:60d829a0353a 237 /* MCG_C7: OSCSEL=0 */
tushki7 0:60d829a0353a 238 #define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
tushki7 0:60d829a0353a 239 /* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
tushki7 0:60d829a0353a 240 #define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
tushki7 0:60d829a0353a 241 /* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
tushki7 0:60d829a0353a 242 #define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
tushki7 0:60d829a0353a 243 /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=0,OUTDIV4=4 */
tushki7 0:60d829a0353a 244 #define SYSTEM_SIM_CLKDIV1_VALUE 0x00040000U /* SIM_CLKDIV1 */
tushki7 0:60d829a0353a 245 /* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,OSC32KOUT=0,RAMSIZE=0 */
tushki7 0:60d829a0353a 246 #define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
tushki7 0:60d829a0353a 247 /* SIM_SOPT2: LPUARTSRC=0,USBSRC=0,PLLFLLSEL=3,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
tushki7 0:60d829a0353a 248 #define SYSTEM_SIM_SOPT2_VALUE 0x00030000U /* SIM_SOPT2 */
tushki7 0:60d829a0353a 249 #elif (CLOCK_SETUP == 3)
tushki7 0:60d829a0353a 250 #define DEFAULT_SYSTEM_CLOCK 4000000u /* Default System clock value */
tushki7 0:60d829a0353a 251 #define MCG_MODE MCG_MODE_BLPE /* Clock generator mode */
tushki7 0:60d829a0353a 252 /* MCG_C1: CLKS=2,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
tushki7 0:60d829a0353a 253 #define SYSTEM_MCG_C1_VALUE 0x9AU /* MCG_C1 */
tushki7 0:60d829a0353a 254 /* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=1,IRCS=1 */
tushki7 0:60d829a0353a 255 #define SYSTEM_MCG_C2_VALUE 0x27U /* MCG_C2 */
tushki7 0:60d829a0353a 256 /* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
tushki7 0:60d829a0353a 257 #define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
tushki7 0:60d829a0353a 258 /* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=1,LOCS0=0 */
tushki7 0:60d829a0353a 259 #define SYSTEM_MCG_SC_VALUE 0x02U /* MCG_SC */
tushki7 0:60d829a0353a 260 /* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=0 */
tushki7 0:60d829a0353a 261 #define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
tushki7 0:60d829a0353a 262 /* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV0=0 */
tushki7 0:60d829a0353a 263 #define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
tushki7 0:60d829a0353a 264 /* MCG_C7: OSCSEL=0 */
tushki7 0:60d829a0353a 265 #define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
tushki7 0:60d829a0353a 266 /* OSC_CR: ERCLKEN=0,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
tushki7 0:60d829a0353a 267 #define SYSTEM_OSC_CR_VALUE 0x00U /* OSC_CR */
tushki7 0:60d829a0353a 268 /* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
tushki7 0:60d829a0353a 269 #define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
tushki7 0:60d829a0353a 270 /* SIM_CLKDIV1: OUTDIV1=1,OUTDIV2=1,OUTDIV3=1,OUTDIV4=7 */
tushki7 0:60d829a0353a 271 #define SYSTEM_SIM_CLKDIV1_VALUE 0x11170000U /* SIM_CLKDIV1 */
tushki7 0:60d829a0353a 272 /* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,OSC32KOUT=0,RAMSIZE=0 */
tushki7 0:60d829a0353a 273 #define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
tushki7 0:60d829a0353a 274 /* SIM_SOPT2: LPUARTSRC=0,USBSRC=0,PLLFLLSEL=3,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
tushki7 0:60d829a0353a 275 #define SYSTEM_SIM_SOPT2_VALUE 0x00030000U /* SIM_SOPT2 */
tushki7 0:60d829a0353a 276 #elif (CLOCK_SETUP == 4)
tushki7 0:60d829a0353a 277 #define DEFAULT_SYSTEM_CLOCK 120000000u /* Default System clock value */
tushki7 0:60d829a0353a 278 #define MCG_MODE MCG_MODE_PEE /* Clock generator mode */
tushki7 0:60d829a0353a 279 /* MCG_C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
tushki7 0:60d829a0353a 280 #define SYSTEM_MCG_C1_VALUE 0x1AU /* MCG_C1 */
tushki7 0:60d829a0353a 281 /* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
tushki7 0:60d829a0353a 282 #define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
tushki7 0:60d829a0353a 283 /* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
tushki7 0:60d829a0353a 284 #define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
tushki7 0:60d829a0353a 285 /* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
tushki7 0:60d829a0353a 286 #define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
tushki7 0:60d829a0353a 287 /* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=1 */
tushki7 0:60d829a0353a 288 #define SYSTEM_MCG_C5_VALUE 0x01U /* MCG_C5 */
tushki7 0:60d829a0353a 289 /* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV0=6 */
tushki7 0:60d829a0353a 290 #define SYSTEM_MCG_C6_VALUE 0x46U /* MCG_C6 */
tushki7 0:60d829a0353a 291 /* MCG_C7: OSCSEL=0 */
tushki7 0:60d829a0353a 292 #define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
tushki7 0:60d829a0353a 293 /* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
tushki7 0:60d829a0353a 294 #define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
tushki7 0:60d829a0353a 295 /* SMC_PMCTRL: RUNM=3,STOPA=0,STOPM=0 */
tushki7 0:60d829a0353a 296 #define SYSTEM_SMC_PMCTRL_VALUE 0x60U /* SMC_PMCTRL */
tushki7 0:60d829a0353a 297 /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=1,OUTDIV3=1,OUTDIV4=4 */
tushki7 0:60d829a0353a 298 #define SYSTEM_SIM_CLKDIV1_VALUE 0x01140000U /* SIM_CLKDIV1 */
tushki7 0:60d829a0353a 299 /* SIM_CLKDIV2: USBDIV=4,USBFRAC=1 */
tushki7 0:60d829a0353a 300 #define SYSTEM_SIM_CLKDIV2_VALUE 0x09U /* SIM_CLKDIV2 */
tushki7 0:60d829a0353a 301 /* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,OSC32KOUT=0,RAMSIZE=0 */
tushki7 0:60d829a0353a 302 #define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
tushki7 0:60d829a0353a 303 /* SIM_SOPT2: LPUARTSRC=0,USBSRC=0,PLLFLLSEL=1,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
tushki7 0:60d829a0353a 304 #define SYSTEM_SIM_SOPT2_VALUE 0x00010000U /* SIM_SOPT2 */
tushki7 0:60d829a0353a 305 #elif (CLOCK_SETUP == 5)
tushki7 0:60d829a0353a 306 #define DEFAULT_SYSTEM_CLOCK 80000000u /* Default System clock value */
tushki7 0:60d829a0353a 307 #define MCG_MODE MCG_MODE_PEE /* Clock generator mode */
tushki7 0:60d829a0353a 308 /* MCG_C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
tushki7 0:60d829a0353a 309 #define SYSTEM_MCG_C1_VALUE 0x1AU /* MCG_C1 */
tushki7 0:60d829a0353a 310 /* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
tushki7 0:60d829a0353a 311 #define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
tushki7 0:60d829a0353a 312 /* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
tushki7 0:60d829a0353a 313 #define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
tushki7 0:60d829a0353a 314 /* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
tushki7 0:60d829a0353a 315 #define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
tushki7 0:60d829a0353a 316 /* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=3 */
tushki7 0:60d829a0353a 317 #define SYSTEM_MCG_C5_VALUE 0x03U /* MCG_C5 */
tushki7 0:60d829a0353a 318 /* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV0=0x10 */
tushki7 0:60d829a0353a 319 #define SYSTEM_MCG_C6_VALUE 0x50U /* MCG_C6 */
tushki7 0:60d829a0353a 320 /* MCG_C7: OSCSEL=0 */
tushki7 0:60d829a0353a 321 #define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
tushki7 0:60d829a0353a 322 /* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
tushki7 0:60d829a0353a 323 #define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
tushki7 0:60d829a0353a 324 /* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
tushki7 0:60d829a0353a 325 #define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
tushki7 0:60d829a0353a 326 /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=1,OUTDIV3=1,OUTDIV4=3 */
tushki7 0:60d829a0353a 327 #define SYSTEM_SIM_CLKDIV1_VALUE 0x01130000U /* SIM_CLKDIV1 */
tushki7 0:60d829a0353a 328 /* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,OSC32KOUT=0,RAMSIZE=0 */
tushki7 0:60d829a0353a 329 #define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
tushki7 0:60d829a0353a 330 /* SIM_SOPT2: LPUARTSRC=0,USBSRC=0,PLLFLLSEL=1,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
tushki7 0:60d829a0353a 331 #define SYSTEM_SIM_SOPT2_VALUE 0x00010000U /* SIM_SOPT2 */
tushki7 0:60d829a0353a 332 #endif
tushki7 0:60d829a0353a 333
tushki7 0:60d829a0353a 334 /**
tushki7 0:60d829a0353a 335 * @brief System clock frequency (core clock)
tushki7 0:60d829a0353a 336 *
tushki7 0:60d829a0353a 337 * The system clock frequency supplied to the SysTick timer and the processor
tushki7 0:60d829a0353a 338 * core clock. This variable can be used by the user application to setup the
tushki7 0:60d829a0353a 339 * SysTick timer or configure other parameters. It may also be used by debugger to
tushki7 0:60d829a0353a 340 * query the frequency of the debug timer or configure the trace clock speed
tushki7 0:60d829a0353a 341 * SystemCoreClock is initialized with a correct predefined value.
tushki7 0:60d829a0353a 342 */
tushki7 0:60d829a0353a 343 extern uint32_t SystemCoreClock;
tushki7 0:60d829a0353a 344
tushki7 0:60d829a0353a 345 /**
tushki7 0:60d829a0353a 346 * @brief Setup the microcontroller system.
tushki7 0:60d829a0353a 347 *
tushki7 0:60d829a0353a 348 * Typically this function configures the oscillator (PLL) that is part of the
tushki7 0:60d829a0353a 349 * microcontroller device. For systems with variable clock speed it also updates
tushki7 0:60d829a0353a 350 * the variable SystemCoreClock. SystemInit is called from startup_device file.
tushki7 0:60d829a0353a 351 */
tushki7 0:60d829a0353a 352 void SystemInit (void);
tushki7 0:60d829a0353a 353
tushki7 0:60d829a0353a 354 /**
tushki7 0:60d829a0353a 355 * @brief Updates the SystemCoreClock variable.
tushki7 0:60d829a0353a 356 *
tushki7 0:60d829a0353a 357 * It must be called whenever the core clock is changed during program
tushki7 0:60d829a0353a 358 * execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates
tushki7 0:60d829a0353a 359 * the current core clock.
tushki7 0:60d829a0353a 360 */
tushki7 0:60d829a0353a 361 void SystemCoreClockUpdate (void);
tushki7 0:60d829a0353a 362
tushki7 0:60d829a0353a 363 #ifdef __cplusplus
tushki7 0:60d829a0353a 364 }
tushki7 0:60d829a0353a 365 #endif
tushki7 0:60d829a0353a 366
tushki7 0:60d829a0353a 367 #endif /* #if !defined(SYSTEM_MK22F51212_H_) */