cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler exception...

yoav
Associate II
Posted on May 16, 2013 at 13:53

Hello,

I'm using the STM32F4 on the discovery evaluation board.

I wrote a simple function that calculates the mean of a vector. When the code is starting to make the summation it goes to HardFault_Handler...

Here is the mean function, a moment before the exception:

0690X00000604sxQAA.png

When I hit F10, the code goes to void HardFault_Handler(void) at stm32f4xx_it.c.

Here is the call of the function:

SNR = CalcMean((float*)local_data_buffer.data_struct.handVISNRBuff,5);

Any Ideas?!

Thanks!

Yoav

#hardfault_handler
10 REPLIES 10
Posted on May 16, 2013 at 14:38

Hard to say, you should be using a decent Hard Fault handler.

Check the array, and the scope of access (n).

You want to look at the assembler code that faulted. If you're using the FPU, you need to ensure it is enabled (typically in SystemInit()), otherwise the CPU will fault on FPU instructions.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/How%20to%20debug%20hard%20fault%20handler%20exceptions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=411]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FHow%20to%20debug%20hard%20fault%20handler%20exceptions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=411
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cm600
Associate II
Posted on May 16, 2013 at 15:29

Are you sure that the FPU  is enabled?

SCB->CFSR bit NOCP should be 0 when you are in the Hard_Fault handler

yoav
Associate II
Posted on May 16, 2013 at 18:14

How do I enable the FPU?

Posted on May 16, 2013 at 18:27

How do I enable the FPU?

I'm going to guess you're not using Keil, where you'd check ''Use FPU'' You will have to check your IDE documentation, and ensure your project has the suitable defines passed to the compiler. From system_stm32f4xx.c, and SystemInit()

void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yoav
Associate II
Posted on May 16, 2013 at 23:47

Thanks for the help, but still no luck...

I'm using IAR, and the FPU settings are present in the system_stm32f4xx.c file.

Any other ideas?

Thanks!

Posted on May 17, 2013 at 00:20

Any other ideas?

Then after you've checked the defines, and breakpointed this instruction, you'll need to identify the assembler instruction which is actually faulting, and the registers and processor context at the fault. Once you've done that you'll be in a position to diagnose the problem.

General causes:

Stack too small, or corrupted

Touching the wrong memory area

Trying to execute 32-bit ARM instructions

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yoav
Associate II
Posted on May 20, 2013 at 12:18

Hi again,

Attached is a print screen of the code, registers, locals, and assembly code.

When I hit F10 I get the hard fault exception.

I'll appreciate your help.

Thanks,

Yoav

0690X00000602oRQAQ.jpg

Posted on May 20, 2013 at 16:58

Honestly it still looks to be a problem with the FPU.

Check SCB->CPACR

Check __FPU_PRESENT and __FPU_USED defines.

In main(), something like

  printf(''CPACR:%08X  FPU:%d %d\n'', SCB->CPACR, __FPU_PRESENT, __FPU_USED};

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yoav
Associate II
Posted on May 21, 2013 at 11:16

Hi again, 

Checked it, but it looks fine.

Here is the Terminal output:

CPACR:00F00000  FPU:1 1

Other ideas, please...?

Many thanks,

Yoav