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.

MSP430F5172: during debugging, registers change value

Part Number: MSP430F5172

Hello

I have some problems with the msp430f5172 microcontroller, I am developing a telemetry application in which I send some temperature values ​​to a server (as a means of connection I use the wiznetw5100 module), but I have been trying to solve a communication problem for several days that still do not I can understand.

To store the response from the server, the requests and the data I am using char-type vectors such as:

char recibido [250];
volatile char token [160];
char petfinal [450];
const char peticion[17] =" HTTP/1.1\r\nHost: ";
const char agent [33]="User-Agent: Gigawatt_firmwareV1.0";
const char authorization[14]="Authorization:";
const char content[30]="Content-Type: application/json";
const char accept[11]="Accept: */*";
const char length[16]="Content-Length: ";

The functions to communicate with the W5100 work well because I have already used them in other applications, the problems I have are:

1) The values ​​of some variables are changing sporadically, I think it is something related to the RAM memory since when monitoring for example the variable "peticion", its value is combined with some other string that I use later, for example, I paused the program for a moment and in the "expressions" window I saw that the value of "peticion" was in: " HTTP/1.1\asig IP ", which I imagine is caused by combinig it with a text that I used for the menu of device configuration.

2) When I load the program, debugging does not start correctly, the following window appears:

As if the program started running without me having given the "Run" button, in order to work I had to select "TI MSP430 USB1 / MSP430 (Running)" and press the "suspend" button leaving the screen as shown below:

Here I stagnated for a while since I did not know what to do, until I discovered that by changing the value of the variable "count" to 1, the program let me exit and continue with the execution of the code. Why does this happen? That could be related to a test that I carried out, where in a loop (while) I wrote a char type vector without defined size until it exceeded 2K of RAM memory?

Now, whenever I load the program I have to do this for it to run, and when I turn on the device without the debug connection, it does not turn on.

  • 1)  This symptom suggests a buffer overrun, past the end of one array and into the next. There are a number of ways to do this; some common ones are (a) using sprintf instead of snprintf (b) using strcpy/strcat instead of strncpy/strncat (c) memcpy using the source length rather than the destination length. Or you could just have a loop that goes too far. The values of the misplaced bytes may offer a clue. 

    The test you described at the end of your post sounds potentially destructive. Can you explain this further?

    2) This symptom indicates that you have enough initialized data that the startup code encounters a Watchdog timeout before it completes initializing it. Try adding something like:

    int _system_pre_init(void) {
        WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog
        return(1);                // Finish C initialization
    }

    which will stop the Watchdog timer before data initialization [Ref CC User Guide (SLAU132X) Sec 6.9.1].

  • Hi Bruce McKenney

    The situation potentially destructive was similar to:

    char recibido[];
    unsigned int contador;
    unsigned int get_size;
    
    int main()
    {
        xxxxx...... more code
        
        for (contador=0;contador <get_size;contador++)
        {
           recibido[contador]=leer(contador);
        }
        
        xxxxx...... more code
    }

    I don't remember the exact code, because I changed it and didn't save it.

    The problem was that the value of the counter variable was increased too much (more than 2500), and the RAM of the MSP430f5172 is 2K. After that the problem I described where the program could not be started started to happen.

    I would also like to consult, how to make the compiler not use in any way the memory spaces assigned to certain variables, because I have not been able to avoid that some arrays are overwritten with data of constants, Strings of characters that I use later or other arrays .

    I appreciate the collaboration.

  • As I understand it(?), you ran this program only once (ever). I don't know of a way to cause permanent damage with a stray write; I expect your program reset with a VMA, perhaps repeatedly. I think this is a coincidence.

    The symptom you displayed in (2) seems clear enough. Did my suggestion help?

    I'm not sure what sort of protection you'd like the compiler to provide. If you want a (global) variable to be read-only, declaring it "const" normally does this, by putting it into Flash.

**Attention** This is a public forum