Author Topic: [SOLVED] AVR-GCC: setup build process  (Read 6147 times)

Offline kashamalasha

  • Single posting newcomer
  • *
  • Posts: 6
[SOLVED] AVR-GCC: setup build process
« on: February 26, 2015, 08:50:38 pm »
Hi, everybody!

Next question. I'm a newbie at microchip bulk programming.
Earlier I did program the microchip using Arduino IDE, but now I'm trying to setup a proper environment to handy work with them via pure AVR-GCC.
I prefer to use Linux distro on my laptop. And there is why I can't use Atmel Studio, CodeVision or AVRStudio application.
I chose: AVR-GCC, AVR Toolchain and CodeBlocks.
All of these stuff works together fine with one note:
actually I can't properly setup internal clock setting for build process in Code::Blocks. I mean, I am doing next:

  • load next fuses to ATTiny45: -U efuse:w:0xFF:m -U hfuse:w:0xDF:m -U lfuse:w:0x62:m (divide internal clock by eight)
  • define #define F_CPU 1000000UL before #include <util/delay.h>
  • write some example code with blinking led

But after loading this hex file to the chip, led isn't blink with proper interval. It is blinking much faster than 1 time per second. Like if I setup F_CPU 800000UL. But if I load this code to chip via Arduino IDE it works fine.

My test code:
Code: [Select]
#define F_CPU 1000000L
#include <avr/io.h>
#include <util/delay.h>

int main(void){
    DDRB = 0x10;
    while(1){
        PORTB |= (1 << PB4);
        _delay_ms(1000);
        PORTB &= ~(1 << PB4);
        _delay_ms(1000);
    }
    return 0;
}

I set two tools in Code::Blocks for setting fuses on microchip by using /usr/bin/avrdude:

    ATTiny45 (int. 1MHz) with next string: "-p attiny45 -P /dev/ttyACM0 -b 19200 -c arduino -U efuse:w:0xFF:m -U hfuse:w:0xDF:m -U lfuse:w:0x62:m"
    ATTiny45 (int. 8MHz) with next string: "-p attiny45 -P /dev/ttyACM0 -b 19200 -c arduino -U efuse:w:0xFF:m -U hfuse:w:0xDF:m -U lfuse:w:0xE2:m"
 

And if I do "avrdude -p attiny45 -P /dev/ttyACM0 -b 19200 -c arduino -v", then I'll get this:

Code: [Select]
Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9206
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (H:FF, E:DF, L:62)

avrdude done.  Thank you.

That's mean that the fuses are correct. And there is why I think that something wrong with the build process in Code::Blocks and AVR-GCC

Here are logs from build systems. The first one from Arduino IDE, second from C::B:
Code: [Select]
/opt/arduino-1.0.6/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=attiny45 -DF_CPU=1000000L -MMD
-DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/opt/arduino-1.0.6/hardware/arduino/cores/arduino -I/home/me/sketchbook/hardware/attiny/variants/tiny8
 /tmp/build6896905435354427440.tmp/TestFCPU.cpp -o /tmp/build6896905435354427440.tmp/TestFCPU.cpp.o
...
opt/arduino-1.0.6/hardware/tools/avr/bin/avr-gcc -Os -Wl,--gc-sections -mmcu=attiny45 -o /tmp/build6896905435354427440.tmp/TestFCPU.cpp.elf
/tmp/build6896905435354427440.tmp/TestFCPU.cpp.o /tmp/build6896905435354427440.tmp/core.a -L/tmp/build6896905435354427440.tmp -lm
/opt/arduino-1.0.6/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings
--change-section-lma .eeprom=0 /tmp/build6896905435354427440.tmp/TestFCPU.cpp.elf /tmp/build6896905435354427440.tmp/TestFCPU.cpp.eep
/opt/arduino-1.0.6/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/build6896905435354427440.tmp/TestFCPU.cpp.elf
/tmp/build6896905435354427440.tmp/TestFCPU.cpp.hex
Binary sketch size: 132 bytes (of a 4,096 byte maximum)

Code: [Select]
avr-gcc -mmcu=attiny45 -Os -Wall -Os -I/usr/include -c main.c -o obj/Release/main.o
avr-g++ -L/usr/lib -o bin/Release/TestFCPU.elf obj/Release/main.o  -mmcu=attiny45 
Output file is bin/Release/TestFCPU.elf with size 3,66 KB
Running project post-build steps
avr-size bin/Release/TestFCPU.elf
   text       data        bss        dec        hex    filename
     82          0          0         82         52    bin/Release/TestFCPU.elf
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex bin/Release/TestFCPU.elf bin/Release/TestFCPU.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex bin/Release/TestFCPU.elf bin/Release/TestFCPU.eep



Thanks in advance for any help.

=== SOLUTION ===
I did next changes in Settings => Compiler...
1. Changed the Linker for dynamic libs in Toolchain executables form "avr-g++" to "avr-gcc":


2. Changed the Search directories for Linker and Compiler from /usr/include to /usr/lib/avr/include and from /usr/lib to /usr/lib/avr/lib:


Thanks for help to everyone.
« Last Edit: February 27, 2015, 05:28:22 pm by kashamalasha »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12207
    • Travis build status
Re: AVR-GCC: setup build process
« Reply #1 on: February 26, 2015, 09:34:41 pm »
You can probably test my arduino template if it works correctly with your cpu.
I've tested it with an arduino uno and a micro.

See here https://github.com/obfuscated/cb_arduino_template for the repo and install instructions.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kashamalasha

  • Single posting newcomer
  • *
  • Posts: 6
Re: AVR-GCC: setup build process
« Reply #2 on: February 26, 2015, 10:43:06 pm »
I've tried, but I can't implement it.

Offline LETARTARE

  • Regular
  • ***
  • Posts: 395
  • L'ami de l'homme.The friend of man.
Re: AVR-GCC: setup build process
« Reply #3 on: February 26, 2015, 11:16:13 pm »
Hello,
You can also find 'GRBL' projects 'Code::Blocks' at:
https://github.com/LETARTARE/Mega2560-grbl-0.8xx/tree/devGrbl
Best regards
C::B  : svn11972, wx-3.1.1, plugins : QtPregen-2.7.2-sdk147
1-Win 7 Business Pack 1 64bits : gcc-8.1.0,
2-OpenSuse-15.1-Leap 64bits :  gcc-7.5., 8.1.0,
=> !! The messages are translated by Deepl !!

Offline kashamalasha

  • Single posting newcomer
  • *
  • Posts: 6
Re: AVR-GCC: setup build process
« Reply #4 on: February 27, 2015, 05:03:27 pm »
I fix the problem. Solution is in the first post.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: AVR-GCC: setup build process
« Reply #5 on: February 27, 2015, 05:19:16 pm »
It might work but I don't think that is the correct solution unless you have special kind of avr-gcc distribution.

Offline kashamalasha

  • Single posting newcomer
  • *
  • Posts: 6
Re: [SOLVED] AVR-GCC: setup build process
« Reply #6 on: February 27, 2015, 10:46:47 pm »
Yep, that's right.
I clean it all and all works fine. I don't why it was there by default.