Page 1 of 1

STM32F4 hard fault error when using floating point

Posted: Wed Mar 18, 2015 8:44 pm
by Luyso
Hi, I'm using the Keil compiler with the discovery board. Each time I try to convert between float and integers the system goes to the hard fault error handler.

I've just tried modifying any RT-Druid demo with the code below, and the same error always occurs:

Code: Select all

TASK(TaskLedBlink)
{
	int a = 2;
	float b = 1.99;
	
	STM_EVAL_LEDToggle(LED4);
	b = (float) a;
}
I guessed that the error was related with the FPU enabling, but now I'm not sure anymore.

Can anyone try to implement that code and confirm to me that I'm the only one getting this problem?

Thanks.

Re: STM32F4 hard fault error when using floating point

Posted: Thu Mar 19, 2015 10:50 am
by outlawch
Hi Luyso,
unfortunately there's NOT floating point support in the CORTEX_MX arch of Erika Enterprise.
If you need to use floating point, you SHOULD use the software support offered by KEIL compiler.

Ciao.

Re: STM32F4 hard fault error when using floating point

Posted: Thu Mar 19, 2015 5:00 pm
by Luyso
Well, that's weird because I can implement filters using floating point signals without any troubles.

The error occurs only when I try to convert between formats.

Re: STM32F4 hard fault error when using floating point

Posted: Thu Mar 19, 2015 5:09 pm
by gfranchi
We had a similar problem. To fix it, we changed the following compiler option to enable the hardware FPU: from --cpu Cortex-M4 to --cpu Cortex-M4.fp.

In particular, you have to edit the file "cc_cortex_m4_keil.mk" located in " $(EEBASE)/pkg/cfg/arch" by changing the following lines:

OPT_CC += --cpu Cortex-M4 becomes OPT_CC += --cpu Cortex-M4.fp,
OPT_ASM += --cpu Cortex-M4 becomes OPT_ASM += --cpu Cortex-M4.fp
OPT_LINK += --cpu Cortex-M4 becomes OPT_LINK += --cpu Cortex-M4.fp

Hope this helps.

Gianluca.

Re: STM32F4 hard fault error when using floating point

Posted: Thu Mar 19, 2015 5:23 pm
by paolo.gai
Good to know...

Luyso... could you please check the solution suggested by Gianluca?

Luyso, Gianluca, could you add a note about this on the Cortex-MX wiki page?

Ciao,

PJ

Re: STM32F4 hard fault error when using floating point

Posted: Thu Mar 19, 2015 6:04 pm
by Luyso
Hi Gianluca, actually it was me. That solution seemed to work for a short time, but when I continued coding the error suddenly appeared again. I didn't modify any configuration parameters, just adding new functions. Now, coming back to the initial code the error is still there.

Just to discard it was a local problem, we have tried to compile the same code using both compiler options (--cpu Cortex-M4 and --cpu Cortex-M4.fp.) in other machine and the error is there.