When CCS 6.1.0.00104 used used to create a project for a MSP432P401R device using the GCC v4.8.4 compiler, when main was reached global variables in the data segment had not been initialized. The msp432_startup_ccs_gcc.c file which was added by CCS at project creation contains the following resetISR function:
void resetISR(void)
{
/* Copy the data segment initializers from flash to SRAM. */
/* Zero fill the bss segment. */
__asm(" ldr r0, =__bss_start__\n"
" ldr r1, =__bss_end__\n"
" mov r2, #0\n"
" .thumb_func\n"
"zero_loop:\n"
" cmp r0, r1\n"
" it lt\n"
" strlt r2, [r0], #4\n"
" blt zero_loop");
/* Call the application's entry point. */
main();
}
i.e. the code which should copy the the data segment initializers from flash to SRAM is missing.
Based upon startup_css_gcc.c for Tiva devices, the msp432_startup_ccs_gcc.c needs the following to copy the data segment initializers from flash to SRAM:
//*****************************************************************************
//
// The following are constructs created by the linker, indicating where the
// the "data" and "bss" segments reside in memory. The initializers for the
// for the "data" segment resides immediately following the "text" segment.
//
//*****************************************************************************
extern uint32_t __data_load__;
extern uint32_t __data_start__;
extern uint32_t __data_end__;
extern uint32_t __bss_start__;
extern uint32_t __bss_end__;
/* This is the code that gets called when the processor first starts execution */
/* following a reset event. Only the absolutely necessary set is performed, */
/* after which the application supplied entry() routine is called. Any fancy */
/* actions (such as making decisions based on the reset cause register, and */
/* resetting the bits in that register) are left solely in the hands of the */
/* application. */
void resetISR(void)
{
uint32_t *pui32Src, *pui32Dest;
//
// Copy the data segment initializers from flash to SRAM.
//
pui32Src = &__data_load__;
for(pui32Dest = &__data_start__; pui32Dest < &__data_end__; )
{
*pui32Dest++ = *pui32Src++;
}
/* Zero fill the bss segment. */
__asm(" ldr r0, =__bss_start__\n"
" ldr r1, =__bss_end__\n"
" mov r2, #0\n"
" .thumb_func\n"
"zero_loop:\n"
" cmp r0, r1\n"
" it lt\n"
" strlt r2, [r0], #4\n"
" blt zero_loop");
/* Call the application's entry point. */
main();
}