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.

RTOS/TM4C1294NCPDT: TI-RTOS exception handler override

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hello,

i am running TI-RTOS on an TM4C1294NCPDT. I am trying to override/hook the exception handler to print out the stacktrace/error message over uart.

My cfg file looks like this:

var m3Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');

m3Hwi.enableException = true;
m3Hwi.nvicCCR.DIV_0_TRP = 1;
m3Hwi.nvicCCR.UNALIGN_TRP = 0;
m3Hwi.resetVectorAddress = 0x4000;
m3Hwi.excHookFunc = "&foobar";
m3Hwi.excHandlerFunc = "&myExceptionHandler";

My exception handler looks like this:

void myExceptionHandler(Hwi_ExcContext *excContent)
{
    GPIO_write(OUTPUT1, GPIO_CFG_OUT_HIGH);
    UARTCharPut(UART0_BASE, 'x');
}

I am producing the heap exception.

void heartBeatFxn(void)
{
    while (1)
    {
        Task_sleep(1000);
        GPIO_toggle(OUTPUT2);
        Memory_alloc(NULL, 2048, 0, NULL);
    }
}

Console shows me this:

ti.sysbios.heaps.HeapMem: line 361: out of memory: handle=0x2003b2cc, size=2072
xdc.runtime.Error.raise: terminating execution

And i am ending in exit.c void abort(void).

The problem is myExceptionHandler or foobar never gets called. I also tried the myExceptionHandler with no parameters at all or void in it but none of it gets called.

What am i doing wrong?

  • Hi Clark,

    Running out of memory is an "error" not an "exception". Since you are passing in NULL for the Error_Block, the program terminates instead of Memory_alloc. If you pass in an initialized Error_Block or Error_IGNORE, the API would have returned with the Error_Block fields set if you supplied an initialized Error_Block. The return (which you are not testing) would have been NULL also. (In hindsight we regret having the program terminate when an error occurs and you have a NULL Error_Block).

    You can plug in an Error hook function which would have been called in your example. You can set the Error.raiseHook function in the .cfg.

    To test exceptions, I like to throw in an something like this somewhere in you code.
    asm(" .word 0x4567f123 "); //some undefined instruction

    This will generally cause an exception if you want to test out your handler.

    Todd
  • Hi Todd,

    thank you very much. I thought oom is an exception.

    When executing your asm instruction myExceptionHandler is called as expected.