Math function problem

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've got a program that uses sin, cos, pow, and sqrt functions to calculate IIR filter coefficients based on specifications. Although the math.h include file has definitions for these the linker complains:

    Severity and Description Path Resource Location Creation Time Id
    undefined reference to `cos' Seneca libfilters.c line 664 1185678363046 49100
    undefined reference to `pow' Seneca libfilters.c line 664 1185678363046 49101
    undefined reference to `sin' Seneca libfilters.c line 664 1185678363046 49099
    undefined reference to `sqrt' Seneca libfilters.c line 459 1185678363046 49098

Can anyone verify if these functions are supposed to be available for the AVR32UC3A?

In a related note, is the source for the C library available, stuff like floating point operations on the AVR32? I found those very helpful when I was doing ADSP-2189 development.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you used -lm in the linker command line to link in the maths library?

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, the source code for the AVR32 C library is available. It's called uClibc. Take a look at http://www.uclibc.org/ and https://www.avrfreaks.net/wiki/in...

Edit: While uclibc does include floating point support, it does not include all the math functions of libm that Leon referenced.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

uClibc runs on top of Linux, for UC3 dev the library to use is Newlib but doesn't have AVR32 optimized floating point.

I don't know of any optimized libraries around, maybe someone else has more details.

-S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My mistake, I thought this was the AVR32 Linux forum. Thanks, Squidgit!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

certsoft wrote:
I've got a program that uses sin, cos, pow, and sqrt functions to calculate IIR filter coefficients based on specifications. Although the math.h include file has definitions for these the linker complains:
...
Can anyone verify if these functions are supposed to be available for the AVR32UC3A?

I've made a test example with calls to sin, cos, pow and sqrt running on the EVK1100, printing results to USART0. Looks ok. Which compiler are you using?

certsoft wrote:

In a related note, is the source for the C library available, stuff like floating point operations on the AVR32? I found those very helpful when I was doing ADSP-2189 development.

I don't know if you're using GCC, but the source code for the 1.1.0 AVR32 GNU Toolchain is here: http://www.atmel.com/dyn/resources/prod_documents/avr32_gnu_toolchain_source_1.1.0.zip
I never took the time to look into it, but this should contain the floating point operations emulation.

Cyr.
.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cboulang wrote:

I've made a test example with calls to sin, cos, pow and sqrt running on the EVK1100, printing results to USART0. Looks ok. Which compiler are you using?

Gcc. Did you add anything to the linker options in AVRStudio?

Quote:

I don't know if you're using GCC, but the source code for the 1.1.0 AVR32 GNU Toolchain is here: http://www.atmel.com/dyn/resources/prod_documents/avr32_gnu_toolchain_source_1.1.0.zip
I never took the time to look into it, but this should contain the floating point operations emulation.

Thanks for the link. I'm over my download limit over the satellite for this month but will take a look at that in a couple of days. Hopefully it has the runtime support source for the compiler for stuff like floating point operations. When trying to do FIR and IIR filters you have to very careful to make sure things like multiply are done in the best way.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

certsoft wrote:
cboulang wrote:

I've made a test example with calls to sin, cos, pow and sqrt running on the EVK1100, printing results to USART0. Looks ok. Which compiler are you using?

Gcc. Did you add anything to the linker options in AVRStudio?

You mean AVR32Studio?
I added -lm (to link with the math library).

Cyr.
.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cboulang wrote:

I added -lm (to link with the math library).

Didn't help here. I tried:
1) -lm on the gcc command line.
2) -lm on the linker command line.
3) -Wl,-lm on the linker command line.

Doesn't do any good. If I can't find the magical gnu incantation I'll just translate the routines from the OmegaSoft Pascal runtime library :twisted:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is the linker command line of the example i used:

Linking to `uc3a0512-example.elf'.
avr32-gcc -march=uc -mpart=uc3a0512  -T../../../../../UTILS/LINKER_SCRIPTS/AT32UC3A/0512/GCC/link_uc3a0512.lds -Wl,--gc-sections ../../../../../DRIVERS/USART/usart.o ../../../../../DRIVERS/INTC/intc.o ../../../../../DRIVERS/GPIO/gpio.o ../../../../../DRIVERS/PM/pm.o ../../../../../UTILS/DEBUG/print_funcs.o ../../example.o ../../../../../DRIVERS/INTC/exception.o  -lm -o uc3a0512-example.elf

In case you use a Makefile/config.mk scheme (from the Software Framework), you should write a single 'm' to the LIBS variable in config.mk; the Makefile adds the -l.

Cyr.
.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cboulang wrote:

In case you use a Makefile/config.mk scheme (from the Software Framework), you should write a single 'm' to the LIBS variable in config.mk; the Makefile adds the -l.

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I have a similar problem with including math.h in AVR32 Studio.
I have tried to include math.h in source file and next to add the option -lm adding in Menù Project-> Properties -> C/C++ Build -> Tool Settings -> AVR32/GNU C Linker -> Libraries -> Libraries (-l) only the letter "m".
But when i start the Build process, in the console I have this error

Quote:
**** Build of configuration Debug for project anello ****

**** Internal Builder is used for build ****
**** NOTE: Internal Builder is experimental currently ****
avr32-gcc -LD:\Documents and Settings\Miccino\Documenti\workspace\anello -LD:\Documents and Settings\Miccino\Documenti\workspace\anello\EVK1100 -Wl,-e,_trampoline -mpart=uc3a0512 -oanello.elf usart.o trampoline.o tc.o spi.o sdramprova.o sdramc.o sdram_log.o pwm.o provva.o print_funcs.o pm.o pi.o pi+logging.o logging_sdram.o intc.o gpio.o exception.o adc.o EVK1100\led.o Campionamento fitto.o
provva.o: In function `tc_irq':
/cygdrive/d/Documents and Settings/Miccino/Documenti/workspace/anello/Debug/..\provva.c:140: undefined reference to `sin'
/cygdrive/d/Documents and Settings/Miccino/Documenti/workspace/anello/Debug/..\provva.c:140: undefined reference to `trunc'
collect2: ld returned 1 exit status
Build error occured, build is stopped

Any ideas?

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mitchcortinueviz wrote:
...
avr32-gcc -LD:\Documents and Settings\Miccino\Documenti\workspace\anello -LD:\Documents and Settings\Miccino\Documenti\workspace\anello\EVK1100 -Wl,-e,_trampoline -mpart=uc3a0512 -oanello.elf usart.o trampoline.o tc.o spi.o sdramprova.o sdramc.o sdram_log.o pwm.o provva.o print_funcs.o pm.o pi.o pi+logging.o logging_sdram.o intc.o gpio.o exception.o adc.o EVK1100\led.o Campionamento fitto.o
...
You may add the maths library in the avr32studio linker settings but the switch still isn't there on the command line. Try adding it to the C/C++ compiler page instead of the linker one.

-S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I've solved the problem disabling the Esperimental Internal Builder.

Thanks,

Mitch

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For AVR32Studio the way to enable math routines is to add a string with only letter 'm' in the pane "Libraries (-l)" in Project-> Properties -> C/C++ Build -> Settings -> Tool Settings -> AVR32/GNU C Linker -> Libraries