cancel
Showing results for 
Search instead for 
Did you mean: 

How can I either turn off HardFault_Handler interrupts or find out whether I'm running stand-alone or with a debugger?

arnold_w
Senior

I am working with the STM32F405-microcontroller and I'm writing my code inside Eclipse (NOT System Workbench) and I'm compiling with GCC and I am debugging using GDB OpenOCD Debugging. My project only has a debug-configuration, it does not have a release configuration (don't want compiler bugs to hit me when I release code). Sometimes I want to display small helpful text-messages and when I'm running in conjunction with a debugger I want to display those inside Eclipse, otherwise I want to send the messages to a UART. When I'm running with the debugger I can simply use _trace_write_semihosting_debug and this works great. However, when I run without debugger my call to _trace_write_semihosting_debug creates a hardware error, HardFault_Handler is called and SCB->HFSR bit 31 (=DEBUG_VT) is set and it's impossible to clear it. How can I either turn off these HardFault interrupts or find out whether I'm running with or without debugger?

3 REPLIES 3
T J
Lead

the Hardfault is telling you something is very wrong.

generally you have accessed memory outside of RAM and peripherals.

"how can I turn that off ? "

best to leave it running and fix the fault.

if the code drops into hard fault, best to reset, not clear the error.

I use OpenOCD and Visual GDB under Visual Studio... It works very well.

Single step, breakpoints etc, if you need help in Visual Studio, I will work with you.

I just use the serial ports and Terra Term to get my display

Look at what ITM_SENDCHAR cues on.

And perhaps things within the ITM, ETM and DWT register frames.​

BKPT might Hard Fault. Perhaps decode the registers, advance PC, and return via stack frame.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

When you run with debugger, you can write a magic number somewhere in the RAM by the load/init script. The code will check it at startup and enable semihosting and ITM.

-- pa