User forums > Embedded development
a problem compiling eeprom of avr(atmega16,winavr) program
Aelxx:
Don't know what details you expect. I do everything default way. No quirks and cludges here.
OK. What I done is:
1) Just installed WinAVR, AVR-Studio, CodeBlocks.
2) Configured GNU AVR GCC compiler in C::B 'compiler and debugger' menu
3) Created project and wrote a program
4) Compile it. Done.
Here is example of compilation output:
--- Quote ---Running project pre-build steps
avr-gcc.exe -mmcu=atmega32 -O3 -Wall -std=gnu99 -fno-strict-aliasing -DF_CPU=14745600UL -gdwarf-2 -W -Wall -std=gnu99 -I"C:\Program Files\Atmel\AVR Studio 5.0\extensions\Application\AVR Toolchain\avr\include" -S main.c -o bin\Debug\main.s
-------------- Build: Debug in KIv05 pH ---------------
avr-gcc.exe -mmcu=atmega32 -O3 -Wall -std=gnu99 -fno-strict-aliasing -DF_CPU=14745600UL -gdwarf-2 -W -Wall -std=gnu99 -I"C:\Program Files\Atmel\AVR Studio 5.0\extensions\Application\AVR Toolchain\avr\include" -c main.c -o obj\Debug\main.o
avr-g++.exe -o bin\Debug\KIv05_pH.elf obj\Debug\main.o -mmcu=atmega32 -Wl,-Map=bin\Debug\KIv05_pH.elf.map,--cref -lm -lm
Output size is 55,61 KB
Running project post-build steps
avr-objcopy -O ihex -R .eeprom -R .eesafe bin\Debug\KIv05_pH.elf bin\Debug\KIv05_pH.elf.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex bin\Debug\KIv05_pH.elf bin\Debug\KIv05_pH.elf.eep.hex
avr-size --mcu=atmega32 --format=avr bin\Debug\KIv05_pH.elf
AVR Memory Usage
----------------
Device: atmega32
Program: 9448 bytes (28.8% Full)
(.text + .data + .bootloader)
Data: 148 bytes (7.2% Full)
(.data + .bss + .noinit)
cmd /R "avr-objdump bin\Debug\KIv05_pH.elf -h -S > bin\Debug\KIv05_pH.elf.lss"
Process terminated with status 0 (0 minutes, 5 seconds)
0 errors, 0 warnings
--- End quote ---
Note no "-lc" in linking. There are two!! "-lm" but it's completely different story.
Maybe you have something wrong with WinAVR or Windows PATHs/Registry?
a)Try reinstall WinAVR?
b)If doesn't help - look at Windows PATH for avr-gcc. What it shows?
scarphin:
Can u pls try to compile the code in the first post and post the output here? I can't debug the problem without the code.
Aelxx:
OK. Test project added in archieve. All OK.
Build log:
--- Quote ----------------- Build: Debug in Test ---------------
avr-gcc.exe -Wall -mmcu=atmega16 -DF_CPU=16000000UL -g -W -Wall -std=gnu99 -I"C:\Program Files\Atmel\AVR Studio 5.0\extensions\Application\AVR Toolchain\avr\include" -c main.c -o obj\Debug\main.o
avr-g++.exe -o bin\Debug\Test.elf obj\Debug\main.o -mmcu=atmega16 -Wl,-Map=bin\Debug\Test.elf.map,--cref
Output size is 5,73 KB
Running project post-build steps
avr-size --mcu=atmega16 --format=avr bin\Debug\Test.elf
AVR Memory Usage
----------------
Device: atmega16
Program: 226 bytes (1.4% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
avr-objcopy -O ihex -R .eeprom -R .eesafe bin\Debug\Test.elf bin\Debug\Test.elf.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex bin\Debug\Test.elf bin\Debug\Test.elf.eep.hex
cmd /c "avr-objdump -h -S bin\Debug\Test.elf > bin\Debug\Test.elf.lss"
Process terminated with status 0 (0 minutes, 3 seconds)
0 errors, 0 warnings
--- End quote ---
scarphin:
Ok I traced the problem, thnx for the help Aelxx. Unfortunately I don't have a solution and I don't know if that's related to CB or the compiler. The problem is the 'winavr_install_dir\avr\lib\libc.a' linker file. This file doesn't have the `__eewr_byte_m16' and '__eerd_byte_m16' functions to link but the linker tries to link to that file by default and can't find the corresponding functions. The correct file having those functions is 'winavr_install_dir\avr\lib\avr5\libc.a' and if I rename or delete 'winavr_install_dir\avr\lib\libc.a', the linker somehow finds the correct file ('winavr_install_dir\avr\lib\avr5\libc.a') and links to it without a problem.
I also tried with the 'AVR Toolchain v3.2.3' and had the same linker error. Deleting or renaming the 'libc.a' in the root folder gives a succesful build too. I'm confused here.
The problem doesn't seem to be CB specific but 'AVR Studio' can build the project correctly, I guess there is some setting to be done to CB.
Aelxx: Are u sure u don't have some extra options or paths in ur compiler or linker settings?
Aelxx:
Why C::B links to wrong library? Don't see any specific options in my configuration changing which would change behaviour of avr-gcc not to link correctly, anyway added part of my C::B configuration file (thru cb_share_config).
Btw, if CodeBlocks does't link to correct lib, but AVR Studio links - have you tried to look at build log of both of them and find difference? Or better run it yourself from command line.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version