cancel
Showing results for 
Search instead for 
Did you mean: 

Undefined reference to `sqrtf' - STM32F4 DSP library

Thomas Jespersen
Associate III
Posted on August 17, 2012 at 18:13

Hi there.

I am trying to get the STM32F4 DSP library to work together with the CoIDE (

http://www.coocox.org

).

Currently I have compiled the DSP math library with GCC using Keil, where I opened the GCC library project.

I've then added the compiled library file, libarm_cortexM4lf_math.a, to the CoIDE project together with the FFT example source code.

I've set the proper definitions: ARM_MATH_CM4, ARM_MATH_MATRIX_CHECK, ARM_MATH_ROUNDING, __FPU_USED

and also selected the ''FPU hard'' compiler command.

Though when I try to compile the project the GCC linker gives me the following error:

      [cc] arm-none-eabi-gcc -O0 -nostartfiles -Wl,-Map=STM32F4_FFT.map -mcpu=cortex-m4 -mthumb -LC:\CooCox\CoIDE\workspace\STM32F4_FFT -Wl,--gc-sections -Wl,-TC:\CooCox\CoIDE\workspace\STM32F4_FFT\arm-gcc-link.ld -g -o STM32F4_FFT.elf ..\obj\arm_fft_bin_example_f32.o ..\obj\startup_stm32f4xx.o ..\obj\stm32f4xx_rcc.o ..\obj\stm32f4xx_gpio.o ..\obj\system_stm32f4xx.o ..\obj\syscalls.o ..\obj\arm_fft_bin_data.o ..\obj\misc.o -L..\.. -larm_cortexM4lf_math

       [cc] C:\CooCox\CoIDE\workspace\STM32F4_FFT\libarm_cortexM4lf_math.a(arm_cmplx_mag_f32.o): In function `arm_sqrt_f32':

       [cc] C:\STM32F4xx_DSP_StdPeriph_Lib_V1.0.1\Libraries\CMSIS\DSP_Lib\Source\GCC/../../../Include/arm_math.h:5705: undefined reference to `sqrtf'

What can I do about the undefined reference to 'sqrtf'? If I try to use the sqrtf function in my main.c file it doesn't give me any errors as long as I remember ''&sharpinclude ''math.h''.

Has it something to do with the compiling of the library in Keil and then imported into CoIDE (but I used same toolchain)? Maybe something with the folder structure?

The complete project can be found in the following zip file: 

http://www.tkjelectronics.dk/uploads/STM32F4_FFT_CoIDE.zip

Thank you in advance.

Best Regards

Thomas Jespersen

#stm32f4-dsp
7 REPLIES 7
Posted on August 18, 2012 at 01:31

Isn't sqrtf() in arm-none-eabi\lib\thumb\v7m\libm.a ?

I'm having deja-vu here, I know I've built a version of the DSP library directly with GNU/GCC and uploaded it here. I'll have to see if I can find it.

If you suspect Keil is the problem, build the library in CooCox or directly with GNU/GCC
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
frankmeyer9
Associate II
Posted on August 18, 2012 at 09:12

If I'm not totally wrong, sqrt (and sqrtf) reside in libm.a, but I can nowhere detect a '-lm' among the compiler/linker flags.

Perhaps you need to add it manually to the project settings.

Posted on August 20, 2012 at 18:53

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Building CMSIS DSP_LIB for GCC&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=176]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FBuilding%20CMSIS%20DSP_LIB%20for%20GCC&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=176

arm_math.h has arm_sqrt_f32() which uses your current libraries' sqrtf()
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Thomas Jespersen
Associate III
Posted on August 24, 2012 at 09:24

Now I finally succeeded compiling the project with the FPU-hard selected.

I had to manually copy the libm.a, libg.a and libc.a from the GCC\lib\armv7e-m\fpu folder to the project folder to avoid any VFP problems.

But now when I run the project I goes to the Default Handler when running this line: arm_cfft_radix4_f32(&S, testInput_f32_10khz); 

The project, as it is now can be downloaded here: 

http://www.tkjelectronics.dk/uploads/STM32F4_FFT_CoIDE_V2.zip

Thanks.

frankmeyer9
Associate II
Posted on August 24, 2012 at 10:52

I had to manually copy the libm.a, libg.a and libc.a from the GCC\lib\armv7e-m\fpu folder to the project folder to avoid any VFP problems.

 

That's not the best way. You could have added ''GCC\lib\armv7e-m\fpu'' to the the library search path, and just add ''-lm'' to your build options.

But now when I run the project I goes to the Default Handler when running this line: arm_cfft_radix4_f32(&S, testInput_f32_10khz);

 

 

I suggest to step into this function, to get closer to the offending expression/instructions.

 

Perhaps the FPU is not enabled, or just a plain stack overflow.

Thomas Jespersen
Associate III
Posted on August 26, 2012 at 00:06

I have tried stepping into the function, which contains these lines of code.

And you were right, it appeared that it stopped because of the FPU not being enabled in the System initialization (startup code).

Now when it is enabled the example works and calculates the FFT max index as it should = 213.

But now my question is how this FFT calculation works with my own samples, as it seems to return an odd maximum number - which did work when calculated on the STM32F103 with the DSP library on that.

I am calculating the samples array using the sinf() function with a set sampling frequency and wanted wave frequency.

Then from the maximum index calculated from the FFT I should be able to calculate the specific frequency which is the maximum by using the known sampling frequency.

Though when I do this there is always one single item in the calculated FFT output that is higher than the frequency I have put in, like a harmonic frequency - but why is this FFT output value then higher than the one on the index for the input frequency?

Because the number in the FFT output array that is just lower than the highest one is correctly placed inside the index that matches the input frequency.

Thanks for your help.

frankmeyer9
Associate II
Posted on August 26, 2012 at 12:34

Your question concerning FFT is not so easy to understand for me, but as I get it, your frequency maximum is not where you expect it.

Have you tried a reference transformation with an external math tool ?

I had used Extrema for that, both viewing the sample vector, and the spectre. And I compared the spectres from the stm32f4 app. with that calculated by Extrema.

Are you sure to expect the maxima at the correct place, considering the FFT size and sampling frequency ?

As I understood it, the arm_cfft_radix4_f32() function 'skips' the negative half of the spectre, just returning [0 ... fs/2].