This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to enable hardfault_handler in SDK12.3.0

Hi, I am using sdk 12.3.0 sd130v2. I have the hardfault_implementation.c included in the project. But I am not able to keep breakpoint anywhere in that file. I have made HARDFAULT_HANDLER_ENABLED 1 in sdk_config.h and included 'HARDFAULT_HANDLER_ENABLED' in project options defines. Still no luck. In other words, how to debug hardfault handler error in sdk 12.3.0?

  • Did you include the compiler specific file like hardfault_handler_gcc.c in your project?

  • Hi, TurboJ, thanks for the quick reply. After including hardfault_handler_keil.c I am able to have breakpoints in hardfault_handler (I am using keil IDS). But, the program halts at HardFault_c_handler at HardFault_process((HardFault_stack_t *)p_stack_address); In watch window, p_stack_address is 0x20002E10 and p_stack_address[0] is 0x20002E30. How to know where the error had started from here? I tried disassembly's 'show disassembly at address' option. But, my disassembly and code were mismatched right from the start. So, 'show disassembly at address' for both 0x20002E10 and 0x20002E30 show some address close to 0x20002E0C : 0xFFF1FFFF - which is not of much help to me.

  • Could you check the Error log "Hardfault PC: " to see where were the last position of the PC before the hardfault. Or you can look for the value of ((HardFault_stack_t *)p_stack_address)->pc directly when debugging.

    Then you can track back to the line of code causing the hardfault in the disassembly window.

  • hi Turbo J and Hung Bui, could you help me about hardfault resetting, i mean that simply i want to reset the chip when hardfault occured , currently i use ble_app_uart example in SDK 12.3.0, in sdk_config.h file i made HARDFAULT_HANDLER_ENABLED 1 but it does not reset itself. (to achieve hardfault i changed to uart priority APP_IRQ_PRIORITY_HIGHEST i dont sure about it but if i send a string ends with CR LF, disconnection occurs and chip hangs on) i saw that hardfault_process function defined in WEAK format so in main file i included hardfault.h and added following function : void HardFault_process(HardFault_stack_t * p_stack) { NVIC_SystemReset(); } unfortunately chip does not reset itself when hardfault occurs, could you help me about my mistake?

  • Have you included hardfault_handler_"your compiler".c into your project ?

Related