I am not expert on Cortex-M3. I recently test the memory handle using mbed LPC1768. It is strange that the debugger cannot jump into the hardfault_handler function. But the exceptional code execuated when it run in non-debug mode.
The code was exported from mbed online compiler and then opened by Keil uvision 5. I rewrite the HardFault_Handler function to capture an exception. The debugger is set as CMSIS-DAP. When I compile the code and load to the chip. It will flash LEDs after few seconds which means it jumps to the Hardfault_handler as expected. However, when I run in debug mode, the code paused at following line. The LED is not flashing as expected.
0x0000263E BEAB BKPT 0xAB
and I check the peripherals->core peripherals->fault report, the HARD_FAULT_STAT is 0x0 which means it didn't catch the interrupt. The BKPT bit as DBG_FAULT_STAT is 1. However, I didn't set any break point.
In the registers view, the ISR is 0 as well which means there is no interrupt caught!
Anyone can help on this problem? If a debugger cannot catch Hard_Fault_stat. It will be very difficult.
Here is the code.
#include "mbed.h" Serial pc(USBTX, USBRX); BusOut leds(LED1, LED2, LED3, LED4); extern "C" void HardFault_Handler() { pc.printf("Hard fault!\r\n"); while(1) { leds = 0x09; wait(0.1); leds = 0x06; wait(0.1); } } void fail() { pc.printf("Caught the failure\r\n"); while(1) { leds = 0x09; wait(0.4); leds = 0x06; wait(0.4); } } class Test { public: int something; char woot[28]; }; int main() { Test *dummy; int index = 0; while(1) { dummy = new Test; if (dummy == NULL) fail(); pc.printf("%u\r\n", index); ++index; } }