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:
{
/* initalise copy table */
if ((unsigned *)&__binit__ != (unsigned *)0xFFFFFFFF)
{
extern void copy_in(void *binit);
copy_in((void *)&__binit__);
}
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