cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with math.h and Codesourcery

christoph239955_stm1
Associate II
Posted on November 30, 2009 at 14:19

Problems with math.h and Codesourcery

4 REPLIES 4
christoph239955_stm1
Associate II
Posted on May 17, 2011 at 13:28

Hi,

I've to use some functions of the math-library. Therefore, I included the math.h and added the linker option -lm. Compiling and linking works without an error or warning, but when the controller (STM32F103RE) reaches the first instruction of the math-library, an hardfault-exception occurs.

Has anyone a solution for this problem? I'm using the codesourcery compiler and linker.

Best regards,

Christoph

janvi
Associate II
Posted on May 17, 2011 at 13:28

recently I had similar problems with other GCC and lib. If there are no warnings in compile, this means, that app and lib are compiled in same manner but does not make shure this is correct for STM32.

E.g. the -mfpu=vfp switch instructs the compiler to use instructions for hardware floating point. There is no impact to your app until compiler really uses such instruction (what will end in a exception for STM32)

Make shure, your app (and lib) has been compiled for software float point. If no default, it is either the -msoft-float or -mfloat-abi=soft switch. Probably there are further diffrent stack orders and float formats possible with the GCC.

Make shure, your search path in the linker file points to directory of correct version of libm.a what should be normally the version compiled for ARMv7, Thumb2, no interwork, little endian, software float to be compatible for STM32.

If you have the things workig, it would be interesting how much the lib code contributes using printf with integer and / or float conversion.

thorsten2
Associate II
Posted on May 17, 2011 at 13:28

Hi,

I think I have the same problem

http://www.st.com/mcu/forums-cat-9204-23.html

Can you help me what I have to change in the makefile.

Many thanks!

Regards,

Thorsten

christoph239955_stm1
Associate II
Posted on May 17, 2011 at 13:28

Thanks for your answer, although I found a different solution: I added the MCU and the Thumb-Mode to the linker options, compiled it using the codesourcery-gcc, and it runs. Without these options, the wrong libraries are linked.