Hard Fault Handler investigation

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello,

 

i am using a SAMC20 (Cortex-M0+) with Keil 5.23 IDE and P&E multilink universal Fx debugger.

my progrram triggers a hard fault handler once every few runs (aprox 3-4 runs, somtimes more).

 

i have tried to investigate the reason for the hard fault, using guides line these:

https://community.arm.com/iot/embedded/f/discussions/3257/debugging-a-cortex-m0-hard-fault

https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

 

 

from what i can see, when i stop the debugger with a breakpoint in the hardFault handler, i see this pictures attached.

 

from what i understand, the problem occured in SP+0x20 = 0x20007FC0

a memory watch is attached showong that address.

in that line the address of the last command issued by the program is 0x3299 (did i do a mistake here?)

 

when i go to that address in my code, i see no address like that. (picture attached)

 

am i missing anything?

can the problem be that something in my programm (while running) made PC be misalligned somehow?

 

any help investigating the problem would be much appreciated.

 

thank you,

omer.

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have run into a lot of issues with hard faults the last couple weeks (FreeRTOS tasks make it even more challenging).  As an embedded beginner is has been tough, but I've worked through tracking them all down.  I'm on a SAMD20 on a custom board.  I tried following steps in the book The Definitive Guide to ARM CortexM0/M0+ and mostly only found that the main stack pointer was invalid.  Using the ASM code in that book didn't work for me, but I at least made a simple hard fault handler and used this to look at the linker addresses:  https://github.com/govind-mukund...

#pragma GCC diagnostic ignored "-Wmissing-prototypes"
void vApplicationMallocFailedHook(void)
{
	configASSERT( (volatile void *) NULL );
}

#pragma GCC diagnostic ignored "-Wmissing-prototypes"
void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName)
{
	configASSERT( (volatile void *) NULL );
}

// HardFault handler
void HardFault_Handler(void)
{
	#pragma GCC diagnostic ignored "-Wunused-variable"
	volatile uint32_t ipsr = __get_IPSR();
	#pragma GCC diagnostic ignored "-Wunused-variable"
	volatile uint32_t msp = __get_MSP();
	#pragma GCC diagnostic ignored "-Wunused-variable"
	volatile uint32_t psp = __get_PSP();
}

 

I only ever found that the main stack pointer was pointing to invalid memory and that was never very helpful.  The cause has been a few different things, but mostly pin collisions or other things that were seemingly unrelated.  I had to go through my code and disable things until I found something that was a cause in the problem.   Not sure if that is helpful, but good luck.

Last Edited: Fri. Mar 16, 2018 - 11:45 AM