How to use Math Library in MQX KSDK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use Math Library in MQX KSDK

3,005 Views
homarpizar
Contributor I

When I try to use any function of the Math.h using KDS MQX, when I compile it show me next error:

 

62793_62793.pngpastedImage_1.png

I´d already included the <math.h> library.

 

Does someone knows how can i solve this problem?

Original Attachment has been moved to: dac_adc_1.zip

Labels (1)
0 Kudos
Reply
12 Replies

2,094 Views
ivadorazinova
NXP Employee
NXP Employee

Hello Homar,

please, what do you try for the project? Can you upload it? Or can you send the part of code where you include the Math.h ?

Best Regards,

Iva

0 Kudos
Reply

2,094 Views
homarpizar
Contributor I

Hi Iva,

Sure, I've already upload the project.

The problem occurs in the main.c at the line 314.

If it could help, I based the project on the next article:

How To: Create a New MQX RTOS for KSDK Project in KDS

Regards.

Omar.

0 Kudos
Reply

2,094 Views
ivadorazinova
NXP Employee
NXP Employee

Hello Homar,

I´m sorry for my late response. Please, can you try CMSIS library?

Math library is optimized for the M4 core and uses M4 core instructions.

Tutorial: Using the ARM CMSIS Library | MCU on Eclipse

Let me know, if it helps.

Best Regards,

Iva

0 Kudos
Reply

2,094 Views
homarpizar
Contributor I

Hi, Iva.

I just watch something weird, when I use any function of <math.h> if I use :

sqrt(100);

Everything it´s OK, the project runs normally.

But when I use:

variable=100;

root= sqrt(variable);

The project doesn't runs.

Could you help me?

Best Regarts.

Omar

0 Kudos
Reply

2,094 Views
BlackNight
NXP Employee
NXP Employee

Hi Omar,

have you included math.h with

#include <math.h>

?

And if you compile your code, there are no compiler warnings?

And what does mean "the project doesn't run" exactly?

Thanks,

Erich

0 Kudos
Reply

2,094 Views
homarpizar
Contributor I

Hello Erich,

I included math.h with #include <math.h>.

Despite that, if I use any math function like this:

variable=100;

root= sqrt(variable);

When I compile, it appears:

pastedImage_1.png

But if I want to use constants as parameter or when the parameter it´s declared as " #define PARAM 100", like this:

sqrt(100);

or

#define PARAM 100

...

...

...

sqrt(PARAM);

And then I compile, no errors or warnings appearing.

I have done each step following this: How To: Create a New MQX RTOS for KSDK Project in KDS  and I´m using the FRDM-K64.

I hope you can help me.

Thanks.

Omar

0 Kudos
Reply

2,094 Views
BlackNight
NXP Employee
NXP Employee

Hi Omar,

can you share what is shown in the Console view (build output)?

The console view shows more details than the Problems view.

Erich

0 Kudos
Reply

2,094 Views
homarpizar
Contributor I

Hello Erich,

Here is the result of the console view:

'Building target: K64_MQX_KSDK_Example.elf'

'Invoking: Cross ARM C++ Linker'

arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections  -g3 -T C:\Freescale\KSDK_1.2.0\platform\devices\MK64F12\linker\gcc\MK64FN1M0xxx12_flash.ld -nostartfiles -nodefaultlibs -Xlinker --gc-sections -LC:\Freescale\KSDK_1.2.0\lib\ksdk_mqx_lib\kds\K64F12\debug -LC:\Freescale\KSDK_1.2.0\rtos\mqx\lib\frdmk64f.kds\debug\mqx_stdlib -LC:\Freescale\KSDK_1.2.0\rtos\mqx\lib\frdmk64f.kds\debug\mqx -Wl,-Map,"K64_MQX_KSDK_Example.map" -Xlinker --cref -Xlinker -static  -Xlinker -z -Xlinker muldefs  -Xlinker --undefined=__isr_vector  -Xlinker --defsym=__stack_size__=0x400  -Xlinker --defsym=__heap_size__=0x200 -o "K64_MQX_KSDK_Example.elf"  ./Sources/LED_RGB.o ./Sources/fsl_pit_irq.o ./Sources/main.o ./Sources/pdb_trigger.o  ./KSDK_Files/board.o ./KSDK_Files/gpio_pins.o ./KSDK_Files/pin_mux.o  ./Debug_Console/fsl_debug_console.o ./Debug_Console/fsl_misc_utilities.o ./Debug_Console/print_scan.o  ./BSP_Files/init_bsp.o ./BSP_Files/mqx_main.o  C:/Freescale/KSDK_1.2.0/lib/ksdk_mqx_lib/kds/K64F12/debug/libksdk_platform_mqx.a C:/Freescale/KSDK_1.2.0/rtos/mqx/lib/frdmk64f.kds/debug/mqx_stdlib/lib_mqx_stdlib.a C:/Freescale/KSDK_1.2.0/rtos/mqx/lib/frdmk64f.kds/debug/mqx/lib_mqx.a -lksdk_platform_mqx -l_mqx_stdlib -l_mqx -lgcc -lc -lsupc++ -lm -lnosys

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libm.a(lib_a-w_sqrt.o): In function `sqrt':

w_sqrt.c:(.text.sqrt+0x40): undefined reference to `__aeabi_dcmplt'

