Skip to content

Commit e16394c

Browse files
Andreas TersteggeAndreas Terstegge
authored andcommitted
Final source code cleanup. Smaller changes in system_msp432p401r.c
1 parent 8853453 commit e16394c

File tree

10 files changed

+60
-92
lines changed

10 files changed

+60
-92
lines changed

targets/TARGET_TI/TARGET_MSP432/PeripheralNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* to integers...
3030
*/
3131

32-
#define DEVICE_SPI_COUNT 4
32+
#define DEVICE_SPI_COUNT 8
3333

3434
typedef uint32_t ADCName;
3535
typedef uint32_t UARTName;

targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/TOOLCHAIN_ARM_STD/msp432p401r.sct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#! armcc -E
22

3+
/**********************************************************
4+
* ARM CC linker script for Texas Instruments MSP432P401R
5+
**********************************************************/
6+
37
/* Device specific values */
48

59
#define ROM_START 0x00000000

targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/TOOLCHAIN_IAR/msp432p401r.icf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/******************************************************
2+
* IAR linker script for Texas Instruments MSP432P401R
3+
******************************************************/
4+
15
/* Device specific values */
26

37
define symbol ROM_START = 0x00000000;

targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/startup_msp432p401r.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ void (* const interruptVectors[])(void) __attribute__((section(".isr_vector")))
228228
void Reset_Handler(void)
229229
{
230230
// Halt the WDT already here, because the following copy process
231-
// from flash to SRAM might take so long that the WDT kicks in
231+
// from flash to SRAM (in case of GCC) might take so long that the
232+
// WDT kicks in
232233
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;
233234
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
234235
// Call system initialization routine

targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/system_msp432p401r.c

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@
2929
#define __REFOCLK_H 128000
3030
#define __SYSCLK 5000000
3131

32-
// We currently do not support a DCO frequency of 1.5MHz, because the SMCLK
33-
// should be at least at 3MHz because of the uTicker, which needs 1MHz.
34-
// SMCLK is typically the half of MCLK. The longest PWM periods depend on
35-
// SMCLK: Timer A is only 16 bit and has a maximum pre-scaler of 64, so the
36-
// longest PWM period is:
37-
// With SMCLK = 3MHz, the maximum period is 1.39s.
38-
// With SMCLK = 24MHz, the maximum period is (only) 174.8ms
39-
32+
// Configuration items in targets.json
4033
#define DCO_1500kHz 0
4134
#define DCO_3MHz 1
4235
#define DCO_6MHz 2
@@ -101,7 +94,7 @@
10194
#elif (MBED_CONF_TARGET_MCLK_SELECT == REFO)
10295
#define __MASTER_CLOCK (__REFOCLK_L / MCLK_DIVIDER)
10396
#elif (MBED_CONF_TARGET_MCLK_SELECT == DCO)
104-
#define __MASTER_CLOCK ( (3000000 << (MBED_CONF_TARGET_DCO_RSEL-1)) / MCLK_DIVIDER)
97+
#define __MASTER_CLOCK ( (1500000 << MBED_CONF_TARGET_DCO_RSEL) / MCLK_DIVIDER)
10598
#elif (MBED_CONF_TARGET_MCLK_SELECT == MOD)
10699
#define __MASTER_CLOCK (__MODCLK / MCLK_DIVIDER)
107100
#elif (MBED_CONF_TARGET_MCLK_SELECT == HFXT)
@@ -118,7 +111,7 @@
118111
#elif (MBED_CONF_TARGET_MCLK_SELECT == REFO)
119112
#define __SUBSYS_CLOCK (__REFOCLK_L / SMCLK_DIVIDER)
120113
#elif (MBED_CONF_TARGET_MCLK_SELECT == DCO)
121-
#define __SUBSYS_CLOCK ( (3000000 << (MBED_CONF_TARGET_DCO_RSEL-1)) / SMCLK_DIVIDER)
114+
#define __SUBSYS_CLOCK ((1500000 << MBED_CONF_TARGET_DCO_RSEL) / SMCLK_DIVIDER)
122115
#elif (MBED_CONF_TARGET_MCLK_SELECT == MOD)
123116
#define __SUBSYS_CLOCK (__MODCLK / SMCLK_DIVIDER)
124117
#elif (MBED_CONF_TARGET_MCLK_SELECT == HFXT)
@@ -127,10 +120,16 @@
127120
#error No SMCLK source defined (MBED_CONF_TARGET_SMCLK_SELECT)
128121
#endif
129122

130-
// global clock variables
123+
// Global clock variables
131124
uint32_t SystemCoreClock = __MASTER_CLOCK; // the value of MCLK in Hz
132125
uint32_t SubsystemMasterClock = __SUBSYS_CLOCK; // the value of SMCLK in Hz
133126

127+
// Global xtal frequencies. If the xtal oscillators are enabled
128+
// during run-time, the frequencies have to be set here so that
129+
// SystemCoreClockUpdate can use them.
130+
uint32_t HfxtFrequency = 0;
131+
uint32_t LfxtFrequency = 0;
132+
134133
//
135134
// Initialize the system
136135
//
@@ -144,7 +143,8 @@ uint32_t SubsystemMasterClock = __SUBSYS_CLOCK; // the value of SMCLK in Hz
144143
// 2. Enables all SRAM banks
145144
// 3. Sets up power regulator and VCORE
146145
// 4. Enable Flash wait states if needed and read buffering
147-
// 5. Change MCLK/SMCLK to desired frequency
146+
// 5. Enable HFXT and/or LFXT if needed
147+
// 6. Configure the Clock System (CS)
148148
//
149149
void SystemInit(void)
150150
{
@@ -153,9 +153,6 @@ void SystemInit(void)
153153
// Enable all SRAM banks
154154
SYSCTL->SRAM_BANKEN = SYSCTL_SRAM_BANKEN_BNK7_EN;
155155

156-
// Unlock CS module
157-
CS->KEY = CS_KEY_VAL;
158-
159156
#if (__MASTER_CLOCK >= 48000000)
160157
// Switches to DCDC VCORE1
161158
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
@@ -164,21 +161,26 @@ void SystemInit(void)
164161
// 1 flash wait states (BANK0 VCORE1 max is 16 MHz,
165162
// BANK1 VCORE1 max is 32 MHz)
166163
FLCTL->BANK0_RDCTL = FLCTL_BANK0_RDCTL_WAIT_1 | FLCTL_BANK0_RDCTL_BUFD
167-
| FLCTL_BANK0_RDCTL_BUFI;
164+
| FLCTL_BANK0_RDCTL_BUFI;
168165
FLCTL->BANK1_RDCTL = FLCTL_BANK1_RDCTL_WAIT_1 | FLCTL_BANK1_RDCTL_BUFD
169-
| FLCTL_BANK1_RDCTL_BUFI;
166+
| FLCTL_BANK1_RDCTL_BUFI;
170167
#elif (__MASTER_CLOCK >= 24000000)
171168
// Switches to DCDC VCORE0
172169
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
173170
PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR__AM_DCDC_VCORE0;
174171
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
175172
// Enable read buffering and 1 flash wait state (BANK0 VCORE0 max is 12 MHz)
176173
FLCTL->BANK0_RDCTL = FLCTL_BANK0_RDCTL_WAIT_1 | FLCTL_BANK0_RDCTL_BUFD
177-
| FLCTL_BANK0_RDCTL_BUFI;
174+
| FLCTL_BANK0_RDCTL_BUFI;
178175
#endif
179176

180-
#if ((MBED_CONF_TARGET_MCLK_SELECT == HFXT) || (MBED_CONF_TARGET_SMCLK_SELECT == HFXT))
181-
// initialize PJ.2 and PJ.3 for HFXT
177+
// Unlock CS module
178+
CS->KEY = CS_KEY_VAL;
179+
180+
#ifdef MBED_CONF_TARGET_HFXT_HZ
181+
HfxtFrequency = MBED_CONF_TARGET_HFXT_HZ;
182+
// Enable the HFXT crystal oscillator.
183+
// Initialize PJ for HFXT
182184
PJ->SEL0 |= BIT3;
183185
PJ->SEL1 &= ~BIT3;
184186
CS->CTL2 |= CS_CTL2_HFXT_EN | HFXT_FREQ;
@@ -188,20 +190,12 @@ void SystemInit(void)
188190
}
189191
#endif
190192

191-
// Set CTL0 and CTL1
192-
CS->CTL0 =(MBED_CONF_TARGET_DCO_RSEL << CS_CTL0_DCORSEL_OFS) |
193-
(MBED_CONF_TARGET_DCO_TUNE & 0x3ff);
194-
CS->CTL1 = MBED_CONF_TARGET_MCLK_SELECT << CS_CTL1_SELM_OFS |
195-
MBED_CONF_TARGET_MCLK_DIV << CS_CTL1_DIVM_OFS |
196-
MBED_CONF_TARGET_SMCLK_SELECT << CS_CTL1_SELS_OFS |
197-
MBED_CONF_TARGET_SMCLK_DIV << CS_CTL1_DIVS_OFS;
198-
199193
#ifdef MBED_CONF_TARGET_LFXT_HZ
200-
// Configure the 32768Hz source. If the LFXT is not
194+
LfxtFrequency = MBED_CONF_TARGET_LFXT_HZ;
195+
// Enable the LFXT crystal oscillator. If the LFXT is not
201196
// available, the system will switch automatically to
202-
// REFOCLK with 32768Hz mode (less precision...)
203-
204-
// initialize PJ.0 and PJ.1 for LFXT
197+
// REFOCLK with 32768Hz mode (less precision...).
198+
// Initialize PJ for LFXT
205199
PJ->SEL0 |= BIT0;
206200
PJ->SEL1 &= ~BIT0;
207201
// Enable LFXT
@@ -212,9 +206,18 @@ void SystemInit(void)
212206
}
213207
#endif
214208

