1*f7529f1dSMatthias Ringwald /* 2*f7529f1dSMatthias Ringwald * ------------------------------------------- 3*f7529f1dSMatthias Ringwald * MSP432 DriverLib - v3_10_00_09 4*f7529f1dSMatthias Ringwald * ------------------------------------------- 5*f7529f1dSMatthias Ringwald * 6*f7529f1dSMatthias Ringwald * --COPYRIGHT--,BSD,BSD 7*f7529f1dSMatthias Ringwald * Copyright (c) 2014, Texas Instruments Incorporated 8*f7529f1dSMatthias Ringwald * All rights reserved. 9*f7529f1dSMatthias Ringwald * 10*f7529f1dSMatthias Ringwald * Redistribution and use in source and binary forms, with or without 11*f7529f1dSMatthias Ringwald * modification, are permitted provided that the following conditions 12*f7529f1dSMatthias Ringwald * are met: 13*f7529f1dSMatthias Ringwald * 14*f7529f1dSMatthias Ringwald * * Redistributions of source code must retain the above copyright 15*f7529f1dSMatthias Ringwald * notice, this list of conditions and the following disclaimer. 16*f7529f1dSMatthias Ringwald * 17*f7529f1dSMatthias Ringwald * * Redistributions in binary form must reproduce the above copyright 18*f7529f1dSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 19*f7529f1dSMatthias Ringwald * documentation and/or other materials provided with the distribution. 20*f7529f1dSMatthias Ringwald * 21*f7529f1dSMatthias Ringwald * * Neither the name of Texas Instruments Incorporated nor the names of 22*f7529f1dSMatthias Ringwald * its contributors may be used to endorse or promote products derived 23*f7529f1dSMatthias Ringwald * from this software without specific prior written permission. 24*f7529f1dSMatthias Ringwald * 25*f7529f1dSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26*f7529f1dSMatthias Ringwald * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 27*f7529f1dSMatthias Ringwald * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28*f7529f1dSMatthias Ringwald * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29*f7529f1dSMatthias Ringwald * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30*f7529f1dSMatthias Ringwald * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31*f7529f1dSMatthias Ringwald * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 32*f7529f1dSMatthias Ringwald * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 33*f7529f1dSMatthias Ringwald * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 34*f7529f1dSMatthias Ringwald * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 35*f7529f1dSMatthias Ringwald * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36*f7529f1dSMatthias Ringwald * --/COPYRIGHT--*/ 37*f7529f1dSMatthias Ringwald /**************************************************************************//** 38*f7529f1dSMatthias Ringwald * @file system_msp432p401r.c 39*f7529f1dSMatthias Ringwald * @brief CMSIS Cortex-M4F Device Peripheral Access Layer Source File for 40*f7529f1dSMatthias Ringwald * MSP432P401R 41*f7529f1dSMatthias Ringwald * @version V1.00 42*f7529f1dSMatthias Ringwald * @date 20-Oct-2015 43*f7529f1dSMatthias Ringwald * 44*f7529f1dSMatthias Ringwald * @note View configuration instructions embedded in comments 45*f7529f1dSMatthias Ringwald * 46*f7529f1dSMatthias Ringwald ******************************************************************************/ 47*f7529f1dSMatthias Ringwald //***************************************************************************** 48*f7529f1dSMatthias Ringwald // 49*f7529f1dSMatthias Ringwald // Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 50*f7529f1dSMatthias Ringwald // 51*f7529f1dSMatthias Ringwald // Redistribution and use in source and binary forms, with or without 52*f7529f1dSMatthias Ringwald // modification, are permitted provided that the following conditions 53*f7529f1dSMatthias Ringwald // are met: 54*f7529f1dSMatthias Ringwald // 55*f7529f1dSMatthias Ringwald // Redistributions of source code must retain the above copyright 56*f7529f1dSMatthias Ringwald // notice, this list of conditions and the following disclaimer. 57*f7529f1dSMatthias Ringwald // 58*f7529f1dSMatthias Ringwald // Redistributions in binary form must reproduce the above copyright 59*f7529f1dSMatthias Ringwald // notice, this list of conditions and the following disclaimer in the 60*f7529f1dSMatthias Ringwald // documentation and/or other materials provided with the 61*f7529f1dSMatthias Ringwald // distribution. 62*f7529f1dSMatthias Ringwald // 63*f7529f1dSMatthias Ringwald // Neither the name of Texas Instruments Incorporated nor the names of 64*f7529f1dSMatthias Ringwald // its contributors may be used to endorse or promote products derived 65*f7529f1dSMatthias Ringwald // from this software without specific prior written permission. 66*f7529f1dSMatthias Ringwald // 67*f7529f1dSMatthias Ringwald // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 68*f7529f1dSMatthias Ringwald // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 69*f7529f1dSMatthias Ringwald // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 70*f7529f1dSMatthias Ringwald // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 71*f7529f1dSMatthias Ringwald // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 72*f7529f1dSMatthias Ringwald // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 73*f7529f1dSMatthias Ringwald // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 74*f7529f1dSMatthias Ringwald // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 75*f7529f1dSMatthias Ringwald // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 76*f7529f1dSMatthias Ringwald // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 77*f7529f1dSMatthias Ringwald // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 78*f7529f1dSMatthias Ringwald // 79*f7529f1dSMatthias Ringwald //***************************************************************************** 80*f7529f1dSMatthias Ringwald 81*f7529f1dSMatthias Ringwald #include <stdint.h> 82*f7529f1dSMatthias Ringwald #include "msp.h" 83*f7529f1dSMatthias Ringwald 84*f7529f1dSMatthias Ringwald /*--------------------- Configuration Instructions ---------------------------- 85*f7529f1dSMatthias Ringwald 1. If you prefer to halt the Watchdog Timer, set __HALT_WDT to 1: 86*f7529f1dSMatthias Ringwald #define __HALT_WDT 1 87*f7529f1dSMatthias Ringwald 2. Insert your desired CPU frequency in Hz at: 88*f7529f1dSMatthias Ringwald #define __SYSTEM_CLOCK 3000000 89*f7529f1dSMatthias Ringwald 3. If you prefer the DC-DC power regulator (more efficient at higher 90*f7529f1dSMatthias Ringwald frequencies), set the __REGULATOR to 1: 91*f7529f1dSMatthias Ringwald #define __REGULATOR 1 92*f7529f1dSMatthias Ringwald *---------------------------------------------------------------------------*/ 93*f7529f1dSMatthias Ringwald 94*f7529f1dSMatthias Ringwald /*--------------------- Watchdog Timer Configuration ------------------------*/ 95*f7529f1dSMatthias Ringwald // Halt the Watchdog Timer 96*f7529f1dSMatthias Ringwald // <0> Do not halt the WDT 97*f7529f1dSMatthias Ringwald // <1> Halt the WDT 98*f7529f1dSMatthias Ringwald #define __HALT_WDT 1 99*f7529f1dSMatthias Ringwald 100*f7529f1dSMatthias Ringwald /*--------------------- CPU Frequency Configuration -------------------------*/ 101*f7529f1dSMatthias Ringwald // CPU Frequency 102*f7529f1dSMatthias Ringwald // <1500000> 1.5 MHz 103*f7529f1dSMatthias Ringwald // <3000000> 3 MHz 104*f7529f1dSMatthias Ringwald // <12000000> 12 MHz 105*f7529f1dSMatthias Ringwald // <24000000> 24 MHz 106*f7529f1dSMatthias Ringwald // <48000000> 48 MHz 107*f7529f1dSMatthias Ringwald #define __SYSTEM_CLOCK 24000000 108*f7529f1dSMatthias Ringwald 109*f7529f1dSMatthias Ringwald /*--------------------- Power Regulator Configuration -----------------------*/ 110*f7529f1dSMatthias Ringwald // Power Regulator Mode 111*f7529f1dSMatthias Ringwald // <0> LDO 112*f7529f1dSMatthias Ringwald // <1> DC-DC 113*f7529f1dSMatthias Ringwald #define __REGULATOR 1 114*f7529f1dSMatthias Ringwald 115*f7529f1dSMatthias Ringwald /*---------------------------------------------------------------------------- 116*f7529f1dSMatthias Ringwald Define clocks, used for SystemCoreClockUpdate() 117*f7529f1dSMatthias Ringwald *---------------------------------------------------------------------------*/ 118*f7529f1dSMatthias Ringwald #define __VLOCLK 10000 119*f7529f1dSMatthias Ringwald #define __MODCLK 24000000 120*f7529f1dSMatthias Ringwald #define __LFXT 32768 121*f7529f1dSMatthias Ringwald #define __HFXT 48000000 122*f7529f1dSMatthias Ringwald 123*f7529f1dSMatthias Ringwald /*---------------------------------------------------------------------------- 124*f7529f1dSMatthias Ringwald Clock Variable definitions 125*f7529f1dSMatthias Ringwald *---------------------------------------------------------------------------*/ 126*f7529f1dSMatthias Ringwald uint32_t SystemCoreClock = __SYSTEM_CLOCK; /*!< System Clock Frequency (Core Clock)*/ 127*f7529f1dSMatthias Ringwald 128*f7529f1dSMatthias Ringwald /** 129*f7529f1dSMatthias Ringwald * Update SystemCoreClock variable 130*f7529f1dSMatthias Ringwald * 131*f7529f1dSMatthias Ringwald * @param none 132*f7529f1dSMatthias Ringwald * @return none 133*f7529f1dSMatthias Ringwald * 134*f7529f1dSMatthias Ringwald * @brief Updates the SystemCoreClock with current core Clock 135*f7529f1dSMatthias Ringwald * retrieved from cpu registers. 136*f7529f1dSMatthias Ringwald */ 137*f7529f1dSMatthias Ringwald void SystemCoreClockUpdate(void) 138*f7529f1dSMatthias Ringwald { 139*f7529f1dSMatthias Ringwald uint32_t source, divider; 140*f7529f1dSMatthias Ringwald uint8_t dividerValue; 141*f7529f1dSMatthias Ringwald 142*f7529f1dSMatthias Ringwald float dcoConst; 143*f7529f1dSMatthias Ringwald int32_t calVal; 144*f7529f1dSMatthias Ringwald uint32_t centeredFreq; 145*f7529f1dSMatthias Ringwald int16_t dcoTune; 146*f7529f1dSMatthias Ringwald 147*f7529f1dSMatthias Ringwald divider = (CS->CTL1 & CS_CTL1_DIVM_MASK) >> CS_CTL1_DIVM_OFS; 148*f7529f1dSMatthias Ringwald dividerValue = 1 << divider; 149*f7529f1dSMatthias Ringwald source = CS->CTL1 & CS_CTL1_SELM_MASK; 150*f7529f1dSMatthias Ringwald 151*f7529f1dSMatthias Ringwald switch(source) 152*f7529f1dSMatthias Ringwald { 153*f7529f1dSMatthias Ringwald case CS_CTL1_SELM__LFXTCLK: 154*f7529f1dSMatthias Ringwald if(BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS)) 155*f7529f1dSMatthias Ringwald { 156*f7529f1dSMatthias Ringwald // Clear interrupt flag 157*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; 158*f7529f1dSMatthias Ringwald CS->CLRIFG |= CS_CLRIFG_CLR_LFXTIFG; 159*f7529f1dSMatthias Ringwald CS->KEY = 1; 160*f7529f1dSMatthias Ringwald 161*f7529f1dSMatthias Ringwald if(BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS)) 162*f7529f1dSMatthias Ringwald { 163*f7529f1dSMatthias Ringwald if(BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS)) 164*f7529f1dSMatthias Ringwald { 165*f7529f1dSMatthias Ringwald SystemCoreClock = (128000 / dividerValue); 166*f7529f1dSMatthias Ringwald } 167*f7529f1dSMatthias Ringwald else 168*f7529f1dSMatthias Ringwald { 169*f7529f1dSMatthias Ringwald SystemCoreClock = (32000 / dividerValue); 170*f7529f1dSMatthias Ringwald } 171*f7529f1dSMatthias Ringwald } 172*f7529f1dSMatthias Ringwald else 173*f7529f1dSMatthias Ringwald { 174*f7529f1dSMatthias Ringwald SystemCoreClock = __LFXT / dividerValue; 175*f7529f1dSMatthias Ringwald } 176*f7529f1dSMatthias Ringwald } 177*f7529f1dSMatthias Ringwald else 178*f7529f1dSMatthias Ringwald { 179*f7529f1dSMatthias Ringwald SystemCoreClock = __LFXT / dividerValue; 180*f7529f1dSMatthias Ringwald } 181*f7529f1dSMatthias Ringwald break; 182*f7529f1dSMatthias Ringwald case CS_CTL1_SELM__VLOCLK: 183*f7529f1dSMatthias Ringwald SystemCoreClock = __VLOCLK / dividerValue; 184*f7529f1dSMatthias Ringwald break; 185*f7529f1dSMatthias Ringwald case CS_CTL1_SELM__REFOCLK: 186*f7529f1dSMatthias Ringwald if (BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS)) 187*f7529f1dSMatthias Ringwald { 188*f7529f1dSMatthias Ringwald SystemCoreClock = (128000 / dividerValue); 189*f7529f1dSMatthias Ringwald } 190*f7529f1dSMatthias Ringwald else 191*f7529f1dSMatthias Ringwald { 192*f7529f1dSMatthias Ringwald SystemCoreClock = (32000 / dividerValue); 193*f7529f1dSMatthias Ringwald } 194*f7529f1dSMatthias Ringwald break; 195*f7529f1dSMatthias Ringwald case CS_CTL1_SELM__DCOCLK: 196*f7529f1dSMatthias Ringwald dcoTune = (CS->CTL0 & CS_CTL0_DCOTUNE_MASK) >> CS_CTL0_DCOTUNE_OFS; 197*f7529f1dSMatthias Ringwald 198*f7529f1dSMatthias Ringwald switch(CS->CTL0 & CS_CTL0_DCORSEL_MASK) 199*f7529f1dSMatthias Ringwald { 200*f7529f1dSMatthias Ringwald case CS_CTL0_DCORSEL_0: 201*f7529f1dSMatthias Ringwald centeredFreq = 1500000; 202*f7529f1dSMatthias Ringwald break; 203*f7529f1dSMatthias Ringwald case CS_CTL0_DCORSEL_1: 204*f7529f1dSMatthias Ringwald centeredFreq = 3000000; 205*f7529f1dSMatthias Ringwald break; 206*f7529f1dSMatthias Ringwald case CS_CTL0_DCORSEL_2: 207*f7529f1dSMatthias Ringwald centeredFreq = 6000000; 208*f7529f1dSMatthias Ringwald break; 209*f7529f1dSMatthias Ringwald case CS_CTL0_DCORSEL_3: 210*f7529f1dSMatthias Ringwald centeredFreq = 12000000; 211*f7529f1dSMatthias Ringwald break; 212*f7529f1dSMatthias Ringwald case CS_CTL0_DCORSEL_4: 213*f7529f1dSMatthias Ringwald centeredFreq = 24000000; 214*f7529f1dSMatthias Ringwald break; 215*f7529f1dSMatthias Ringwald case CS_CTL0_DCORSEL_5: 216*f7529f1dSMatthias Ringwald centeredFreq = 48000000; 217*f7529f1dSMatthias Ringwald break; 218*f7529f1dSMatthias Ringwald } 219*f7529f1dSMatthias Ringwald 220*f7529f1dSMatthias Ringwald if(dcoTune == 0) 221*f7529f1dSMatthias Ringwald { 222*f7529f1dSMatthias Ringwald SystemCoreClock = centeredFreq; 223*f7529f1dSMatthias Ringwald } 224*f7529f1dSMatthias Ringwald else 225*f7529f1dSMatthias Ringwald { 226*f7529f1dSMatthias Ringwald 227*f7529f1dSMatthias Ringwald if(dcoTune & 0x1000) 228*f7529f1dSMatthias Ringwald { 229*f7529f1dSMatthias Ringwald dcoTune = dcoTune | 0xF000; 230*f7529f1dSMatthias Ringwald } 231*f7529f1dSMatthias Ringwald 232*f7529f1dSMatthias Ringwald if (BITBAND_PERI(CS->CTL0, CS_CTL0_DCORES_OFS)) 233*f7529f1dSMatthias Ringwald { 234*f7529f1dSMatthias Ringwald dcoConst = *((float *) &TLV->DCOER_CONSTK_RSEL04); 235*f7529f1dSMatthias Ringwald calVal = TLV->DCOER_FCAL_RSEL04; 236*f7529f1dSMatthias Ringwald } 237*f7529f1dSMatthias Ringwald /* Internal Resistor */ 238*f7529f1dSMatthias Ringwald else 239*f7529f1dSMatthias Ringwald { 240*f7529f1dSMatthias Ringwald dcoConst = *((float *) &TLV->DCOIR_CONSTK_RSEL04); 241*f7529f1dSMatthias Ringwald calVal = TLV->DCOIR_FCAL_RSEL04; 242*f7529f1dSMatthias Ringwald } 243*f7529f1dSMatthias Ringwald 244*f7529f1dSMatthias Ringwald SystemCoreClock = (uint32_t) ((centeredFreq) 245*f7529f1dSMatthias Ringwald / (1 246*f7529f1dSMatthias Ringwald - ((dcoConst * dcoTune) 247*f7529f1dSMatthias Ringwald / (8 * (1 + dcoConst * (768 - calVal)))))); 248*f7529f1dSMatthias Ringwald } 249*f7529f1dSMatthias Ringwald break; 250*f7529f1dSMatthias Ringwald case CS_CTL1_SELM__MODOSC: 251*f7529f1dSMatthias Ringwald SystemCoreClock = __MODCLK / dividerValue; 252*f7529f1dSMatthias Ringwald break; 253*f7529f1dSMatthias Ringwald case CS_CTL1_SELM__HFXTCLK: 254*f7529f1dSMatthias Ringwald if(BITBAND_PERI(CS->IFG, CS_IFG_HFXTIFG_OFS)) 255*f7529f1dSMatthias Ringwald { 256*f7529f1dSMatthias Ringwald // Clear interrupt flag 257*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; 258*f7529f1dSMatthias Ringwald CS->CLRIFG |= CS_CLRIFG_CLR_HFXTIFG; 259*f7529f1dSMatthias Ringwald CS->KEY = 1; 260*f7529f1dSMatthias Ringwald 261*f7529f1dSMatthias Ringwald if(BITBAND_PERI(CS->IFG, CS_IFG_HFXTIFG_OFS)) 262*f7529f1dSMatthias Ringwald { 263*f7529f1dSMatthias Ringwald if(BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS)) 264*f7529f1dSMatthias Ringwald { 265*f7529f1dSMatthias Ringwald SystemCoreClock = (128000 / dividerValue); 266*f7529f1dSMatthias Ringwald } 267*f7529f1dSMatthias Ringwald else 268*f7529f1dSMatthias Ringwald { 269*f7529f1dSMatthias Ringwald SystemCoreClock = (32000 / dividerValue); 270*f7529f1dSMatthias Ringwald } 271*f7529f1dSMatthias Ringwald } 272*f7529f1dSMatthias Ringwald else 273*f7529f1dSMatthias Ringwald { 274*f7529f1dSMatthias Ringwald SystemCoreClock = __HFXT / dividerValue; 275*f7529f1dSMatthias Ringwald } 276*f7529f1dSMatthias Ringwald } 277*f7529f1dSMatthias Ringwald else 278*f7529f1dSMatthias Ringwald { 279*f7529f1dSMatthias Ringwald SystemCoreClock = __HFXT / dividerValue; 280*f7529f1dSMatthias Ringwald } 281*f7529f1dSMatthias Ringwald break; 282*f7529f1dSMatthias Ringwald } 283*f7529f1dSMatthias Ringwald } 284*f7529f1dSMatthias Ringwald 285*f7529f1dSMatthias Ringwald /** 286*f7529f1dSMatthias Ringwald * Initialize the system 287*f7529f1dSMatthias Ringwald * 288*f7529f1dSMatthias Ringwald * @param none 289*f7529f1dSMatthias Ringwald * @return none 290*f7529f1dSMatthias Ringwald * 291*f7529f1dSMatthias Ringwald * @brief Setup the microcontroller system. 292*f7529f1dSMatthias Ringwald * 293*f7529f1dSMatthias Ringwald * Performs the following initialization steps: 294*f7529f1dSMatthias Ringwald * 1. Enables the FPU 295*f7529f1dSMatthias Ringwald * 2. Halts the WDT if requested 296*f7529f1dSMatthias Ringwald * 3. Enables all SRAM banks 297*f7529f1dSMatthias Ringwald * 4. Sets up power regulator and VCORE 298*f7529f1dSMatthias Ringwald * 5. Enable Flash wait states if needed 299*f7529f1dSMatthias Ringwald * 6. Change MCLK to desired frequency 300*f7529f1dSMatthias Ringwald * 7. Enable Flash read buffering 301*f7529f1dSMatthias Ringwald */ 302*f7529f1dSMatthias Ringwald void SystemInit(void) 303*f7529f1dSMatthias Ringwald { 304*f7529f1dSMatthias Ringwald // Enable FPU if used 305*f7529f1dSMatthias Ringwald #if (__FPU_USED == 1) /* __FPU_USED is defined in core_cm4.h */ 306*f7529f1dSMatthias Ringwald SCB->CPACR |= ((3UL << 10 * 2) | /* Set CP10 Full Access */ 307*f7529f1dSMatthias Ringwald (3UL << 11 * 2)); /* Set CP11 Full Access */ 308*f7529f1dSMatthias Ringwald #endif 309*f7529f1dSMatthias Ringwald 310*f7529f1dSMatthias Ringwald #if (__HALT_WDT == 1) 311*f7529f1dSMatthias Ringwald WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // Halt the WDT 312*f7529f1dSMatthias Ringwald #endif 313*f7529f1dSMatthias Ringwald 314*f7529f1dSMatthias Ringwald SYSCTL->SRAM_BANKEN = SYSCTL_SRAM_BANKEN_BNK7_EN; // Enable all SRAM banks 315*f7529f1dSMatthias Ringwald 316*f7529f1dSMatthias Ringwald #if (__SYSTEM_CLOCK == 1500000) // 1.5 MHz 317*f7529f1dSMatthias Ringwald // Default VCORE is LDO VCORE0 so no change necessary 318*f7529f1dSMatthias Ringwald 319*f7529f1dSMatthias Ringwald // Switches LDO VCORE0 to DCDC VCORE0 if requested 320*f7529f1dSMatthias Ringwald #if __REGULATOR 321*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 322*f7529f1dSMatthias Ringwald PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4; 323*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 324*f7529f1dSMatthias Ringwald #endif 325*f7529f1dSMatthias Ringwald 326*f7529f1dSMatthias Ringwald // No flash wait states necessary 327*f7529f1dSMatthias Ringwald 328*f7529f1dSMatthias Ringwald // DCO = 1.5 MHz; MCLK = source 329*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; // Unlock CS module for register access 330*f7529f1dSMatthias Ringwald CS->CTL0 = CS_CTL0_DCORSEL_0; // Set DCO to 1.5MHz 331*f7529f1dSMatthias Ringwald CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source 332*f7529f1dSMatthias Ringwald CS->KEY = 0; 333*f7529f1dSMatthias Ringwald 334*f7529f1dSMatthias Ringwald // Set Flash Bank read buffering 335*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 336*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 337*f7529f1dSMatthias Ringwald 338*f7529f1dSMatthias Ringwald #elif (__SYSTEM_CLOCK == 3000000) // 3 MHz 339*f7529f1dSMatthias Ringwald // Default VCORE is LDO VCORE0 so no change necessary 340*f7529f1dSMatthias Ringwald 341*f7529f1dSMatthias Ringwald // Switches LDO VCORE0 to DCDC VCORE0 if requested 342*f7529f1dSMatthias Ringwald #if __REGULATOR 343*f7529f1dSMatthias Ringwald while(PCM->CTL1 & PCM_CTL1_PMR_BUSY); 344*f7529f1dSMatthias Ringwald PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4; 345*f7529f1dSMatthias Ringwald while(PCM->CTL1 & PCM_CTL1_PMR_BUSY); 346*f7529f1dSMatthias Ringwald #endif 347*f7529f1dSMatthias Ringwald 348*f7529f1dSMatthias Ringwald // No flash wait states necessary 349*f7529f1dSMatthias Ringwald 350*f7529f1dSMatthias Ringwald // DCO = 3 MHz; MCLK = source 351*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; // Unlock CS module for register access 352*f7529f1dSMatthias Ringwald CS->CTL0 = CS_CTL0_DCORSEL_1; // Set DCO to 1.5MHz 353*f7529f1dSMatthias Ringwald CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source 354*f7529f1dSMatthias Ringwald CS->KEY = 0; 355*f7529f1dSMatthias Ringwald 356*f7529f1dSMatthias Ringwald // Set Flash Bank read buffering 357*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 358*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 359*f7529f1dSMatthias Ringwald 360*f7529f1dSMatthias Ringwald #elif (__SYSTEM_CLOCK == 12000000) // 12 MHz 361*f7529f1dSMatthias Ringwald // Default VCORE is LDO VCORE0 so no change necessary 362*f7529f1dSMatthias Ringwald 363*f7529f1dSMatthias Ringwald // Switches LDO VCORE0 to DCDC VCORE0 if requested 364*f7529f1dSMatthias Ringwald #if __REGULATOR 365*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 366*f7529f1dSMatthias Ringwald PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4; 367*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 368*f7529f1dSMatthias Ringwald #endif 369*f7529f1dSMatthias Ringwald 370*f7529f1dSMatthias Ringwald // No flash wait states necessary 371*f7529f1dSMatthias Ringwald 372*f7529f1dSMatthias Ringwald // DCO = 12 MHz; MCLK = source 373*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; // Unlock CS module for register access 374*f7529f1dSMatthias Ringwald CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz 375*f7529f1dSMatthias Ringwald CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source 376*f7529f1dSMatthias Ringwald CS->KEY = 0; 377*f7529f1dSMatthias Ringwald 378*f7529f1dSMatthias Ringwald // Set Flash Bank read buffering 379*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 380*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 381*f7529f1dSMatthias Ringwald 382*f7529f1dSMatthias Ringwald #elif (__SYSTEM_CLOCK == 24000000) // 24 MHz 383*f7529f1dSMatthias Ringwald // Default VCORE is LDO VCORE0 so no change necessary 384*f7529f1dSMatthias Ringwald 385*f7529f1dSMatthias Ringwald // Switches LDO VCORE0 to DCDC VCORE0 if requested 386*f7529f1dSMatthias Ringwald #if __REGULATOR 387*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 388*f7529f1dSMatthias Ringwald PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4; 389*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 390*f7529f1dSMatthias Ringwald #endif 391*f7529f1dSMatthias Ringwald 392*f7529f1dSMatthias Ringwald // 1 flash wait state (BANK0 VCORE0 max is 12 MHz) 393*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_1; 394*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_1; 395*f7529f1dSMatthias Ringwald 396*f7529f1dSMatthias Ringwald // DCO = 24 MHz; MCLK = source 397*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; // Unlock CS module for register access 398*f7529f1dSMatthias Ringwald CS->CTL0 = CS_CTL0_DCORSEL_4; // Set DCO to 24MHz 399*f7529f1dSMatthias Ringwald CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source 400*f7529f1dSMatthias Ringwald CS->KEY = 0; 401*f7529f1dSMatthias Ringwald 402*f7529f1dSMatthias Ringwald // Set Flash Bank read buffering 403*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL |= (FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 404*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 405*f7529f1dSMatthias Ringwald 406*f7529f1dSMatthias Ringwald #elif (__SYSTEM_CLOCK == 48000000) // 48 MHz 407*f7529f1dSMatthias Ringwald // Switches LDO VCORE0 to LDO VCORE1; mandatory for 48 MHz setting 408*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 409*f7529f1dSMatthias Ringwald PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_1; 410*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 411*f7529f1dSMatthias Ringwald 412*f7529f1dSMatthias Ringwald // Switches LDO VCORE1 to DCDC VCORE1 if requested 413*f7529f1dSMatthias Ringwald #if __REGULATOR 414*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 415*f7529f1dSMatthias Ringwald PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_5; 416*f7529f1dSMatthias Ringwald while((PCM->CTL1 & PCM_CTL1_PMR_BUSY)); 417*f7529f1dSMatthias Ringwald #endif 418*f7529f1dSMatthias Ringwald 419*f7529f1dSMatthias Ringwald // 2 flash wait states (BANK0 VCORE1 max is 16 MHz, BANK1 VCORE1 max is 32 MHz) 420*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_2; 421*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL &= ~FLCTL_BANK1_RDCTL_WAIT_MASK | FLCTL_BANK1_RDCTL_WAIT_2; 422*f7529f1dSMatthias Ringwald 423*f7529f1dSMatthias Ringwald // DCO = 48 MHz; MCLK = source 424*f7529f1dSMatthias Ringwald CS->KEY = CS_KEY_VAL; // Unlock CS module for register access 425*f7529f1dSMatthias Ringwald CS->CTL0 = CS_CTL0_DCORSEL_5; // Set DCO to 48MHz 426*f7529f1dSMatthias Ringwald CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source 427*f7529f1dSMatthias Ringwald CS->KEY = 0; 428*f7529f1dSMatthias Ringwald 429*f7529f1dSMatthias Ringwald // Set Flash Bank read buffering 430*f7529f1dSMatthias Ringwald FLCTL->BANK0_RDCTL |= (FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI); 431*f7529f1dSMatthias Ringwald FLCTL->BANK1_RDCTL |= (FLCTL_BANK1_RDCTL_BUFD | FLCTL_BANK1_RDCTL_BUFI); 432*f7529f1dSMatthias Ringwald #endif 433*f7529f1dSMatthias Ringwald 434*f7529f1dSMatthias Ringwald } 435