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.

MSP-EXP430F5529LP: Program will not run if another variable is added or an array is made larger

Part Number: MSP-EXP430F5529LP
Other Parts Discussed in Thread: ENERGIA

Hello, i have been having a very weird issue to do with our MSP boards.

The program will not start (the first step in the program is to turn an LED on) if an extra variable is compiled into the program or if an arrays size is increase. 

I dont really know what is causing this, i assume its something to do with large global variables but i really dont know how to deal with it if it is that. Does anyone have an idea of why this issue could be occuring? i am using Energia instead of code composer so i hope it wouldnt be something to do with that.

  • How many globals are you using?

    Are you allocating a lot of variables on the stack, too?

  • There are definitely a lot of globals, the program has many setup variables and there is a few large 288 item arrays.

    I do not know if im allocating them on the stack

  • You allocate on the stack when you create a variable (an "auto" variable) inside a function.

  • some locals are made, no where near the amount of globals though. this program is sort of a combination of 4-5 different libraries which each have their own globals but also globals from the example files. id estimate there to be atleast 20 globals.

    i should probably add that even when those large global arrays are reduced down to 3 items the problem still occurs, that version of the code is using roughly 26% of the 8kB RAM

  • Usually this happens when you have a wild pointer that clobbers some important part of memory. It works fine when it interferes with a not-so-important variable, but once you move things around a bit you start overwriting important bits - like stack return addresses.

  • do you have any ideas how i could fix that issue? those large data arrays are quite important. Is there some way to increase how large the stack can be or is that a hardware limitation? or another way of storing these variables?

    I just attempted to import the project into code composer to try and use the debugger, i thought it may provide me with some insight of what is wrong, but it gets a java stack overflow error. Do you think this may be related at all?

  • Hello Keith, i ended up replicating the issue in another energia project by creating a large array (1000 big) and used the disassembler to see if it was actually running and to my surprise it is. It seems to get to a "run_array" function and does that a few times and then starts again at the start of the program. What is weird though is that the function only has one return and that is never reached. I was wondering, if this function is taking a long time to run, could it be the watchdog timer resetting the board?

    EDIT: It seems to be a specific MOV.A instruction where the program restarts after. I then changed the size of the array to see if the location would change and it seems to have, it sort of runs a loop and if i increase the size by 100 it happens earlier and if i shrink the size by 100 it takes longer

  • Using CCS, it is possible for the watchdog timer to time-out during C (.data/.bss) initialization if your data is too big. The usual fix for this is to define a _system_pre_init() function that stops the watchdog (before C initialization runs). [Ref CC User Guide (SLAU132s) Sec 6.9.1] Recent versions of CCS also have a project-level check-box to ask the C startup to do this automatically.

    I don't know whether Energia has a similar mechanism. I suppose you could just add something like

    int _system_pre_init(void) {
        WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog
        return(1);                  // You can finish C initialization now
    }

    and see if it helps

  • I had just found that function, sadly it looks like energia doesnt use that function which is very annoying. Havent had any luck with finding anything about a version for energia, guess i may have hit the end of what can be done.

    Hopefully energia code may be portable to a normal project in some way

  • Poking around github, it looks like Energia uses msp430-gcc. That may have an analogous mechanism, but I don't know it, and I don't see any hints in SLAU646E .

  • It did let me compile with the TI compiler tho i didnt seem to help, i also read something like that about gcc. ill keep looking at it as it may be the right direction

  • I found the solution, just like your said GCC has its own way of declaring "noinit", as soon as i did this it got to setup immediately, this is fine as i was already initialising the variables later but it seems the watchdog timer is reset when using a forloop.

    To not initialise a global variable or array you write the code below after the variable:

    __attribute__ ((section (".noinit")))

    Example:

    TYPE array[1000] __attribute__ ((section (".noinit")));

    Thanks for your help!

**Attention** This is a public forum