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.

470M Hard Fault

Other Parts Discussed in Thread: HALCOGEN

Hi,

I am running FreeRTOS on TMS470M development kit (TMDX470MF066HDK). Currently, my code compiles without errors, but when I load it on the processor and run it, it frequently ends up in a hard fault exception. I have found that the region it fails in is inside the _init() function, which has been generated by HalCoGen. Specifically, it faults on the line (*handler)((const unsigned char *)loadAdr, runAdr); on the second iteration through the while() loop. For some reason, the stack seems to get corrupted at that point and the variables tablePtr and tableLimit lose their values. Upon return from the function, the processor immediately goes into a hard fault. In cases of normal execution, these variables retain their values until the function exits, and the processor continues into main(). The faulting function is shown below:

void _init()
{
/* initalise copy table */
    if ((unsigned *)&__binit__ != (unsigned *)0xFFFFFFFF)
    {
        extern void copy_in(void *binit);
        copy_in((void *)&__binit__);
    }
    
   /* initalise the C global variables */ 
   if (&__TI_Handler_Table_Base < &__TI_Handler_Table_Limit)
   {
       unsigned char **tablePtr   = (unsigned char **)&__TI_CINIT_Base;
       unsigned char **tableLimit = (unsigned char **)&__TI_CINIT_Limit;

       while (tablePtr < tableLimit)
       {
       unsigned char *loadAdr = *tablePtr++;
       unsigned char *runAdr  = *tablePtr++;
       unsigned char  idx     = *loadAdr++;
       unsigned char i = 0;
       handler_fptr   handler = (handler_fptr)(&__TI_Handler_Table_Base)[idx];

       (*handler)((const unsigned char *)loadAdr, runAdr);
       }
   }
}

More details:
Once the processor ends up in Hard Fault, the following registers are set:
Hard Fault Status Register = 0x40000000, FORCED bit = 1
Bus Fault Status Register = 0x02, PRECISERR bit = 1

Additionally, I've noted that in cases where execution faults, the variables in the function are stored at an offset of 0x1000 from where they are stored when execution succeeds. I am not certain if they are going out bounds of RAM in these cases or not.

I have tried using a different 470 board to rule out any hardware defects, since this fault seems to happen 50% of the time, and have also tried to load a completely unmodified version of the FreeRTOS port for the 470M, still with exactly the same results. For reference, I am using compiler version 4.9.7 in CCSv5.x. Note: if I reset the processor after the Hard Fault, the code will run without problems, but resetting the processor half of the time does not seem to be an appropriate solution to this problem.

Please let me know what the issue may be, and how I may go about debugging it.

Thanks,
Aiste

  • Aiste,

    Would you please setup breakpoints at data abort and prefetch abort locations at the interrupt table to if there is any abort? On Cortex-M3 based device, a CPU reset is needed to initialize the stack pointer before any code execution.

    Thanks and regards,

    Zhaohong

  • Hi Zhaohong,

    I'm not certain exactly where I would set the breakpoint for that. 

    Additionally, after I downloaded CCSv5.3 yesterday and the compiler version changed from 4.9.7 to 5.0.1, I am no longer experiencing the problem. The processor seems to initialize and run without issues 100% of the time. Although the issue is solved, do you have any suggestions of why that may be? I have not made any code changes since changing the CCS version. 

    Thanks,

    Aiste

  • Aiste,

    I would think it a compiler related issue. It seems that compiler version 4.9.7 does not treat some compiler switches in the init() function correctly. We saw similar problem in the past.

    Glad to hear that you solved the problem.

    Thanks and regards,

    Zhaohong