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.

MSP432P401R: UNDEFINSTR Hard Fault on void function return

Part Number: MSP432P401R


I am getting thrown into a fault ISR when I go to return from a certain function. The xPSR Exception register is reading 3, and register 0xE000ED28 is reading 0x0100, which when translated in the manual goes to an UNDEFINSTR error.

I have tried the same code on two different processors, and I am getting the same result. The function that is causing the problems is as follows:

char ack[10];
GPS_GA(ack);
if(ack[0] != '\0'){}
/**
 * Turns on GPS transparency mode
 * Gets the GP Accuracy tag, and pareses out the accuracy
 * Turns off GPS transparency mode
 * 
 * Puts the result in data
 * 
 * @param data 10 character char array
 */
void GPS_GA(char* data){
    char gpsResp[256];
    char* acc = NULL;
    char accuracy[10];
    if(GPS_PassThrough(true)){
        do{
            getResponse_Timeout(GPS_UART_MODULE, 1000, gpsResp);
            acc = strstr(gpsResp, "$GPACCURACY");
        }while(acc == NULL);
        int i;
        for(i = 0; i < 10 && acc[i+12] != '.' && acc[i+12] != '*'; i++){
            accuracy[i] = acc[i+12];
        }
        accuracy[i] = '\0';
        while(!GPS_PassThrough(false));
        strcpy(data, accuracy);
    }else{
        data[0] = '\0';
    }
    int i = 0;
    i++;
}

The last 2 lines of the function are just there for a sanity check. I can put a breakpoint on i++ and I can confirm that data contains what it is supposed to and accuracy does as well. I get the fault ISR somewhere between the i++ of GPS_GA and the if statement. A breakpoint put on the if statement is never triggered.

I am using compiler TI v16.9.1.LTS. It is a custom built board based on the RGC package.

I have also tried coding the function in another way, returning an int, and got the same error. I tried changing the function name, and it worked once...

  • I don't see anything obvious, but I am going to guess that you are clobbering the return pointer in the stack. accuracy only has 10 locations and you are probably storing the null in accuracy[10] which does not exist.
  • Reid Kersey said:
    I am getting thrown into a fault ISR when I go to return from a certain function.

    As a guess maybe the software is overwriting the return address which has been stored on the stack, leading to the crash when the GPS_GA function attempt to return.

    The following could help to confirm this:

    a) Step into the GPS_GA function and determine the address on the stack where the return address is stored.

    b) Set a Hardware Watchpoint to trigger on a write to the address on the stack where the return address is stored.

    c) Set a breakpoint on the i++ statement.

    Resume the program and see if the Hardware Watchpoint triggers before the i++ statement is reached. If so, that should identify the offending code which is causing the overwrite.

  • You were very much correct. I obliterated that return pointer. I didn't know I could watch the stack like that. Thanks for the info!

**Attention** This is a public forum