209+
// Set CTL0 and CTL1
210+
CS->CTL0 =(MBED_CONF_TARGET_DCO_RSEL << CS_CTL0_DCORSEL_OFS) |
211+
(MBED_CONF_TARGET_DCO_TUNE & 0x3ff);
212+
CS->CTL1 = MBED_CONF_TARGET_MCLK_SELECT << CS_CTL1_SELM_OFS |
213+
MBED_CONF_TARGET_MCLK_DIV << CS_CTL1_DIVM_OFS |
214+
MBED_CONF_TARGET_SMCLK_SELECT << CS_CTL1_SELS_OFS |
215+
MBED_CONF_TARGET_SMCLK_DIV << CS_CTL1_DIVS_OFS;
216+
215217
// Lock CS module
216218
CS->KEY = 0;
217-
// Update the global clock values
219+
220+
// Update the global clock values.
218221
SystemCoreClockUpdate();
219222
}
220223

@@ -247,9 +250,7 @@ void SystemCoreClockUpdate(void)
247250
// always switch to REFOCLK with 32768Hz
248251
SystemCoreClock = __REFOCLK_L;
249252
} else {
250-
#ifdef MBED_CONF_TARGET_LFXT_HZ
251-
SystemCoreClock = MBED_CONF_TARGET_LFXT_HZ;
252-
#endif
253+
SystemCoreClock = LfxtFrequency;
253254
}
254255
break;
255256
}
@@ -335,9 +336,7 @@ void SystemCoreClockUpdate(void)
335336
// switch over to SYSOSC...
336337
SystemCoreClock = __SYSCLK;
337338
} else {
338-
#ifdef MBED_CONF_TARGET_HFXT_HZ
339-
SystemCoreClock = MBED_CONF_TARGET_HFXT_HZ;
340-
#endif
339+
SystemCoreClock = HfxtFrequency;
341340
}
342341
break;
343342
}
@@ -357,9 +356,7 @@ void SystemCoreClockUpdate(void)
357356
// always switch to REFOCLK with 32768Hz
358357
SubsystemMasterClock = __REFOCLK_L;
359358
} else {
360-
#ifdef MBED_CONF_TARGET_LFXT_HZ
361-
SubsystemMasterClock = MBED_CONF_TARGET_LFXT_HZ;
362-
#endif
359+
SubsystemMasterClock = LfxtFrequency;
363360
}
364361
break;
365362
}
@@ -445,9 +442,7 @@ void SystemCoreClockUpdate(void)
445442
// switch over to SYSOSC...
446443
SubsystemMasterClock = __SYSCLK;
447444
} else {
448-
#ifdef MBED_CONF_TARGET_HFXT_HZ
449-
SubsystemMasterClock = MBED_CONF_TARGET_HFXT_HZ;
450-
#endif
445+
SubsystemMasterClock = HfxtFrequency;
451446
}
452447
break;
453448
}

