cancel
Showing results for 
Search instead for 
Did you mean: 

Arithmetic on STM32F4xx

FLast.18
Associate II
Posted on January 16, 2013 at 16:24

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
4 REPLIES 4
Posted on January 16, 2013 at 16:34

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()
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FLast.18
Associate II
Posted on January 16, 2013 at 21:04

0690X00000605UQQAY.png

On the picture you can see point where occurs hardfault exception( line 382 ).

Have you any ideas?

Posted on January 16, 2013 at 23:10

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.c

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..
FLast.18
Associate II
Posted on January 17, 2013 at 05:48

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.