HardFault_Handler exception...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 4: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:- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 5: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=411Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 6:29 AM
Are you sure that the FPU is enabled?
SCB->CFSR bit NOCP should be 0 when you are in the Hard_Fault handler- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 9:14 AM
How do I enable the FPU?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 9: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
..
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 2: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!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-16 3: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 instructionsUp vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-20 3: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,Yoav- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-20 7: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};Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-05-21 2: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