2013-05-16 04:53 AM
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: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_handler2013-05-16 05:38 AM
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¤tviews=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=4112013-05-16 06:29 AM
Are you sure that the FPU is enabled?
SCB->CFSR bit NOCP should be 0 when you are in the Hard_Fault handler2013-05-16 09:14 AM
How do I enable the FPU?
2013-05-16 09:27 AM
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
..
2013-05-16 02:47 PM
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!2013-05-16 03:20 PM
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 instructions2013-05-20 03:18 AM
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,Yoav2013-05-20 07:58 AM
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};2013-05-21 02:16 AM
Hi again,
Checked it, but it looks fine.Here is the Terminal output:CPACR:00F00000 FPU:1 1Other ideas, please...?Many thanks,Yoav