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.

Occurrence of a hard fault in TIVA C series launchpad

Other Parts Discussed in Thread: MAX232, MAX3232, TM4C123GH6PM

I am using the launchpad to display data on a simple 16x2 LCD and simultaneously a timer(in interrupt mode) to transmit some data via UART1, and a receive interrupt . TIVA launchpad in connected to a 4key key-pad.

The system is functioning as required but code gets stuck in the FaultISR() in an arbitrary fashion.LCD functions work perfectly and have been defined above main. Following is a main() :

int main(void) {

unsigned volatile int temp_val1=0,temp_val2=0;
unsigned volatile char flag=1;
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // control pins for LCD
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // data/command pins for LCD
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // UART1 pins, 2 inputs from keypad
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // 2 inputs from keypad
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2| GPIO_PIN_1| GPIO_PIN_3);

config_TIMER();

IntMasterEnable();
sw_init();                                    // initialises the GPIO for key-pad
LCDInitialize();

   while(1)

  {

   if(GPIOPinRead(SW_PORT1, sw4 )==0)
  {
    mil(150);                                              // a delay function, defined above main()
    flag=1;
    temp_val1++;
    LCDClear();
   }
   else if(GPIOPinRead(SW_PORT1,sw3)==0)
   {
    mil(150);
    flag=2;
    temp_val2++;
    LCDClear();
   }

   switch(flag)                             //flag is a variable which keeps track of the mode selected to be displayed on LSD
 {
  case 1:
  LCDRow1();
  LCDWriteString("NODE 1 : ");
  if(temp_val1>30)
  {

   LCDWriteString(" FIRE");
   }
   else
   {
    LCDWriteString("no FIRE");
    }
    LCDRow2();
    LCDWriteString("Temp_Field: ");
    LCDWriteInteger(temp_val1);
    break;
    case 2:
    LCDRow1();
    LCDWriteString("NODE 2 : ");
    if(temp_val2>30)
   {

     LCDWriteString(" FIRE");
    }
    else
   {
     LCDWriteString("no FIRE");
    }
    LCDRow2();
    LCDWriteString("Temp_Field: ");
    LCDWriteInteger(temp_val2);
    break;

    default:
    break;

    }

  }
}

  • Hi,

    Since the hard fault is a very serious thing, please read this application note which shows up how to deal with the problem: http://www.ti.com/lit/an/spma043/spma043.pdf

    Also, not checked all your code, but the missing parts/routine could be at the origin of your problems.

    Petrei

  • HI,

    Thanks Petrei for the suggestion. I read the spma043 pdf and did the mentioned steps, but my problem wasn't solved.

    The values of the registers using the debugger are as follows:

    NVIC_HFAULT_STAT: 0x40000000

    NVIC_FAULT_STAT: 0X00009200

    this means that the set bits are BFARV, BSTKE, and PRECISE

    NVIC_FAULT_ADDR: 0X1FFFFFF8  

    and when i searched this address in the datasheet it corresponds to a location in the block reserved for ROM.

    Also MSP : 0X1FFFFFF8

    Please give me some insights about what the problem could be. if the interrupt ISRs needs to be provided i will do so.

    Thanks in advance,

    Saurav

  • Hi,

    I know it is difficult to track down the cause - you must continue - do the following: in the "debug" window, upper left one, you have all stack frames used, up to the fault handler. Look and see which is the previous one - to determine the function and the location which caused the interrupt - click on that to get the info - eventually post a picture.

    Petrei

  • Sorry i didn't understand where to find the stack frames used on the top left of the debug window.

    posting a screen shot. please point how to see the stack frames:

  • Hi,

    This is the "debug" window (or pane):

    As you can see, there are two rows: FaultISR() and 0xFFFFFF0 - each row correspond to a stack frame - usually selecting (click on) one row moves you to that stack frame. 

    But in this case, seems you did not even reached the "main" function - please check your project again, something unusual brings you there - did you configured the stack? 

    Petrei

  • I read the value of the stack pointer(sp),i.e 0x1FFFFFE0 and used that in the memory browser and got the following:

    And as mentioned in the application note

    "

    In the screen capture above, the first two rows show the exception stack frame. The first row shows the saved
    values of registers R0-R3. The second row begins with the saved value of R12, followed by LR, PC, and then
    xPSR register. To start with, the most interesting value is the PC, which is 0x0000.0CBC. There is a high
    probability that this points either directly at, or near the instruction that caused the fault.

    "

    Here my PC value should be 0x00000E62, I used it in the diassembly window to get the following:

    So is the problem arising due to the API SysCtlDelay()  ??

  • Hi,

    No, the stack pointer shoud not be neiter at 0x20000000, nor below that address. At 0x20000000 should be a reserved space for interrupt vectors in the case you move them to SRAM. SP should be in SRAM.

    If you are sure you enter main, then start by stepping over each function until you find out which one is the cause of hard fault. For your special initialization functions, step in first when you got to that function and then step over each inside expression/function.

    But check again the stack , the linker file and the map file.

    Petrei

  • Actually i am using the Lab4 project of the TIVA launchpad workshop to develop my application. Should i create a new project and do all the initial settings and try?

    And i tried stepping over the functions and stepping into the ones with special initialization, did not find which one is causing the fault. while stepping over the functions nothing causes the hard fault. Only when i resume, the code works fine for some random time and gets stuck.

  • Hey,

    I made a new project and did all the initial settings. the code is working fine.

    But i don't understand what was happening till now. Any reasoning or explanations?

    Thanks for being patient and helping me.

  • Hi,

    Good to know you succeeded - you are the only one who can/must answer these questions, since you have the whole project. Try to compare the settings for each one and separately the files, and you will discover a little tiny detail not obvious which could make problem(s).

    Petrei

  • Thanks a lot for your help. In this process of debugging i leant a few new things likes using the CCS debugger properly and analysing the code.

    Saurav

  • Hi Petrei,

    I have one more doubt. In my new project When i am defining the pins B0,B1 as UART1 pins by

    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);

    i am getting 2 errors as

    #20 identifier "GPIO_PB0_U1RX" is undefined

    #20 identifier "GPIO_PB1_U1TX" is undefined

    my other Uart API's are not showing any errors, i have included driverlib/uart.h, i also tried defining the part in the code, but these 2 errors are still there.

    thanks

  • Hi,

    What Tiva version do you use?

    Also, defining part should not be done in the code, but in compiler predefined symbols and you need to #include "driverlib/pin_map.h" file In your source file. This is a big file - open it in your IDE and find out first (search for) the name of your micro controller, then you will see the conditional expression #ifdef PART _IS_TM4C123xxx - verify if your pins are there at the specified port locations.

    If you use UART1, take care you need also an external converter chip like MAX232 to convert the 3V levels to the PC levels - you need to be sure on the levels (MAX232 is for 5V converter to PC levels).

    Petrei

    Edit :

    MAX3232 works with 3V levels.

    You may use PinMux utility to geneate the code for you and verify your code.

  • Thanks for your reply.

    Ya i browsed e2e community for similar posts and rectified the error.

    And about voltage levels, i have considered them. I am using TIVA TM4C123GH6PM (Launchpad) 's  UART1  to Interface it with Xbee, so no conversions are needed.

    My application is working fine. Thanks again

    Saurav

     

  • Hello all,

    I ahve been facing a serious problem that my code enters faultISR routine many a times. But if I try an remove some if loops then code starts working fine. 

    I dont know what exactly could be the issue. can anybody help me? Its little urgent,

    Thank you.

  • Hijacking other, unrelated threads, especially when they are marked as answered, is a bad idea. Open a new thread.

    Its little urgent,

    That is more detrimental than helpful. Or do you expect others to take the heat for your omissions and deficiencies ?

    Present more information about your issue. No one here is in possession of a magic crystal ball.

    I ahve been facing a serious problem that my code enters faultISR routine many a times. But if I try an remove some if loops then code starts working fine.

    Presenting some code might be helpful.

    Try increasing the stack size - sounds like a stack overflow.

  • Thank You F.m.

    Thanks for your reply.

    I will try and update on the same.