targets/TARGET_TI/TARGET_MSP432/device/cmsis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#undef DIR_H
2222

2323
#include "msp.h"
24-
#include "cmsis_nvic.h"
2524

2625
#undef CS
2726

targets/TARGET_TI/TARGET_MSP432/device/cmsis_nvic.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

targets/TARGET_TI/TARGET_MSP432/i2c_api.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
/* Low-level implementation of I2C functionality for MSP432 */
18+
/* Low-level implementation of I2C functionality for MSP432.
19+
* This implementation does also support DEVICE_I2CSLAVE and DEVICE_I2C_ASYNCH.
20+
*/
21+
1922

2023
#if DEVICE_I2C
2124

targets/TARGET_TI/TARGET_MSP432/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct spi_s {
8080
PinName pin_mosi;
8181
PinName pin_sclk;
8282
PinName pin_ssel;
83-
// Addresses of needed HW-registers
83+
// Addresses of HW-registers
8484
__IO uint16_t *EUSCI_CTLW0;
8585
__IO uint16_t *EUSCI_BRW;
8686
__IO uint16_t *EUSCI_STATW;

targets/TARGET_TI/TARGET_MSP432/spi_api.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18+
/* Low-level implementation of SPI functionality for MSP432.
19+
* This implementation does also support DEVICE_SPISLAVE and DEVICE_SPI_ASYNCH.
20+
*/
21+
1822
#include "spi_api.h"
1923
#include "mbed_assert.h"
2024

2125
#if DEVICE_SPI
2226

23-
//#define SPI_EVENT_ERROR (1 << 1)
24-
//#define SPI_EVENT_COMPLETE (1 << 2)
25-
//#define SPI_EVENT_RX_OVERFLOW (1 << 3)
26-
//#define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW)
27-
//
28-
//#define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred
29-
//
30-
//#define SPI_FILL_WORD (0xFFFF)
31-
//#define SPI_FILL_CHAR (0xFF)
32-
33-
3427
/* With SPI_ASYNCH, our type spi_s is embedded
3528
* into a bigger structure (see spi_api.h). So we
3629
* need a macro to extract the spi_s object.

0 commit comments

Comments
 (0)