summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorja Martinez2016-09-10 10:23:54 -0500
committerBorja Martinez2016-09-10 10:23:54 -0500
commita99955e7fde336f52fd81b00eb4e998768c5aaf5 (patch)
tree8f06abcd2045550a4ca08a7f09b8c0120c344b47
parentd3b6449727b9a0dccfce53754bfcfd5e8ee24e6c (diff)
downloadi3-mote-a99955e7fde336f52fd81b00eb4e998768c5aaf5.tar.gz
i3-mote-a99955e7fde336f52fd81b00eb4e998768c5aaf5.tar.xz
i3-mote-a99955e7fde336f52fd81b00eb4e998768c5aaf5.zip
Created Test MSP432 Clock System
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h15
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/main.c124
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/msp432p401r.cmd84
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/startup_msp432p401r_ccs.c254
-rw-r--r--Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/system_msp432p401r.c434
5 files changed, 911 insertions, 0 deletions
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h
new file mode 100644
index 0000000..fc06eaa
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/i3mote.h
@@ -0,0 +1,15 @@
1
2
3/* Rev.B */
4#define HID_PORT GPIO_PORT_P6
5#define LEDR GPIO_PIN2
6#define LEDG GPIO_PIN3
7#define BUTTON GPIO_PIN1
8
9
10/* Rev.A
11#define LED_PORT GPIO_PORT_P8
12#define LEDR GPIO_PIN5
13#define LEDG GPIO_PIN6
14#define BUTTON GPIO_PIN7
15*/
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/main.c b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/main.c
new file mode 100644
index 0000000..3ba4325
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/main.c
@@ -0,0 +1,124 @@
1/*******************************************************************************
2 * MSP432 Clock System - HFXT Startup
3 *
4 * Description:
5 *
6 * HFXTAL:
7 * Starts the 48MHz crystal attached to HFXTIN/HFXTOUT
8 * Sources MCLK from the crystal
9 *
10 * LFXTL:
11 * Starts the 32khz crystal attached to LFXTIN/LFXTOUT
12 * Sources AMCLK from crystal
13 *
14 * Internal DCO:
15 * Starts the DCO
16 * Sources SMCLK from DCO
17 *
18 * Blinks an LED using SysTick (which is sourced from MCLK).
19 *
20 *
21 *
22 * MSP432P401
23 * ------------------
24 * /|\| |
25 * | | |
26 * --|RST P8.5 |---> LED
27 * | |
28 * | PJ.3 HFXTIN |<--------
29 * | | < 48Mhz xTal >
30 * | PJ.2 HFXTOUT |<--------
31 * | |
32 * | PJ.0 LFXIN |<--------
33 * | | < 32khz xTal >
34 * | PJ.1 LFXOUT |<--------
35 * | |
36 * | P4.2 |--> ACLK - 32.768 KHz
37 * | P4.3 |--> MCLK - 12.000 MHz
38 * | P4.4 |--> HSMCLK - 6.000 MHz
39 * | P7.0 |--> SMCLK
40 * | |
41 *
42 * Author: Timothy Logan
43 * Rev: B.Martinez
44 ******************************************************************************/
45#include "i3mote.h"
46
47/* DriverLib Includes */
48#include "driverlib.h"
49
50/* Standard Includes */
51#include <stdint.h>
52
53#include <stdbool.h>
54
55int main(void)
56{
57 /* Halting the Watchdog */
58 MAP_WDT_A_holdTimer();
59
60 /* Configuring pins for peripheral/crystal usage*/
61 /* LFXTAL */
62 MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
63 GPIO_PIN0 | GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION);
64
65 /* HFXTL */
66 MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
67 GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
68
69 /* Clocks Output */
70 GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4,
71 GPIO_PIN2|GPIO_PIN3|GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
72 GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7,
73 GPIO_PIN0, GPIO_PRIMARY_MODULE_FUNCTION);
74
75 /* LEDs */
76 MAP_GPIO_setAsOutputPin(HID_PORT,LEDG|LEDR);
77 MAP_GPIO_setOutputHighOnPin(HID_PORT, LEDG|LEDR);
78
79 /* Setting the external clock frequency. This API is optional */
80 CS_setExternalClockSourceFrequency(32000,12000000);
81
82 /* Starting HFXT in non-bypass mode without a timeout. Before we start
83 * we have to change VCORE to 1 to support the 48MHz frequency */
84 MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
85 MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
86 MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
87 CS_startHFXT(false);
88
89 /* Initializing MCLK to HFXT (effectively 48/4 MHz) */
90 MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_4);
91
92 /* Initializing ACLK to LFXT */
93 CS_startLFXT(false);
94 MAP_CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
95
96
97 /* Initializes Aux. Clocks System with DCO */
98 MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
99 MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
100 MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
101
102 /*
103 * Configuring SysTick to trigger at 6000000
104 * MCLK is 12MHz so this will make it toggle every 0.5s
105 * */
106
107 MAP_SysTick_enableModule();
108 MAP_SysTick_setPeriod(6000000);
109 MAP_Interrupt_enableSleepOnIsrExit();
110 MAP_SysTick_enableInterrupt();
111
112 /* Enabling MASTER interrupts */
113 MAP_Interrupt_enableMaster();
114
115 while (1)
116 {
117 MAP_PCM_gotoLPM0();
118 }
119}
120
121void SysTick_Handler(void)
122{
123 MAP_GPIO_toggleOutputOnPin(HID_PORT, LEDG|LEDR);
124}
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/msp432p401r.cmd b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/msp432p401r.cmd
new file mode 100644
index 0000000..346c191
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/msp432p401r.cmd
@@ -0,0 +1,84 @@
1/******************************************************************************
2*
3* Copyright (C) 2012 - 2015 Texas Instruments Incorporated - http://www.ti.com/
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions
7* are met:
8*
9* Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11*
12* Redistributions in binary form must reproduce the above copyright
13* notice, this list of conditions and the following disclaimer in the
14* documentation and/or other materials provided with the
15* distribution.
16*
17* Neither the name of Texas Instruments Incorporated nor the names of
18* its contributors may be used to endorse or promote products derived
19* from this software without specific prior written permission.
20*
21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*
33* Default linker command file for Texas Instruments MSP432P401R
34*
35* File creation date: 2015-09-03
36*
37*****************************************************************************/
38
39--retain=flashMailbox
40
41MEMORY
42{
43 MAIN (RX) : origin = 0x00000000, length = 0x00040000
44 INFO (RX) : origin = 0x00200000, length = 0x00004000
45 SRAM_CODE (RWX): origin = 0x01000000, length = 0x00010000
46 SRAM_DATA (RW) : origin = 0x20000000, length = 0x00010000
47}
48
49/* The following command line options are set as part of the CCS project. */
50/* If you are building using the command line, or for some reason want to */
51/* define them here, you can uncomment and modify these lines as needed. */
52/* If you are using CCS for building, it is probably better to make any such */
53/* modifications in your CCS project and leave this file alone. */
54/* */
55/* A heap size of 1024 bytes is recommended when you plan to use printf() */
56/* for debug output to the console window. */
57/* */
58/* --heap_size=1024 */
59/* --stack_size=512 */
60/* --library=rtsv7M4_T_le_eabi.lib */
61
62/* Section allocation in memory */
63
64SECTIONS
65{
66 .intvecs: > 0x00000000
67 .text : > MAIN
68 .const : > MAIN
69 .cinit : > MAIN
70 .pinit : > MAIN
71 .init_array : > MAIN
72
73 .flashMailbox : > 0x00200000
74
75 .vtable : > 0x20000000
76 .data : > SRAM_DATA
77 .bss : > SRAM_DATA
78 .sysmem : > SRAM_DATA
79 .stack : > SRAM_DATA (HIGH)
80}
81
82/* Symbolic definition of the WDTCTL register for RTS */
83WDTCTL_SYM = 0x4000480C;
84
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/startup_msp432p401r_ccs.c b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/startup_msp432p401r_ccs.c
new file mode 100644
index 0000000..d5f9a14
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/startup_msp432p401r_ccs.c
@@ -0,0 +1,254 @@
1/*
2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
5 *
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * --/COPYRIGHT--*/
37//*****************************************************************************
38//
39// Copyright (C) 2012 - 2015 Texas Instruments Incorporated - http://www.ti.com/
40//
41// Redistribution and use in source and binary forms, with or without
42// modification, are permitted provided that the following conditions
43// are met:
44//
45// Redistributions of source code must retain the above copyright
46// notice, this list of conditions and the following disclaimer.
47//
48// Redistributions in binary form must reproduce the above copyright
49// notice, this list of conditions and the following disclaimer in the
50// documentation and/or other materials provided with the
51// distribution.
52//
53// Neither the name of Texas Instruments Incorporated nor the names of
54// its contributors may be used to endorse or promote products derived
55// from this software without specific prior written permission.
56//
57// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
58// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
59// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
60// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
61// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
63// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
67// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68//
69// MSP432 Family Interrupt Vector Table for CGT
70//
71//****************************************************************************
72
73#include <stdint.h>
74
75/* Forward declaration of the default fault handlers. */
76static void resetISR(void);
77static void nmiISR(void);
78static void faultISR(void);
79static void defaultISR(void);
80
81
82/* External declaration for the reset handler that is to be called when the */
83/* processor is started */
84extern void _c_int00(void);
85
86/* External declaration for system initialization function */
87extern void SystemInit(void);
88
89/* Linker variable that marks the top of the stack. */
90extern unsigned long __STACK_END;
91
92
93/* External declarations for the interrupt handlers used by the application. */
94extern void SysTick_Handler(void);
95
96
97/* Interrupt vector table. Note that the proper constructs must be placed on this to */
98/* ensure that it ends up at physical address 0x0000.0000 or at the start of */
99/* the program if located at a start address other than 0. */
100#pragma RETAIN(interruptVectors)
101#pragma DATA_SECTION(interruptVectors, ".intvecs")
102void (* const interruptVectors[])(void) =
103{
104 (void (*)(void))((uint32_t)&__STACK_END),
105 /* The initial stack pointer */
106 resetISR, /* The reset handler */
107 nmiISR, /* The NMI handler */
108 faultISR, /* The hard fault handler */
109 defaultISR, /* The MPU fault handler */
110 defaultISR, /* The bus fault handler */
111 defaultISR, /* The usage fault handler */
112 0, /* Reserved */
113 0, /* Reserved */
114 0, /* Reserved */
115 0, /* Reserved */
116 defaultISR, /* SVCall handler */
117 defaultISR, /* Debug monitor handler */
118 0, /* Reserved */
119 defaultISR, /* The PendSV handler */
120 SysTick_Handler, /* The SysTick handler */
121 defaultISR, /* PSS ISR */
122 defaultISR, /* CS ISR */
123 defaultISR, /* PCM ISR */
124 defaultISR, /* WDT ISR */
125 defaultISR, /* FPU ISR */
126 defaultISR, /* FLCTL ISR */
127 defaultISR, /* COMP0 ISR */
128 defaultISR, /* COMP1 ISR */
129 defaultISR, /* TA0_0 ISR */
130 defaultISR, /* TA0_N ISR */
131 defaultISR, /* TA1_0 ISR */
132 defaultISR, /* TA1_N ISR */
133 defaultISR, /* TA2_0 ISR */
134 defaultISR, /* TA2_N ISR */
135 defaultISR, /* TA3_0 ISR */
136 defaultISR, /* TA3_N ISR */
137 defaultISR, /* EUSCIA0 ISR */
138 defaultISR, /* EUSCIA1 ISR */
139 defaultISR, /* EUSCIA2 ISR */
140 defaultISR, /* EUSCIA3 ISR */
141 defaultISR, /* EUSCIB0 ISR */
142 defaultISR, /* EUSCIB1 ISR */
143 defaultISR, /* EUSCIB2 ISR */
144 defaultISR, /* EUSCIB3 ISR */
145 defaultISR, /* ADC14 ISR */
146 defaultISR, /* T32_INT1 ISR */
147 defaultISR, /* T32_INT2 ISR */
148 defaultISR, /* T32_INTC ISR */
149 defaultISR, /* AES ISR */
150 defaultISR, /* RTC ISR */
151 defaultISR, /* DMA_ERR ISR */
152 defaultISR, /* DMA_INT3 ISR */
153 defaultISR, /* DMA_INT2 ISR */
154 defaultISR, /* DMA_INT1 ISR */
155 defaultISR, /* DMA_INT0 ISR */
156 defaultISR, /* PORT1 ISR */
157 defaultISR, /* PORT2 ISR */
158 defaultISR, /* PORT3 ISR */
159 defaultISR, /* PORT4 ISR */
160 defaultISR, /* PORT5 ISR */
161 defaultISR, /* PORT6 ISR */
162 defaultISR, /* Reserved 41 */
163 defaultISR, /* Reserved 42 */
164 defaultISR, /* Reserved 43 */
165 defaultISR, /* Reserved 44 */
166 defaultISR, /* Reserved 45 */
167 defaultISR, /* Reserved 46 */
168 defaultISR, /* Reserved 47 */
169 defaultISR, /* Reserved 48 */
170 defaultISR, /* Reserved 49 */
171 defaultISR, /* Reserved 50 */
172 defaultISR, /* Reserved 51 */
173 defaultISR, /* Reserved 52 */
174 defaultISR, /* Reserved 53 */
175 defaultISR, /* Reserved 54 */
176 defaultISR, /* Reserved 55 */
177 defaultISR, /* Reserved 56 */
178 defaultISR, /* Reserved 57 */
179 defaultISR, /* Reserved 58 */
180 defaultISR, /* Reserved 59 */
181 defaultISR, /* Reserved 60 */
182 defaultISR, /* Reserved 61 */
183 defaultISR, /* Reserved 62 */
184 defaultISR /* Reserved 63 */
185};
186
187
188/* This is the code that gets called when the processor first starts execution */
189/* following a reset event. Only the absolutely necessary set is performed, */
190/* after which the application supplied entry() routine is called. Any fancy */
191/* actions (such as making decisions based on the reset cause register, and */
192/* resetting the bits in that register) are left solely in the hands of the */
193/* application. */
194void resetISR(void)
195{
196 SystemInit();
197
198 /* Jump to the CCS C Initialization Routine. */
199 __asm(" .global _c_int00\n"
200 " b.w _c_int00");
201}
202
203/* This is the code that gets called when the processor receives a NMI. This */
204/* simply enters an infinite loop, preserving the system state for examination */
205/* by a debugger. */
206static void nmiISR(void)
207{
208 /* Fault trap exempt from ULP advisor */
209 #pragma diag_push
210 #pragma CHECK_ULP("-2.1")
211
212 /* Enter an infinite loop. */
213 while(1)
214 {
215 }
216
217 #pragma diag_pop
218}
219
220
221/* This is the code that gets called when the processor receives a fault */
222/* interrupt. This simply enters an infinite loop, preserving the system state */
223/* for examination by a debugger. */
224static void faultISR(void)
225{
226 /* Fault trap exempt from ULP advisor */
227 #pragma diag_push
228 #pragma CHECK_ULP("-2.1")
229
230 /* Enter an infinite loop. */
231 while(1)
232 {
233 }
234
235 #pragma diag_pop
236}
237
238
239/* This is the code that gets called when the processor receives an unexpected */
240/* interrupt. This simply enters an infinite loop, preserving the system state */
241/* for examination by a debugger. */
242static void defaultISR(void)
243{
244 /* Fault trap exempt from ULP advisor */
245 #pragma diag_push
246 #pragma CHECK_ULP("-2.1")
247
248 /* Enter an infinite loop. */
249 while(1)
250 {
251 }
252
253 #pragma diag_pop
254}
diff --git a/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/system_msp432p401r.c b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/system_msp432p401r.c
new file mode 100644
index 0000000..3cd0694
--- /dev/null
+++ b/Basic-Test-Package/MSP432/Test_MSP432_ClockSystem/system_msp432p401r.c
@@ -0,0 +1,434 @@
1/*
2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
5 *
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * --/COPYRIGHT--*/
37/**************************************************************************//**
38* @file system_msp432p401r.c
39* @brief CMSIS Cortex-M4F Device Peripheral Access Layer Source File for
40* MSP432P401R
41* @version V1.00
42* @date 20-Oct-2015
43*
44* @note View configuration instructions embedded in comments
45*
46******************************************************************************/
47//*****************************************************************************
48//
49// Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
50//
51// Redistribution and use in source and binary forms, with or without
52// modification, are permitted provided that the following conditions
53// are met:
54//
55// Redistributions of source code must retain the above copyright
56// notice, this list of conditions and the following disclaimer.
57//
58// Redistributions in binary form must reproduce the above copyright
59// notice, this list of conditions and the following disclaimer in the
60// documentation and/or other materials provided with the
61// distribution.
62//
63// Neither the name of Texas Instruments Incorporated nor the names of
64// its contributors may be used to endorse or promote products derived
65// from this software without specific prior written permission.
66//
67// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
68// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
69// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
70// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
71// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
72// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
73// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
77// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78//
79//*****************************************************************************
80
81#include <stdint.h>
82#include "msp.h"
83
84/*--------------------- Configuration Instructions ----------------------------
85 1. If you prefer to halt the Watchdog Timer, set __HALT_WDT to 1:
86 #define __HALT_WDT 1
87 2. Insert your desired CPU frequency in Hz at:
88 #define __SYSTEM_CLOCK 3000000
89 3. If you prefer the DC-DC power regulator (more efficient at higher
90 frequencies), set the __REGULATOR to 1:
91 #define __REGULATOR 1
92 *---------------------------------------------------------------------------*/
93
94/*--------------------- Watchdog Timer Configuration ------------------------*/
95// Halt the Watchdog Timer
96// <0> Do not halt the WDT
97// <1> Halt the WDT
98#define __HALT_WDT 1
99
100/*--------------------- CPU Frequency Configuration -------------------------*/
101// CPU Frequency
102// <1500000> 1.5 MHz
103// <3000000> 3 MHz
104// <12000000> 12 MHz
105// <24000000> 24 MHz
106// <48000000> 48 MHz
107#define __SYSTEM_CLOCK 12000000
108
109/*--------------------- Power Regulator Configuration -----------------------*/
110// Power Regulator Mode
111// <0> LDO
112// <1> DC-DC
113#define __REGULATOR 1
114
115/*----------------------------------------------------------------------------
116 Define clocks, used for SystemCoreClockUpdate()
117 *---------------------------------------------------------------------------*/
118#define __VLOCLK 10000
119#define __MODCLK 24000000
120#define __LFXT 32768
121#define __HFXT 48000000
122
123/*----------------------------------------------------------------------------
124 Clock Variable definitions
125 *---------------------------------------------------------------------------*/
126uint32_t SystemCoreClock = __SYSTEM_CLOCK; /*!< System Clock Frequency (Core Clock)*/
127
128/**
129 * Update SystemCoreClock variable
130 *
131 * @param none
132 * @return none
133 *
134 * @brief Updates the SystemCoreClock with current core Clock
135 * retrieved from cpu registers.
136 */
137void SystemCoreClockUpdate(void)
138{
139 uint32_t source, divider;
140 uint8_t dividerValue;
141
142 float dcoConst;
143 int32_t calVal;
144 uint32_t centeredFreq;
145 int16_t dcoTune;
146
147 divider = (CS->CTL1 & CS_CTL1_DIVM_MASK) >> CS_CTL1_DIVM_OFS;
148 dividerValue = 1 << divider;
149 source = CS->CTL1 & CS_CTL1_SELM_MASK;
150
151 switch(source)
152 {
153 case CS_CTL1_SELM__LFXTCLK:
154 if(BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS))
155 {
156 // Clear interrupt flag
157 CS->KEY = CS_KEY_VAL;
158 CS->CLRIFG |= CS_CLRIFG_CLR_LFXTIFG;
159 CS->KEY = 1;
160
161 if(BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS))
162 {
163 if(BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS))
164 {
165 SystemCoreClock = (128000 / dividerValue);
166 }
167 else
168 {
169 SystemCoreClock = (32000 / dividerValue);
170 }
171 }
172 else
173 {
174 SystemCoreClock = __LFXT / dividerValue;
175 }
176 }
177 else
178 {
179 SystemCoreClock = __LFXT / dividerValue;
180 }
181 break;
182 case CS_CTL1_SELM__VLOCLK:
183 SystemCoreClock = __VLOCLK / dividerValue;
184 break;
185 case CS_CTL1_SELM__REFOCLK:
186 if (BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS))
187 {
188 SystemCoreClock = (128000 / dividerValue);
189 }
190 else
191 {
192 SystemCoreClock = (32000 / dividerValue);
193 }
194 break;
195 case CS_CTL1_SELM__DCOCLK:
196 dcoTune = (CS->CTL0 & CS_CTL0_DCOTUNE_MASK) >> CS_CTL0_DCOTUNE_OFS;
197
198 switch(CS->CTL0 & CS_CTL0_DCORSEL_MASK)
199 {
200 case CS_CTL0_DCORSEL_0:
201 centeredFreq = 1500000;
202 break;
203 case CS_CTL0_DCORSEL_1:
204 centeredFreq = 3000000;
205 break;
206 case CS_CTL0_DCORSEL_2:
207 centeredFreq = 6000000;
208 break;
209 case CS_CTL0_DCORSEL_3:
210 centeredFreq = 12000000;
211 break;
212 case CS_CTL0_DCORSEL_4:
213 centeredFreq = 24000000;
214 break;
215 case CS_CTL0_DCORSEL_5:
216 centeredFreq = 48000000;
217 break;
218 }
219
220 if(dcoTune == 0)
221 {
222 SystemCoreClock = centeredFreq;
223 }
224 else
225 {
226
227 if(dcoTune & 0x1000)
228 {
229 dcoTune = dcoTune | 0xF000;
230 }
231
232 if (BITBAND_PERI(CS->CTL0, CS_CTL0_DCORES_OFS))
233 {
234 dcoConst = *((float *) &TLV->DCOER_CONSTK_RSEL04);
235 calVal = TLV->DCOER_FCAL_RSEL04;
236 }
237 /* Internal Resistor */
238 else
239 {
240 dcoConst = *((float *) &TLV->DCOIR_CONSTK_RSEL04);
241 calVal = TLV->DCOIR_FCAL_RSEL04;
242 }
243
244 SystemCoreClock = (uint32_t) ((centeredFreq)
245 / (1
246 - ((dcoConst * dcoTune)
247 / (8 * (1 + dcoConst * (768 - calVal))))));
248 }
249 break;
250 case CS_CTL1_SELM__MODOSC:
251 SystemCoreClock = __MODCLK / dividerValue;
252 break;
253 case CS_CTL1_SELM__HFXTCLK:
254 if(BITBAND_PERI(CS->IFG, CS_IFG_HFXTIFG_OFS))
255 {
256 // Clear interrupt flag
257 CS->KEY = CS_KEY_VAL;
258 CS->CLRIFG |= CS_CLRIFG_CLR_HFXTIFG;
259 CS->KEY = 1;
260
261 if(BITBAND_PERI(CS->IFG, CS_IFG_HFXTIFG_OFS))
262 {
263 if(BITBAND_PERI(CS->CLKEN, CS_CLKEN_REFOFSEL_OFS))
264 {
265 SystemCoreClock = (128000 / dividerValue);
266 }
267 else
268 {
269 SystemCoreClock = (32000 / dividerValue);
270 }
271 }
272 else
273 {
274 SystemCoreClock = __HFXT / dividerValue;
275 }
276 }
277 else
278 {
279 SystemCoreClock = __HFXT / dividerValue;
280 }
281 break;
282 }
283}
284
285/**
286 * Initialize the system
287 *
288 * @param none
289 * @return none
290 *
291 * @brief Setup the microcontroller system.
292 *
293 * Performs the following initialization steps:
294 * 1. Enables the FPU
295 * 2. Halts the WDT if requested
296 * 3. Enables all SRAM banks
297 * 4. Sets up power regulator and VCORE
298 * 5. Enable Flash wait states if needed
299 * 6. Change MCLK to desired frequency
300 * 7. Enable Flash read buffering
301 */
302void SystemInit(void)
303{
304 // Enable FPU if used
305 #if (__FPU_USED == 1) /* __FPU_USED is defined in core_cm4.h */
306 SCB->CPACR |= ((3UL << 10 * 2) | /* Set CP10 Full Access */
307 (3UL << 11 * 2)); /* Set CP11 Full Access */
308 #endif
309
310 #if (__HALT_WDT == 1)
311 WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // Halt the WDT
312 #endif
313
314 SYSCTL->SRAM_BANKEN = SYSCTL_SRAM_BANKEN_BNK7_EN; // Enable all SRAM banks
315
316 #if (__SYSTEM_CLOCK == 1500000) // 1.5 MHz
317 // Default VCORE is LDO VCORE0 so no change necessary
318
319 // Switches LDO VCORE0 to DCDC VCORE0 if requested
320 #if __REGULATOR
321 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
322 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
323 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
324 #endif
325
326 // No flash wait states necessary
327
328 // DCO = 1.5 MHz; MCLK = source
329 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
330 CS->CTL0 = CS_CTL0_DCORSEL_0; // Set DCO to 1.5MHz
331 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
332 CS->KEY = 0;
333
334 // Set Flash Bank read buffering
335 FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
336 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
337
338 #elif (__SYSTEM_CLOCK == 3000000) // 3 MHz
339 // Default VCORE is LDO VCORE0 so no change necessary
340
341 // Switches LDO VCORE0 to DCDC VCORE0 if requested
342 #if __REGULATOR
343 while(PCM->CTL1 & PCM_CTL1_PMR_BUSY);
344 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
345 while(PCM->CTL1 & PCM_CTL1_PMR_BUSY);
346 #endif
347
348 // No flash wait states necessary
349
350 // DCO = 3 MHz; MCLK = source
351 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
352 CS->CTL0 = CS_CTL0_DCORSEL_1; // Set DCO to 1.5MHz
353 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
354 CS->KEY = 0;
355
356 // Set Flash Bank read buffering
357 FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
358 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
359
360 #elif (__SYSTEM_CLOCK == 12000000) // 12 MHz
361 // Default VCORE is LDO VCORE0 so no change necessary
362
363 // Switches LDO VCORE0 to DCDC VCORE0 if requested
364 #if __REGULATOR
365 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
366 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
367 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
368 #endif
369
370 // No flash wait states necessary
371
372 // DCO = 12 MHz; MCLK = source
373 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
374 CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz
375 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
376 CS->KEY = 0;
377
378 // Set Flash Bank read buffering
379 FLCTL->BANK0_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
380 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
381
382 #elif (__SYSTEM_CLOCK == 24000000) // 24 MHz
383 // Default VCORE is LDO VCORE0 so no change necessary
384
385 // Switches LDO VCORE0 to DCDC VCORE0 if requested
386 #if __REGULATOR
387 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
388 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_4;
389 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
390 #endif
391
392 // 1 flash wait state (BANK0 VCORE0 max is 12 MHz)
393 FLCTL->BANK0_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_1;
394 FLCTL->BANK1_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_1;
395
396 // DCO = 24 MHz; MCLK = source
397 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
398 CS->CTL0 = CS_CTL0_DCORSEL_4; // Set DCO to 24MHz
399 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
400 CS->KEY = 0;
401
402 // Set Flash Bank read buffering
403 FLCTL->BANK0_RDCTL |= (FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
404 FLCTL->BANK1_RDCTL &= ~(FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
405
406 #elif (__SYSTEM_CLOCK == 48000000) // 48 MHz
407 // Switches LDO VCORE0 to LDO VCORE1; mandatory for 48 MHz setting
408 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
409 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_1;
410 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
411
412 // Switches LDO VCORE1 to DCDC VCORE1 if requested
413 #if __REGULATOR
414 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
415 PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_5;
416 while((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
417 #endif
418
419 // 2 flash wait states (BANK0 VCORE1 max is 16 MHz, BANK1 VCORE1 max is 32 MHz)
420 FLCTL->BANK0_RDCTL &= ~FLCTL_BANK0_RDCTL_WAIT_MASK | FLCTL_BANK0_RDCTL_WAIT_2;
421 FLCTL->BANK1_RDCTL &= ~FLCTL_BANK1_RDCTL_WAIT_MASK | FLCTL_BANK1_RDCTL_WAIT_2;
422
423 // DCO = 48 MHz; MCLK = source
424 CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
425 CS->CTL0 = CS_CTL0_DCORSEL_5; // Set DCO to 48MHz
426 CS->CTL1 &= ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM__DCOCLK; // Select MCLK as DCO source
427 CS->KEY = 0;
428
429 // Set Flash Bank read buffering
430 FLCTL->BANK0_RDCTL |= (FLCTL_BANK0_RDCTL_BUFD | FLCTL_BANK0_RDCTL_BUFI);
431 FLCTL->BANK1_RDCTL |= (FLCTL_BANK1_RDCTL_BUFD | FLCTL_BANK1_RDCTL_BUFI);
432 #endif
433
434}