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.

Error when I use stdio.h library.

Other Parts Discussed in Thread: TM4C123GH6PM

My process not run and jump to FaultISR() function of tm4c123gh6pm_startup_ccs.c file. Before debugging, I built and not have errors. So anyone can help me how to use sprintf() function.

My code below 

#include <stdio.h>

char * __restrict Temp;

char * __restrict varI;

char varX = 65;
char temp[3];

int main(void)
{
          //
          // Configuring system's clock.
          // System's clock = 50Mhz.
          //
          SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

          // initLCD();

          varI = &varX;

           Temp = &temp[0];

           sprintf(Temp, "%02d", varI);

            while(1)
            {
                  ;
             }
            return 0;
}

  • Your problem has nothing to do with studio.h and everything to do with your code.
  • From your code it is not clear to me what you are trying to do. What your code does is tries to print the address of the variable "varX" as a decimal number into the three byte string temp. It won't fit. but the reason you are jumping to the FaultISR is that most likely you have overflowed the stack. The "sprintf" function requires a lot of stack space. The default project only allocates 256 bytes. Increase your stack size to 1024 bytes. You can do this by changing the project settings and editing the link command file.

    Changing the project settings:

    Editing the link command file:

    __STACK_TOP = __stack + 1024;
    

  • Thanks, Bob Crosby. Best Supporter. Have a good day. :)