HardFault_Handler from FreeRTOS - why?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HardFault_Handler from FreeRTOS - why?

4,706 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dpa on Sat Jul 28 11:41:05 MST 2012
Hi LPC Fans,

I've modified the freertos project in the NXP demos for LPC11xx. A task blinks an led if the value of a variable is !0. The variable value is toggled if we can take a binary semaphore that is given by an interrupt handler invoked by a button connected to a GPIO port. It all seems to work as expected, unless I press the button quickly, repeatedly, and then I end up in the HardFault_Handler. I'm new to the Cortex in general (I know the previous ARM arches) and M0 in particular. How do I debug this?

Best regards,
Dave
0 Kudos
Reply
8 Replies

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dpa on Fri Aug 03 15:18:00 MST 2012
Thanks superfred, you prompted me to find this (FreeRTOS & Context interrupts - I think it's relevant to the M0 also):
http://www.freertos.org/RTOS-Cortex-M3-M4.html
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dpa on Fri Aug 03 12:19:20 MST 2012
for all the replies. I found that by repeatedly pressing the button (which generates a lot of interrupts, due to the lack of de-bounce circuitry [I didn't make it ;-)]) was causing the isr to overrun the bounds of the stack. Thanks to TheFallGuy in particular, and apologies for not looking there first...
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Tue Jul 31 05:29:23 MST 2012
Debugging a Hard Fault:
http://support.code-red-tech.com/CodeRedWiki/DebugHardFault
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Tue Jul 31 04:46:48 MST 2012
To get closer, one can catch the failing code --in-- the hardfault routine, and check
the contents of some system registers that contain the reason for the hardfault.
There is also some example code by joseph yiu around ...

I've done it once, but details like core register names and so are flushed down the memory hole - sorry.
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Superfred on Mon Jul 30 09:10:37 MST 2012
Hi dpa,

I had a similar problem: RTOS hangs up during interrupt.

Maybe my solution works also for you:
After long research I found out that you have to change the interrupt priority for the GPIO interrupt (in fact for all used interrupts), see
http://www.freertos.org/a00110.html,
section[FONT=Arial] [I][SIZE=2]configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY[/SIZE][/I][/FONT]

After I set the priority for GPIO with the command
NVIC_SetPriority( EINT3_IRQn, 27);
before starting the RTOS, everything works.

Fred
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Jul 30 01:14:19 MST 2012
You are almost certainly overflowing your stack, causing it to overwrite some other data some other data in you system.
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by  on Mon Jul 30 00:46:52 MST 2012
I have the following page on debugging hard faults on M3/4, although I'm not sure how much is consistent with the M0:

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

If you think your issue might be related to your use of the RTOS then there is also the following page for a start:

http://www.freertos.org/FAQHelp.html
0 Kudos
Reply

3,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OXO on Mon Jul 30 00:13:14 MST 2012
Post your code. It's impossible to help without seeing it..
0 Kudos
Reply