Hardfault – Getting Cause of

Hi 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 “`cpp 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, handler2addressconst n” ” bx r2 n” ” handler2addressconst: .word getRegistersFromStack n” ); } extern “C” void getRegistersFromStack( uint32t *pulFaultStackAddress ) { uint32t 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; } “`

Hardfault – Getting Cause of

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.
So if you put a break point on entry to the naked function, then step through the assembly instructions, does it get to the jump instruction? If so, what happens when you execute the jump instruction? If not, what do the assembly instruction do? If the jump is just missing altogether then try adding “attribute((used))” to the function so the compiler doesn’t remove it (it may not know it is used if it is only called from the inline asm code).

Hardfault – Getting Cause of

Hello Barry Thank you for replying this fast. Unfortunatelly no, i can breakpoint to the “asm volatile” line, but if i then step, the debugger just shows be an address and any further step i try to make has no impact, it keeps staying on this line. Same result with attribute used for both functions. I missed to mention that this is built with -Og, not -O0, but in this case, all 3 involved functions are wrapped into the following section:

pragma GCC push_options

pragma GCC optimize(“O0”)

void example() { }

pragma GCC pop_options

Hardfault – Getting Cause of

Are you sure you actually have the hard fault handler installed. If you cannot put a break point on it it sounds like its not there. If you stop the debugger and it is sitting in a tight loop it sounds like you are actually executing a default handler rather than your handler.

Hardfault – Getting Cause of

Yes, positive, and i can breakpoint the hardfault handler as well as the prepare (naked) function. But there it ends, once i make 1 step inside the naked function, its over and it keeps staying on the address of some execution instruction. https://ibb.co/BBMPmv3 https://ibb.co/HF2gGzY https://ibb.co/jJvbxM9

Hardfault – Getting Cause of

Do you switch to assembly view before trying to step into the asm function? It is written as inline asm so the compiler is not going to be able to step into it.

Hardfault – Getting Cause of

I am/was not aware of such option. Need to check before i can answer. Its a modifed version of eclipse, Atollic TrueSTUDIO V8.1.

Hardfault – Getting Cause of

i do have the option to live step by looking at the disassembly, but the output once i step inside the inline asm instructions is as follows: de854710: Failed to execute MI command: -data-disassemble -s 3733276432 -e 3733276477 — 3 Error message from debugger back end: Cannot access memory at address 0xde854710

Hardfault – Getting Cause of

Hello Barry I cannot figure it out. I know that i am not allowed to use a “prepare” naked function as shown above as i will go deeper into the stack and therefore the register readout of course does not what it is supposed to. but other than placing the asm instructions directly into the fault handlers entry point, i dont know how i can handle this. Eclipse says, when debugging inline asm code, i should switch into the dissassambly to actually see what is happending. This even seems to work, until i try to step, as soon as i execute the first line of asm instructions, it jumps to an unknown location, and the debuggers gets cut out… Is there an alternative? Could i somehow translate the asm into c?