STM32F4 hard fault error when using floating point

Forum related to ERIKA Enterprise and RT-Druid version 2

Moderator: paolo.gai

Locked
Luyso

STM32F4 hard fault error when using floating point

Post 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.
outlawch

Re: STM32F4 hard fault error when using floating point

Post 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.
Luyso

Re: STM32F4 hard fault error when using floating point

Post 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.
gfranchi

Re: STM32F4 hard fault error when using floating point

Post 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.
paolo.gai
Administrator
Posts: 877
Joined: Thu Dec 07, 2006 12:11 pm

Re: STM32F4 hard fault error when using floating point

Post 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
Luyso

Re: STM32F4 hard fault error when using floating point

Post 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.
Locked