Hello, guys!
We have nRF51822 rev3 SoC that runs the code developed with nRF5 SDK v12.3.0. SoftDevice s130 is enabled and used.
We want to use our custom HardFault_Handler() function that overwrites the weak HardFault_Handler implementation. To achieve this, we did the following:
- Enabled HardFault handler in sdk_config.h with
#ifndef HARDFAULT_HANDLER_ENABLED #define HARDFAULT_HANDLER_ENABLED 1 #endif
2. Used our custom HardFault_Handler() implementation in main.c file:
void HardFault_Handler(void) { uint32_t *sp = (uint32_t *) __get_MSP(); // Get stack pointer uint32_t ia = sp[12]; // Get instruction address from stack NRF_LOG_INFO("Hard Fault at address: 0x%08x\r\n", (unsigned int)ia); while(1) ; }
However, it seems that we never reach our HardFault_Handler() implementation!
To test if we can properly reach our HardFault_Handler() implementation we created a custom illegal_instruction_execution() function that will cause the HardFault and tried to call that function in the code. The content of the function is as follows:
static int illegal_instruction_execution(void) { int (*bad_instruction)(void) = (void *)0xE0000000; return bad_instruction(); }
The function is properly causing the HardFault because we can clearly see it from the function Call Stack:
However, it seems we don't enter into our custom HardFault_Handler() function. Do you have any idea about what we are missing here?
Thanks in advance for your time and efforts.
Sincerely,
Bojan.