Using pow() breakes the building and floating_point printing errors

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

Hello everyone,

hopefully everyone is safe working in the labs. under the hood.

Since couple of days the code of mine does not build and come up with the errors below...


D:\Users\Arhitect\Documents\C_Programs\Physalis_Banshee\Physalis_GEO_version_3.8>make flash
avr-gcc -Os -g -std=gnu99 -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -DF_CPU=20000000UL -DBAUD= -I. -I../../Physalis_GEO_version_3.6 -mmcu=atmega1284p -c -o main.o main.c
main.c: In function 'secondsRun':
main.c:569: warning: format '%0.5f' expects type 'double', but argument 3 has type 'float'
avr-gcc -Wl,-Map,Physalis_GEO_version_3.8.map -Wl,--gc-sections -Wl,-u,vfprintf -lprintf_flt -lm   -mmcu=atmega1284p battery_pack.o fuse.o main.o sharp_IRED_PSD_sensor.o stepper_motor.o USART.o  -o Physalis_GEO_version_3.8.elf
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51\libc.a(floatsisf.o): In function `__floatunsisf':
(.text.avr-libc.fplib+0x0): multiple definition of `__floatunsisf'
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr51\libgcc.a(_usi_to_sf.o):c:\avrdev\gcc\build-avr\avr\avr51\libgcc/../../.././gcc/fp-bit.c:1391: first defined here
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51\libc.a(log.o): In function `log':
(.text.avr-libc.fplib+0x46): relocation truncated to fit: R_AVR_13_PCREL against symbol `__addsf3' defined in .text section in d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr51\libgcc.a(_addsub_sf.o)
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51\libc.a(log.o): In function `log':
(.text.avr-libc.fplib+0x4e): relocation truncated to fit: R_AVR_13_PCREL against symbol `__addsf3' defined in .text section in d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr51\libgcc.a(_addsub_sf.o)
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51\libc.a(pow.o): In function `pow':
(.text.avr-libc.fplib+0x94): relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text section in d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr51\libgcc.a(_mul_sf.o)
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51\libc.a(inverse.o): In function `inverse':
(.text.avr-libc.fplib+0xc): relocation truncated to fit: R_AVR_13_PCREL against symbol `__divsf3' defined in .text section in d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr51\libgcc.a(_div_sf.o)
d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51\libc.a(modf.o): In function `modff':
(.text.avr-libc.fplib+0x3e): relocation truncated to fit: R_AVR_13_PCREL against symbol `__subsf3' defined in .text section in d:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr51\libgcc.a(_addsub_sf.o)
make: *** [Physalis_GEO_version_3.8.elf] Error 1

D:\Users\Arhitect\Documents\C_Programs\Physalis_Banshee\Physalis_GEO_version_3.8>

if I remove the " x = pow(ired_range, -0.93532);" line of code, then everything is fine.

 

void secondsRun(void){                                                // small function counts seconds from Timer

    seconds_ ++;
    if(seconds_ > 59){
        seconds_ = 0;
        minutesRun();
    }

    CTRLPWM_PORT ^= (1 << GREED_LED);                                            // toggle green LED every second

    ambient_light = fetchDataADC(AMBIENT_LIGHT);                                // check ambient light conditions
    printString("ambient light = ");
    printWord(ired_range);                                           // variables swapped bc of ADC update issues
    printString("\t");

    char buffer[20];
    ired_range = fetchDataADC(IRED_SENSOR);                             // ping IRED-distance sensor for distance

    float x;

    x = pow(ired_range, -0.93532);

    sprintf(buffer, "%0.5f", x);

    printString(buffer);

    printString("\t\r\nSharp IRED-sensor ~ ping : ");
    printWord(ambient_light);                                        // variables swapped bc of ADC update issues
    printString("\r\n\n");
    de_EnergizeStepper();                                                        // Stepping Motor Torque Release
    distanceTraveled(hall_S2R_pulse, hall_S2L_pulse);                  // Read Hall sensors for distance traveled
    printString("\t");
    printTime(year_, months_, days_, hours_, minutes_, seconds_, milliseconds_);  // Prints Date/Time to terminal
    printString("\r\n\n");
}

I was lurking around here and found this thread: https://www.avrfreaks.net/forum/... , looking through it i did not really grasp the idea of how this issue can be managed , or solved.
It seems that Its time to ask the global hive mind :)

Dave

This topic has a solution.

work in progress...

Last Edited: Tue. Mar 24, 2020 - 05:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Try a forum search for

relocation truncated to fit:

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  1. Use something newer than winavr
  2. shouldn’t the -lxxx library specifies be at the end of the link line?

 

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

newer than winAVR? any examples? the avrdude is updated to version 6.3 which is the latest.

 

work in progress...

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

AVRDUDE is just a thing for programming the code into the chip.

 

The suggestion is to look at build tools more recent than WinAVR - which is ancient!

 

eg, Atmel Studio 7 (or the GCC version which comes with it)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dave_Zeb. wrote:
newer than winAVR?
These days it is Atmel-Microchip who make the avr-gcc builds for most folks (not least being all the users of C/C++ in AS7). YOu can get it from:

 

https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers

 

It would be unwise using a 10+ year old compiler in this day and age when so many things have been fixed and so many new features added.

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

Indeed, wasn't aware of that... 

 

I will try to download it asap. Meanwhile, what bothers me, in which clever way should I change/update the old compiler of mine so that everything still continues to work afterwards clawson. Also what is actually this issue related to, was reading several post from late 2007....year and wasn't really clear to me.

 

 

work in progress...

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

The problem is generally with link order. In the old compiler you HAVE to ensure that -lm links last. These days one of the many changes that have happened in the intervening 10+ years is you don't need -lm at all because it is now implied (and last).

 

Oh and you appear to have "-lm" when I guess you mean "-Wl,-lm". Even if using the old, outdated stuff at least use Mfile for you Makefile template - don't attempt to roll your own. In the Mfile template it does:

LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)

where MATH_LIB is

MATH_LIB = -lm

 

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

I have downloaded the latest version of the GNU tool-chain, from the link provided above. It comes with the folder "avr8-gnu-toolchain-win32_x86" where one can find many many different files and executables. I have un-zipped it, and not sure what to do.

 

My first guess is to copy everything into the actual WINAVR folder of mine. Like, it as it is mentioned in first post of mine,  the path of it above in error messages. Is that the way to update the build tools?

 

 

 

 

 

 

Somehow there is no light at the end of the tunnel. I tried to use the hints above but, no success so far.  Below is the mysterious make file which I am using to link... I do not understand much of it although.
 

 


##########------------------------------------------------------##########
##########              Project-specific Details                ##########
##########    Check these every time you start a new project    ##########
##########------------------------------------------------------##########

MCU  = atmega1284p
F_CPU = 20000000UL
#BAUD  = 250000UL

## Also try BAUD = 19200 or 38400 if you're feeling lucky.

## A directory for common include files and the simple USART library.
## If you move either the current folder or the Library folder, you'll
##  need to change this path to match.
LIBDIR = ../../Physalis_GEO_version_3.6

##########------------------------------------------------------##########
##########                 Programmer Defaults                  ##########
##########          Set up once, then forget about it           ##########
##########        (Can override.  See bottom of file.)          ##########
##########------------------------------------------------------##########

PROGRAMMER_TYPE = avrisp
# extra arguments to avrdude: baud rate, chip type, -F flag, etc.
# dynamic prototype arguments for flasher
PROGRAMMER_ARGS = -P com4 -b 19200
# static prototype arguments for flasher
#PROGRAMMER_ARGS = -P com6 -b 19200
##########------------------------------------------------------##########
##########                  Program Locations                   ##########
##########     Won't need to change if they're in your PATH     ##########
##########------------------------------------------------------##########

CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRSIZE = avr-size
AVRDUDE = avrdude

##########------------------------------------------------------##########
##########                   Makefile Magic!                    ##########
##########         Summary:                                     ##########
##########             We want a .hex file                      ##########
##########        Compile source files into .elf                ##########
##########        Convert .elf file into .hex                   ##########
##########        You shouldn't need to edit below.             ##########
##########------------------------------------------------------##########

## The name of your project (without the .c)
# TARGET = blinkLED
## Or name it automatically after the enclosing directory
TARGET = $(lastword $(subst /, ,$(CURDIR)))

# Object files: will find all .c/.h files in current directory
#  and in LIBDIR.  If you have any other (sub-)directories with code,
#  you can add them in to SOURCES below in the wildcard statement.

SOURCES=$(wildcard *.c $(LIBDIR)/*.c)
OBJECTS=$(SOURCES:.c=.o)
HEADERS=$(SOURCES:.c=.h)

## Compilation options, type man avr-gcc if you're curious.
CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR)
CFLAGS = -Os -g -std=gnu99 -Wall
## Use short (8-bit) data types
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
## Splits up object files per function
CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS = -Wl,-Map,$(TARGET).map
## Optional, but often ends up with smaller code
LDFLAGS += -Wl,--gc-sections
## Relax shrinks code even more, but makes disassembly messy
##LDFLAGS += -Wl,--relax
LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm  ## for floating-point printf
##LDFLAGS += -Wl,-u,vfprintf -lprintf_min      ## for smaller printf
TARGET_ARCH = -mmcu=$(MCU)

## Explicit pattern rules:
##  To make .o files from .c files
%.o: %.c $(HEADERS) Makefile
	 $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<;

$(TARGET).elf: $(OBJECTS)
	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@

%.hex: %.elf
	 $(OBJCOPY) -j .text -j .data -O ihex $< $@

%.eeprom: %.elf
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@

%.lst: %.elf
	$(OBJDUMP) -S $< > $@

## These targets don't have files named after them
.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses

all: $(TARGET).hex

debug:
	@echo
	@echo "Source files:"   $(SOURCES)
	@echo "MCU, F_CPU, BAUD:"  $(MCU), $(F_CPU), $(BAUD)
	@echo

# Optionally create listing file from .elf
# This creates approximate assembly-language equivalent of your code.
# Useful for debugging time-sensitive bits,
# or making sure the compiler does what you want.
disassemble: $(TARGET).lst

disasm: disassemble

# Optionally show how big the resulting program is
size:  $(TARGET).elf
	$(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf

clean:
	rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \
	$(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \
	$(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \
	$(TARGET).eeprom

squeaky_clean:
	rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom

##########------------------------------------------------------##########
##########              Programmer-specific details             ##########
##########           Flashing code to AVR using avrdude         ##########
##########------------------------------------------------------##########

flash: $(TARGET).hex
	$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<

## An alias
program: flash

flash_eeprom: $(TARGET).eeprom
	$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$<

avrdude_terminal:
	$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt

## If you've got multiple programmers that you use,
## you can define them here so that it's easy to switch.
## To invoke, use something like `make flash_arduinoISP`
flash_usbtiny: PROGRAMMER_TYPE = usbtiny
flash_usbtiny: PROGRAMMER_ARGS =  # USBTiny works with no further arguments
flash_usbtiny: flash

flash_usbasp: PROGRAMMER_TYPE = usbasp
flash_usbasp: PROGRAMMER_ARGS =  # USBasp works with no further arguments
flash_usbasp: flash

flash_arduinoISP: PROGRAMMER_TYPE = avrisp
flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0
## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5
flash_arduinoISP: flash

flash_109: PROGRAMMER_TYPE = avr109
flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0
flash_109: flash

#flash_AVR_ISP_MK_II: PROGRAMMER_TYPE = avrisp_mk2
#flash_AVR_ISP_MK_II: PROGRAMMER_ARGS = -b 19200 -P USB

##########------------------------------------------------------##########
##########       Fuse settings and suitable defaults            ##########
##########------------------------------------------------------##########

## Mega 48, 88, 168, 328 default values
LFUSE = 0x62
HFUSE = 0xdf
EFUSE = 0x00

## Generic
FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m

fuses:
	$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \
	           $(PROGRAMMER_ARGS) $(FUSE_STRING)
show_fuses:
	$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv

## Called with no extra definitions, sets to defaults
set_default_fuses:  FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
set_default_fuses:  fuses

## Set the fuse byte for full-speed mode
## Note: can also be set in firmware for modern chips
set_fast_fuse: LFUSE = 0xE2
set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m
set_fast_fuse: fuses

## Set the EESAVE fuse byte to preserve EEPROM across flashes
set_eeprom_save_fuse: HFUSE = 0xD7
set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m
set_eeprom_save_fuse: fuses

## Clear the EESAVE fuse byte
clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m
clear_eeprom_save_fuse: fuses

 

work in progress...

Last Edited: Mon. Mar 23, 2020 - 08:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Do yourself a favour and just install AS7

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

Or perhaps MplabX if on linux or mac....

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

I know and I do agree that it will save tons of time and energy letting more concentrate on development and not on constantly breaking tools-chain, and here and there.
But if now I leave this stuff and start using something else, it will be running away from problems, which I believe not good.

It would be really good insight for me to try to understand this weird make-files finally, which I was avoiding ever since I got to know them.

 

so -lm flag is missing or not in right place? okay, which line on makefile above we are talking about, and where does the linker directives start from.
 

work in progress...

Last Edited: Mon. Mar 23, 2020 - 09:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My first guess is to copy everything into the actual WINAVR folder of mine. Like, it as it is mentioned in first post of mine,  the path of it above in error messages. Is that the way to update the build tools?

Just put the new tool directory ahead of the WINAVR directory in your PATH variable...

 

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

where can I find the PATH variable...

 

LIBDIR = ../../Physalis_GEO_version_3.6

this one?

work in progress...

Last Edited: Tue. Mar 24, 2020 - 11:29 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Start a command prompt and type "PATH" followed by enter to see what your current path is. You can set PATH by type "environment variables" into Windows Start. When you run that you will get to:

 

 

Use "Environment Variables" at the bottom of that. Select the existing entry for "Path" and edit the location of the avr-gcc toolchain (the directory where the new avr-gcc.exe is located) onto the Start of that variable. Note that you will have two copies of Path you can edit, one "for user XXX" and one for "system variables" which apply to everyone. To get right onto the very start of the PATH make the edit to the "System variables" copy.

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

after the changes, everything is back on track!. It looks like that the linker errors are completely gone.  

 

Highly appreciated the input and feedback from everyone in this tread.
 

D:\Users\Arhitect\Documents\C_Programs\Physalis_Banshee\Physalis_GEO_version_3.8>make flash
avr-gcc -Os -g -std=gnu99 -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -DF_CPU=20000000UL -DBAUD= -I. -I../../Physalis_GEO_version_3.6 -mmcu=atmega1284p -c -o main.o main
main.c: In function 'espLinkSilent':
main.c:726:10: warning: variable 'set_rate' set but not used [-Wunused-but-set-variable]
  uint8_t set_rate = 0;                                                           // robo-Drive() arguments for speed and rate
          ^
avr-gcc -Wl,-Map,Physalis_GEO_version_3.8.map -Wl,--gc-sections -Wl,-lm -u,vfprintf -lprintf_flt    -mmcu=atmega1284p battery_pack.o fuse.o main.o sharp_IRED_PSD_sensor.o stepper_motor.o USART.o  -o Physalis_GEO_version_3.8.elf
avr-objcopy -j .text -j .data -O ihex Physalis_GEO_version_3.8.elf Physalis_GEO_version_3.8.hex
avrdude -c avrisp -p atmega1284p -P com4 -b 19200 -U flash:w:Physalis_GEO_version_3.8.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "Physalis_GEO_version_3.8.hex"
avrdude: input file Physalis_GEO_version_3.8.hex auto detected as Intel Hex
avrdude: writing flash (8684 bytes):

Writing | ################################################## | 100% 8.38s

avrdude: 8684 bytes of flash written
avrdude: verifying flash memory against Physalis_GEO_version_3.8.hex:
avrdude: load data flash data from input file Physalis_GEO_version_3.8.hex:
avrdude: input file Physalis_GEO_version_3.8.hex auto detected as Intel Hex
avrdude: input file Physalis_GEO_version_3.8.hex contains 8684 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 5.02s

avrdude: verifying ...
avrdude: 8684 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:D1, L:C6)

avrdude done.  Thank you.

now I have the AVR-GCC-5.4.0 version, before it was 3.0.4.

work in progress...

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

-j's rather than -R's (used in most other build systems like AS7)? Interesting.

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

Dave_Zeb. wrote:

 

avr-objcopy -j .text -j .data -O ihex Physalis_GEO_version_3.8.elf Physalis_GEO_version_3.8.hex

in this line you mean?, what is actually the difference.

It seems that the new compiler found a unused variable "set_rate" as can be seen, with old compiler i did not get that information.

work in progress...

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

If you use -j's (that is list the inclusions not the exclusions) then if you later add some flash section like .mydata you have to remember to add another -j for it here. But if you use -R's (exclusions not inclusions) then it just includes everything that is not specifically excluded. Both Mfile and AS7 choose to use -R in preference to -j for this reason.

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

the action adding the new toolchain to the "Path" tells the makefile to compile and link the sources using that specific avr-gcc-5.4.4. What about the hole lots of files that are sitting in that toolchain folder. Does that mean that only specifying the location in "Path" tells the linker to use all the files inside.

work in progress...

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

Yes it's all built to use paths relative to where the .exe's are located.