5 years ago.

Determining when my program has crashed?

I've got a program on my FRDM-K64F that seems to have died. It runs for a bit and it responds to ping, then eventually stops responding to ping.

Unfortunately, I don't have any I/O available other than the onboard RGB LED, which will make debugging fun. I'll have to use the three colors, along with maybe a few brightness values to give myself a handful of states to home in on where execution has stopped.

I read up on fault handlers, and I added the following functions, though I do not know if they really do anything...

DigitalOut GreenLed(LED_GREEN);
DigitalOut RedLed(LED_RED);

void BlinkErrorCode( int blinks)
{
    for( int i=0; i<blinks; i++) {
        RedLed = 0;
        wait( 0.1);
        RedLed = 1;
        wait( 0.1);
    }
    wait(0.5);
}

extern "C" void HardFault_Handler()
{
    GreenLed = 1;
    BlinkErrorCode(1);
}

extern "C" void UsageFault_Handler()
{
    GreenLed = 1;
    BlinkErrorCode( 2);
}

extern "C" void  BusFault_Handler()
{
    GreenLed = 1;
    BlinkErrorCode( 3);
}

extern "C" void MemMang_Handler()
{
    GreenLed = 1;
    BlinkErrorCode( 4);
}

Are there any other special functions I can implement to determine where my code fails? Ideally, I would like a handler that is called every time the program crashes, and I could then look at the value of a state variable to find the source.

I just found a Keil document that says it's supposed to be MemManage_Handler, not MemMang. I guess FreeRTOS's site had a typo. I'll try this and see if it indicates a memory problem.

posted by Dave M 06 Dec 2014

Dave, if you are able to export to GCC (ARM Embedded) and reproduce it there then you could use pyOCD and arm-none-eabi-gdb to debug the issue.

posted by Adam Green 06 Dec 2014

Thanks, Adam. I had considered trying the export to KDS option and trying to debug from there, but hadn't heard of pyOCD before and will have to try it out!

posted by Dave M 08 Dec 2014

(deleted because it was probably a stupid question)

posted by Dave M 09 Dec 2014
Be the first to answer this question.