w_sqrt.c:(.text.sqrt+0x92): undefined reference to `__aeabi_ddiv'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libm.a(lib_a-e_sqrt.o): In function `__ieee754_sqrt':

e_sqrt.c:(.text.__ieee754_sqrt+0x156): undefined reference to `__aeabi_dmul'

e_sqrt.c:(.text.__ieee754_sqrt+0x15e): undefined reference to `__aeabi_dadd'

e_sqrt.c:(.text.__ieee754_sqrt+0x182): undefined reference to `__aeabi_dsub'

e_sqrt.c:(.text.__ieee754_sqrt+0x18a): undefined reference to `__aeabi_ddiv'

collect2.exe: error: ld returned 1 exit status

make: *** [K64_MQX_KSDK_Example.elf] Error 1

Thanks for helping.

Omar

0 Kudos
Reply

2,094 Views
BlackNight
NXP Employee
NXP Employee

It is a problem of your linker settings. You have both -nostartfiles and -nodefaultlibs enabled, so the linker does not link with the standard libraries (which include the math functions).

Try these settings:

pastedImage_0.png

I hope this helps,

Erich

0 Kudos
Reply

2,094 Views
homarpizar
Contributor I

I tried as you show me,

But now it is shown:

'Building target: K64_MQX_KSDK_Example.elf'

'Invoking: Cross ARM C++ Linker'

arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections  -g3 -T C:\Freescale\KSDK_1.2.0\platform\devices\MK64F12\linker\gcc\MK64FN1M0xxx12_flash.ld -Xlinker --gc-sections -LC:\Freescale\KSDK_1.2.0\lib\ksdk_mqx_lib\kds\K64F12\debug -LC:\Freescale\KSDK_1.2.0\rtos\mqx\lib\frdmk64f.kds\debug\mqx_stdlib -LC:\Freescale\KSDK_1.2.0\rtos\mqx\lib\frdmk64f.kds\debug\mqx -Wl,-Map,"K64_MQX_KSDK_Example.map" -Xlinker --cref -Xlinker -static  -Xlinker -z -Xlinker muldefs  -Xlinker --undefined=__isr_vector  -Xlinker --defsym=__stack_size__=0x400  -Xlinker --defsym=__heap_size__=0x200 -o "K64_MQX_KSDK_Example.elf"  ./Sources/main.o  ./KSDK_Files/board.o ./KSDK_Files/gpio_pins.o ./KSDK_Files/pin_mux.o  ./Debug_Console/fsl_debug_console.o ./Debug_Console/fsl_misc_utilities.o ./Debug_Console/print_scan.o  ./BSP_Files/init_bsp.o ./BSP_Files/mqx_main.o  C:/Freescale/KSDK_1.2.0/lib/ksdk_mqx_lib/kds/K64F12/debug/libksdk_platform_mqx.a C:/Freescale/KSDK_1.2.0/rtos/mqx/lib/frdmk64f.kds/debug/mqx_stdlib/lib_mqx_stdlib.a C:/Freescale/KSDK_1.2.0/rtos/mqx/lib/frdmk64f.kds/debug/mqx/lib_mqx.a -lksdk_platform_mqx -l_mqx_stdlib -l_mqx -lgcc -lc -lsupc++ -lm -lnosys

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-signalr.o): In function `_kill_r':

signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-signalr.o): In function `_getpid_r':

signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-closer.o): In function `_close_r':

closer.c:(.text._close_r+0xc): undefined reference to `_close'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-fstatr.o): In function `_fstat_r':

fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-isattyr.o): In function `_isatty_r':

isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'

c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-lseekr.o): In function `_lseek_r':

lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'

collect2.exe: error: ld returned 1 exit status

make: *** [K64_MQX_KSDK_Example.elf] Error 1

0 Kudos
Reply

2,094 Views
BlackNight
NXP Employee
NXP Employee

It seems that this MQX project somehow has additional dependency e.g. on some I/O functions.

I see you have

-lnosys

in your linker flags: try to remove that option and instead link with the system library?

Erich

0 Kudos
Reply

2,094 Views
homarpizar
Contributor I

I removed nosys from the Cross ARM C++ Linker Libraries, but I don´t know how to link with the system library.

Can you help me, please?

Omar

0 Kudos
Reply