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.

TM4C123GH6PM: sprintf results in faultISR loop

Part Number: TM4C123GH6PM

Hello

I am measuring magnetic fields with the HMC5883L chip in single measurement mode, and transmitting the data via UART to a PC. 

The program crashes (goes into faultISR loop) when the sprintf function is used. Often, it only happens the second time the function is used and everything from the first call is actually transmitted fine via UART (not every time).

I tried to increase the heap and stack sizes to 3072 and 2048 in the project properties window, but this didn't solve it. 

Below is the part of the program where the sprintf function is used:

uint32_t measxL, measxH, measyL, measyH, measzL, measzH;
int16_t measx, measy, measz;
char meas[30];

while(1)   // each cycle will give a measurement
{
     // single measurement mode
     reg = 0x02; // to CRA register
     value = 0x01; // single measurement mode
     HMC_I2C_TRANSMIT(slave_address, reg, value); // send to HMC5883L for configuration

     vTaskDelay(10/portTICK_RATE_MS); // wait 10 ms for measurements to be performed (alternatively monitor DRDY)

     // read data in HMC5883L registers
     HMC_I2C_MEASUREMENT(slave_address, 0x06, &measxL, &measxH, &measyL, &measyH, &measzL, &measzH);

     measx = ((measxH & 0xFF) << 8) | measxL;
     measy = ((measyH & 0xFF) << 8) | measyL;
     measz = ((measzH & 0xFF) << 8) | measzL;

     sprintf(meas,"%d, %d, %d",measx,measy,measz);
     uart0_printstring(meas);

     vTaskDelay(1000/ portTICK_RATE_MS); // wait 1000 ms for next measurement
}

I just started working with this microcontroller, so I am beginner level. I have tried to look at other posts such as this one: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1186770/tm4c123gh6pm-sprintf-with-float---printf_support-full-and-stack-size-to-1024-crashes

and this one: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/446764/problems-moving-to-second-stage-hello-world

But it didn't solve my problem, and the last one is too advanced for me at this time. 

I have included the required libraries and CCS doesn't give me any complaints. 

Best regards,

Simon

  •     sprintf(meas,"%d, %d, %d",measx,measy,measz);

    First step: Replace this with:

        snprintf(meas, sizeof(meas), "%d, %d, %d",(int32_t)measx,(int32_t)measy,(int32_t)measz);

    Even if it doesn't fix your (immediate) symptom, it avoids a number of hazards.

  • Hello Simon,

    Try Bruce's suggestion first and foremost. Beyond that, I would recommend using the following document to try and track what is triggering the issue: https://www.ti.com/lit/pdf/spma043

    If you are using a lot of stack before the call there is a chance the increase wasn't enough but it would surprise me if this was a stack issue.

    I really agree with Amit's post in one of those prior threads to just use UARTprintf from TivaWare though, since you are just doing UART --> PC.

    Best Regards,

    Ralph Jacobi