This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432E401Y: Array declaration issue on MSP432E401Y launchpad

Part Number: MSP432E401Y

Tool/software:

Hi Maters,

I am working on a MSP432E401Y launch pad and want to collect some samples (about 1000) through and external ADC and store in an array for frequency calculation. As I declare an array, the code run into the infinite loop in startup_msp432e401y_ccs.c. When I change the size of the array from 1000 to 2, the code runs well. As I increase the size of the array from 2 one by one till 13, the code runs well. But when the array size is 14, the code runs into the infinite loop. 

the code is here.

void main(void)
{

uint32_t systemClock;

systemClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480),120000000);

uint32_t i,ii,N, i32Idx;
uint32_t N_sample=100;

uint32_t sample_data[14];
sample_data[0]=1;

The array starts from the address of 0x20000348. I checked the microcontroller's memory; this part (0X2000.0000 to 0X3FFF.FFFF) can store data, and there should not be conciliation.   

I also copy the variables with their addresses as follows.  

Please help,

Thank you very much,

Zhonghai

  • Have you tried to make it global, rather than allocating on the stack?

  • This works fine for me on an MSP432P401R:

    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    
    //![Simple GPIO Config]
    int main(void)
    {
        volatile uint32_t ii;
        uint32_t data[1000];
    
        /* Halting the Watchdog */
        MAP_WDT_A_holdTimer();
    
        /* Configuring P1.0 as output */
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
        data[0] = 50000;
    
        while (1)
        {
            /* Delay Loop */
            for(ii=0;ii<data[0];ii++)
            {
            }
    
            MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
        }
    }

  • Hi,

      Most likely you don't have enough stack. Try increasing the stack size and see if it makes a difference. See below for 512Bytes of stack. You can change to a larger value. 

    MEMORY
    {
    FLASH (RX) : origin = 0x00000000, length = 0x00100000
    SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }

    /* The following command line options are set as part of the CCS project. */
    /* If you are building using the command line, or for some reason want to */
    /* define them here, you can uncomment and modify these lines as needed. */
    /* If you are using CCS for building, it is probably better to make any such */
    /* modifications in your CCS project and leave this file alone. */
    /* */
    /* --heap_size=0 */
    /* --stack_size=256 */
    /* --library=rtsv7M4_T_le_eabi.lib */

    /* Section allocation in memory */

    SECTIONS
    {
    #ifndef gen_crc_table
    .intvecs: > 0x00000000
    .text : > FLASH
    .const : > FLASH
    .cinit : > FLASH
    .pinit : > FLASH
    .rodata : > FLASH
    .init_array : > FLASH
    #else
    .intvecs: > 0x00000000, crc_table(crc_table_for_intvecs)
    .text : > FLASH, crc_table(crc_table_for_text)
    .const : > FLASH, crc_table(crc_table_for_const)
    .cinit : > FLASH, crc_table(crc_table_for_cinit)
    .pinit : > FLASH, crc_table(crc_table_for_pinit)
    .rodata : > FLASH, crc_table(crc_table_for_pinit)
    .init_array : > FLASH, crc_table(crc_table_for_init_array)
    .TI.crctab : > FLASH
    #endif

    .vtable : > 0x20000000
    .data : > SRAM
    .bss : > SRAM
    .sysmem : > SRAM
    .stack : > SRAM
    }

    __STACK_TOP = __stack + 512;

  • Hi Charles,

    As I increase the stack size, I can increase the size of the array, and the code runs normal. 

    What is the upper limit of the stack size? 

    Thank you very much,

    Zhonghai 

  • Keith,

    Thank you very much.

    It is the stack size issue. 

    Zhonghai 

  • In theory, the stack is limited by the physical amount of SRAM on the device.  Of course you don't want to reserve too much because the unused memory is just wasted. There is a .map file in the Debug folder to view how memory is allocated for different things. 

  • Hi Charles,

    I checked the datasheet, and found MSP432E401Y has 256KB SRAM. So the maximum stack value can be 256k? 

    Now I set 8192, and it works for the array with 1000 elements. 

    Thanks,

    Zhonghai 

  • I checked the datasheet, and found MSP432E401Y has 256KB SRAM. So the maximum stack value can be 256k? 

    You should only reserve enough for what you need or waste the unused memory. 

  • Which is why I suggested allocating it globally rather than in main().

  • Thank you very much. I also tried global variable; it works too.