cancel
Showing results for 
Search instead for 
Did you mean: 

arm_sqrt_f32 and arm_math.h

d4
Associate III

Hi, I'm using Cube and Makefile.

I'd like a clearer run through of how to make use of the sqrt f32 function in arm_math.h.

. The header doco says to copy the header to Include, done.

. Then link the Lib for big/little endian. Here's where I'm stuck, how do I link the Lib and which endian do I use? I have an STM32F303VB.

. And then how exactly do I setup the variablesin main.c for use of arm_sqrt_f32() in, for example, the while loop?

Regards,

Dan

8 REPLIES 8
Ozone
Lead

I only used the CMSIS DSP lib with SPL.

However, I always had to add the implementation (*.c file containing e.g. the sqrtf() function) to the build as well. This would solve any endianess question, BTW.

I don't want to get involved in the Cube mess. Consult the tutorials/help of your unnamed toolchain on how to include link libs, and what libs it provides.

You're using Little Endian devices.

The libraries are either pre-built or you need to make them from the component parts. The resulting .o or .lib added to the project, or too the list of objects passed to the linker.

Alternatively you can add the source files to the project and let the compiler and linker figure it out. Libraries tend to allow for selective pull of functions and dependencies.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Bassett.David
Senior

Hello,

As "sqrtf" is a standard C library function, simply including math.h should be sufficient. Other standard library functions, string ones for example, may be used by including string.h - the tool chain should resolve the references and add the necessary code images to the link. I can verify that Keil operates in this manner.

Besides, the actual file names for specific library functions are often rather bizarre and it might be difficult to determine which one(s) are needed anyways. Let the tool chain take care of it for you!?

Regards,

Dave

Hello again,

BTW, if you specify "--fpmode=fast" to the compiler, sqrtf() produces a single instruction, inline (12 - 14 cycles).

The OP's questions seems to focus on arm_sqrt_f32(), a function from ARM's DSP lib.

d4
Associate III
mckenney
Senior

The library is probably named "arm_cortexM4lf_math.a", where the "l" is little-endian and the "f" is "float" (as opposed to "d" for double).

Here's something non-obvious: Before you #include <arm_math.h>" be sure to "#define ARM_MATH_CM4 1" or you'll get arcane compilation errors. (It may or may not already be #define-ed.)

As a practical matter: If you spend more than a few minutes trying to find the .a file, it might be quicker to download the source from arm.com and copy the .c file(s) you're interested in right into your project. The ones I've done this with were all free-standing.

If you Google "arm_sqrt_f32" it will probably take you to the API document pages at arm.com. For something relatively simple like sqrt, that's probably enough to get you started.

d4
Associate III

I believe this was doing it in the end. Not strictly tested in terms of speed.

Compile flag:

# float-abi

FLOAT-ABI = -mfloat-abi=hard

Tells the compiler to get as much float math done in hardware, as far as I know.