Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
I tried it but it seems to be undefined. What is the name of such a function in Dave3/XMC4500 please?

Thanks!
0 Likes
7 Replies
Not applicable
Hi BMS,

The sqrt function is available under DSP_Lib in the CMSIS folder.
If you go to C:\DAVE-3.1\CMSIS\DSP_Lib\Source\FastMathFunctions\ you should able to find the source file for sqrt function.
0 Likes
Not applicable
Thank you very much Jackson! However, when I tried to use the arm_sqrt_q15 function, I encountered the following error.

C:\DAVE-3.1\CMSIS\Include\arm_math.h:268:20: fatal error: ARMCM4.h: No such file or directory

I searched in the DAVE-3.1 folder but couldn't find this header file.

Thanks!
0 Likes
Not applicable
Hi BMS,

What you need to do is to add "ARM_MATH_CM4" in the preprocessor, which is in Project -> Active Project Properties -> C/C++ Build -> Setting -> ARM-GCC C Compiler.
Once you added this, you should be able to run the arm_math.
This way, you are using the math functionality provided by ARM CMSIS.

There is another way to get the sqrt function which is much easier and I should have told you previously.
In DAVE3, it is already include newlib library where math functionality is included.
You can find more information here: http://sourceware.org/newlib/libm.html

Therefore what you need to do is
     
#include "math.h"

and you can use the function

double sqrt(double x);
float sqrtf(float x);
0 Likes
Not applicable
Thank you so much Jackson for the clear explanation. It works.

Cheers
0 Likes
User6412
Level 4
Level 4
I have included "math.h" as you noted like this:

#include //Declarations from DAVE3 Code Generation (includes SFR declaration)
#include "math.h"

int main(void)
{
// status_t status; // Declaration of return variable for DAVE3 APIs (toggle comment if required)


DAVE_Init(); // Initialization of DAVE Apps


while(1)
{
float a = 1.0f;
float b = 3.14f;
for(long i = 0; i < 1000000; i++) {
a = sqrtf(a + b);
}
if(a > 0)
IO004_TogglePin(IO004_Handle0);
}
return 0;
}


But there is a build error:


Main.o: In function `main':
C:\Development\Dave\performance\Release/../Main.c:28: undefined reference to `sqrtf'
collect2: ld returned 1 exit status
make: *** [performance.elf] Error 1

**** Build Finished ****


What is wrong?
0 Likes
Not applicable
Hi,

What you need to do is to add "m" in Libraries.
Go to Project -> Active Project Properties -> C/C++ Build -> Settings -> ARM-GCC C Linker, add "m" in the Libraries (-l)
200.attach

Best regards,
Sophia
0 Likes
User6412
Level 4
Level 4
Thanks! It works!
0 Likes