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.

Corruption of global variables stored in RAM on the MSP430F4152



We have been seeing problems in devices where global variables have either been sporadically set to 0 or a random value. These same values are periodically written to information memory to be saved in case of power loss. Here is the strange issue, the values are correct in information memory, but the globals that are supposed to hold the same value are not. It seems to happen relatively infrequently, but when it does it obviously causes a lot of problems. Here is some more information on the issue:

1. It seems that these globals get corrupted right after they are written to information flash.

2. It is possible that the program on the devices was compiled in debug mode instead of release mode.

So my question, is there any common issue that can cause globals to be unreliable like this? And are these issues more common in debug mode v.s. release mode? I can provide any other information about the program or memory usage.

  • Perhaps the stack is growing to the point that it overwrites your globals. On MSP430 the stack grows down from top of RAM, and globals live below the stack.

    I'd expect debug build stack usage to be at least as high as release, if not higher.

    Also the point of failure would probably be somewhere that the call graph is particularly deep, or includes functions with high stack use (parameters, local variables etc). Does that description match the part of your code that writes the globals out to flash?

  • Thank you Robert, this does describe the code where it writes globals to flash. After more research on stack overflows, I do believe this is the cause of the issue.

**Attention** This is a public forum