Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How do the SDK's HardFault_Handler()'s work?

I'm trying to reduce the size of my firmware update binary. It turns out that although enabling the "Execute-only Code" option in Keil increases my code size, it ends up decreasing the size of my compressed firmware update binary!

Unfortunately, to get the project to compile with the "Execute-only Code" option, I have to remove hardfault_handler_keil.c; otherwise, I get the following errors:

  • hardfault_handler_keil.c(55): error: A1944E: Literal pool entries cannot be generated in execute-only sections
  • hardfault_handler_keil.c(67): error: A1944E: Literal pool entries cannot be generated in execute-only sections
  • hardfault_handler_keil.c(68): error: A1944E: Literal pool entries cannot be generated in execute-only sections

If I remove hardfault_handler_keil.c, then upon a HardFault, my system would use the default handler, which is just an infinite loop, instead of getting to our custom HardFault_process(), and this is not acceptable.

I have an alternative implementation of Hardfault_Handler() that does not cause compilation errors:

extern void HardFault_c_handler(uint32_t * p_stack_address);

void HardFault_Handler(void)
{
  uint32_t r0;
  __ASM volatile("   mrs r0, msp        \n");

  uint32_t *p_stack = (uint32_t*)(void*)(r0);

  HardFault_c_handler(p_stack);
}

But this is seems "too easy". Can I get a description of the general "purpose" of the HardFault_Handler() function in hardfault_handler_keil.c? Would my implementation not handle certain types of HardFault? I'm not well-versed in ARM assembly, so I'm not all that sure what it's intended to do.

I am using the nRF52832 and nRF5 SDK v17.1.0.

Parents Reply Children
No Data
Related