Arithmetic on STM32F4xx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-01-16 7:24 AM
Hi All! I have some issue, when I make an arithmetic operations using my STM32F4 Discovery.
simple example:float a = 3.2, b = 2.5, c = 0;c= a +b; When I run this code, I get Hard Fault Exception.What possible reasons? How i can operate with float type. I'm using Keil on Windows 7.Thanks. #floating-point- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-01-16 7:34 AM
So what instruction is faulting? That might give you an idea as to what the problem is. Try single stepping the code, or examining the CPU state, and stacked context in the fault handler.
If you are using FPU instructions, the FPU must be enabled on the processor. This is usually done in SystemInit() or ResetHandler. Perhaps you can provide a more complete example? The system will probably hard fault if you exit from main()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-01-16 12:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-01-16 2:10 PM
The C code really doesn't help me much, you need to be stepping through the disassembler window, and display the physical instructions that are causing the fault.
If you are executing floating-point unit (FPU) specific instructions, and they fail, it is probably because the unit has not been enabled. From STM32F4-Discovery_FW_V1.1.0\Libraries\CMSIS\ST\STM32F4xx\Source\Templates\system_stm32f4xx.cvoid 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-01-16 8:48 PM
clive1, it's helped.
In Target settings was set flag Use FPU. But it doesn't worked. When i added your code in SystemInit(), issue was gone. Thanks! WBR, Ramil.