STM32F4 discovery floating point

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
pjohnson
Posts: 5
Joined: Tue May 08, 2012 6:10 pm

STM32F4 discovery floating point

Post by pjohnson »

I added a floating point divide to the STM32F4 discovery example from chibios 2.4.0. It throws me into the exception handler.

My code looks like this,

float xg;
short z;

z = 1000;
xg = (float)z/22.5f;

The exception happens at the divide.

Thanks in advance for your help.
pjohnson
Posts: 5
Joined: Tue May 08, 2012 6:10 pm

Re: STM32F4 discovery floating point

Post by pjohnson »

Sorry, I should add that I am compiling using gcc 4.6 from CodeSourcery.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 discovery floating point

Post by Giovanni »

Hi,

Please also make sure to set CORTEX_USE_FPU to TRUE in chconf.h.

If you already did that then there are two possible explanations:

1) You are hitting bug 3513897. The workaround is to not put FP code in the main() function, it will be fixed in 2.4.1 (already fixed in SVN).

2) Please look at the compiled asm code, it is possible that the compiler inserts a call to a library function, codesourcery does not have yet libraries properly compiled for the CM4 FPU. If this is the case you can try the following GCC based toolchain that should have properly compiled libraries: https://launchpad.net/gcc-arm-embedded

Giovanni
pjohnson
Posts: 5
Joined: Tue May 08, 2012 6:10 pm

Re: STM32F4 discovery floating point

Post by pjohnson »

I must be getting bug 3513897, my code is in main.

I will give the svn version a try.
pjohnson
Posts: 5
Joined: Tue May 08, 2012 6:10 pm

Re: STM32F4 discovery floating point

Post by pjohnson »

Turning on CORTEX_USE_FPU and moving to the svn version did the trick.

Now I am having problems with atan2f giving funny results, but I don't think it is Chibios related.

Thanks for your help.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 discovery floating point

Post by Giovanni »

That is probably related to the library, you should give that other GCC toolchain a try.

Giovanni
Post Reply