Extracting faulting address on Cortex-M3

OP #1659017
Rate this post
• ▲ useful
▼ not useful
I'm trying to display information on my LCD in the fault handler.  I'm 
mostly interested in the address of the code that caused it, or close to 
it.  BFAR rarely gives me a valid address.

I've planted identical bugs in my code, but in multiple locations which 
I can trigger individually.  I try writing to 0x3000000, which is an 
invalid address and always causes a fault as expected, but the 
hardfault_args pointer (see code below) sometimes needs to be 
incremented by one word to land on the correct set of pushed registers 
(r0-r3, r12, LR, PC, xPSR).  hardfault_args will point to the correct 
address in the stack when some bugs are triggered, but other bugs will 
cause hardfault_args to be one word too small.  It's perfectly 
repeatable.  I'm not using an RTOS.

I've tried incrementing hardfault_args when it isn't divisible by 8. 
I've also tried setting STKALIGN in the NVIC.  Initially I thought this 
worked, but I was testing it on a slightly different CM3 micro 
(LM3S6965) with slightly different code, but same core. Now I'm trying 
it on a LM3S9B00 chip and one of the artificial bugs is still causing 
hardfault_args to be offset by one word; this bug is even in the same 
function, but different location, than another which gives good results 
(each of these bugs is in a completely different area and triggered 
individually) This is driving me nuts.

Any ideas?


Here's what I'm using (GCC):

static void IntDefaultHandler(void)
{
  __asm(  "TST LR, #4\n"
        "ITE EQ\n"
        "MRSEQ R0, MSP\n"
        "MRSNE R0, PSP\n"
        "B hard_fault_handler_c\n");
}

void hard_fault_handler_c(unsigned int * hardfault_args)
{
//display hardfault_args[0], hardfault_args[1],...hardfault_args[7]
}

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.