STM32F4 hard fault error when using floating point

Forum related to ERIKA Enterprise and RT-Druid version 2

Moderator: paolo.gai

Post Reply
Luyso
Newbie
Posts: 3
Joined: Sat Feb 28, 2015 6:20 pm

STM32F4 hard fault error when using floating point

Post by Luyso » Wed Mar 18, 2015 8:44 pm

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.

outlawch
Newbie
Posts: 17
Joined: Fri Apr 27, 2012 9:11 pm
Location: Pisa
Contact:

Re: STM32F4 hard fault error when using floating point

Post by outlawch » Thu Mar 19, 2015 10:50 am

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.

Luyso
Newbie
Posts: 3
Joined: Sat Feb 28, 2015 6:20 pm

Re: STM32F4 hard fault error when using floating point

Post by Luyso » Thu Mar 19, 2015 5:00 pm

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.

gfranchi
Newbie
Posts: 7
Joined: Thu Sep 20, 2007 5:12 pm

Re: STM32F4 hard fault error when using floating point

Post by gfranchi » Thu Mar 19, 2015 5:09 pm

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.

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: STM32F4 hard fault error when using floating point

Post by paolo.gai » Thu Mar 19, 2015 5:23 pm

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

Luyso
Newbie
Posts: 3
Joined: Sat Feb 28, 2015 6:20 pm

Re: STM32F4 hard fault error when using floating point

Post by Luyso » Thu Mar 19, 2015 6:04 pm

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.

Post Reply