After the tutorial which can be found here, i try unsuccessfully to see which thread and where in the stack the hardfault was originated.
Unlike the tutorial, my HardFault_Handler() function is not directly a naked function but forwards to one (prepareRegistersFromStack()). In the debugger, i can see the jump to the function prepareRegistersFromStack().
This functiom, prepareRegistersFromStack() then should jump to the getRegistersFromStack() function, although this never happens.
I also tried directly like the example states, so making the HardFault_Handler() a naked function which should jump to the getRegistersFromStack(), but unfortunatelly the same applies, no jump.
Can someone help me out here? Why does the getRegistersFromStack() not get called?
Thanks
extern "C" __attribute__((naked)) void HardFault_Handler()
{
__disable_fault_irq();
__disable_irq();
prepareRegistersFromStack();
}
extern "C" void prepareRegistersFromStack()
{
__asm volatile
(
" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" ldr r1, [r0, #24] \n"
" ldr r2, handler2_address_const \n"
" bx r2 \n"
" handler2_address_const: .word getRegistersFromStack \n"
);
}
extern "C" void getRegistersFromStack( uint32_t *pulFaultStackAddress )
{
uint32_t dummy;
/* These are volatile to try and prevent the compiler/linker optimising them
away as the variables never actually get used. If the debugger won't show the
values of the variables, make them global my moving their declaration outside
of this function. */
volatile uint32_t r0;
volatile uint32_t r1;
volatile uint32_t r2;
volatile uint32_t r3;
volatile uint32_t r12;
volatile uint32_t lr; /* Link register. */
volatile uint32_t pc; /* Program counter. */
volatile uint32_t psr;/* Program status register. */
r0 = pulFaultStackAddress[ 0 ];
r1 = pulFaultStackAddress[ 1 ];
r2 = pulFaultStackAddress[ 2 ];
r3 = pulFaultStackAddress[ 3 ];
r12 = pulFaultStackAddress[ 4 ];
lr = pulFaultStackAddress[ 5 ];
pc = pulFaultStackAddress[ 6 ];
psr = pulFaultStackAddress[ 7 ];
/* When the following line is hit, the variables contain the register values. */
for(;;);
/* remove warnings */
dummy = r0;
dummy = r1;
dummy = r2;
dummy = r3;
dummy = r12;
dummy = lr;
dummy = pc;
dummy = psr;
dummy = dummy;
}