User forums > Using Code::Blocks

[SOLVED] AVR-GCC: setup build process

(1/2) > >>

kashamalasha:
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: ---#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;
}

--- End code ---

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: ---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.
--- End code ---

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: ---/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)
--- End code ---


--- Code: ---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
--- End code ---



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.

oBFusCATed:
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.

kashamalasha:
I've tried, but I can't implement it.

LETARTARE:
Hello,
You can also find 'GRBL' projects 'Code::Blocks' at:
https://github.com/LETARTARE/Mega2560-grbl-0.8xx/tree/devGrbl
Best regards

kashamalasha:
I fix the problem. Solution is in the first post.

Navigation

[0] Message Index

[#] Next page

Go to full version