Page 1 of 1

STM32F4 discovery floating point

Posted: Tue May 08, 2012 6:18 pm
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.

Re: STM32F4 discovery floating point

Posted: Tue May 08, 2012 6:20 pm
by pjohnson
Sorry, I should add that I am compiling using gcc 4.6 from CodeSourcery.

Re: STM32F4 discovery floating point

Posted: Tue May 08, 2012 6:44 pm
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

Re: STM32F4 discovery floating point

Posted: Tue May 08, 2012 7:13 pm
by pjohnson
I must be getting bug 3513897, my code is in main.

I will give the svn version a try.

Re: STM32F4 discovery floating point

Posted: Wed May 09, 2012 2:30 pm
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.

Re: STM32F4 discovery floating point

Posted: Wed May 09, 2012 3:04 pm
by Giovanni
That is probably related to the library, you should give that other GCC toolchain a try.

Giovanni