This is a log of what I have done to get Eclipse running with WinAVR on Windows XP. Maybe it’s helpfull for others.
Prerequisites
- Download a Java Runtime JRE or JDK, if you do not have already. Anything greater 1.4.2 should be ok.
- Download Eclipse 3.2.2 here
- Download the CDT 3.1.2 plugin for Eclipse C/C++ development here
- Download WinAVR 20070525 here
Install WinAVR
Start the executable and choose a directory to install to. Mine goes to c:winavr-20070525.
Install Eclipse
Extract the downloaded zip into a directory, e.g. c:Programmeeclipse. Eclipse is now already working. You may want to create a desktop shortcut for the executable.
Install CDT
Extract the zip into a tmp directory. Then select the contents of the features and plugins folder and copy them to the respective folders beneath the eclipse folder.
Startup
- Open eclipse. It will ask for a workspace folder. If you are new to eclipse, choose a folder, where you would like to put your source code.
- It starts with the Java perspective, but we want C/C++. Select “Open Perspective” from the upper right corner. Then select “Other”. Then select “C/C++”. Your screen should now show the perspective for C development.
Start a Project
- Now select “File/New” of the menu. Then select “Managed make C project”. This creates a project with automated make. You do not have to take care of the makefile yourself.
- Enter “test” as project name and select “next”.
- Select “executable (gnu on windows)” as Project type. We will change this later.
- “Debug” and “Release” are ok as targets. Release only is also ok.
- Select “finish”.
- Ignore the warning for now that appears in the problems tab.
Configuration
Now we have to configure the settings for the WinAVR compiler and linker.
- Select “Project -> properties”. If “properties” are greyed out, then click on the project folder “test” to select it. Now the “properties” menu should be selectable.
- Select “C/C++ Build” on the left list.
- Select “Release” as configuration. We will change this target only. If you want to configure the “Debug” target as well, then go through these steps again.
- Select the “GCC C Compiler” in the tree below.
- Change “gcc” to “avr-gcc”
- Select “symbols” and enter a new symbol for the speed of your board, e.g. “F_CPU=4096000”.
- Select “Directories” and add “C:WinAVR-20070525avrinclude” to the includes.
- Select “Miscellaneous” and enter your type of controller, e.g. “-mmcu=atmega8”.
- Select “GCC C Linker” and change “gcc” to “avr-gcc”.
- Select the tab “Build Steps”.
- To convert the executable into a hex file, we use a post build step. Enter “Post-build step” as
"avr-objcopy -j .text -j .data -O ihex test.exe test.hex".
- Select “ok” to close the properties dialog.
Testing the Configuration
- Right-click on your project folder and select “New -> Source File”
- Enter “test.c”. Now write a small test program.
/* * test.c */ #include <util/delay.h> #include <avr/io.h> #define LED PD4 int main(void) { // define pd4 as output DDRD |= (1 << LED); while (1) { PORTD |= (1 << LED); // switch on _delay_ms(100); _delay_ms(100); PORTD &= ~(1 << LED); // switch off _delay_ms(100); _delay_ms(100); } return 0; }
- Saving triggers an automated build run. The console output should look like this:
**** Build of configuration Release for project test **** make -k all Building file: ../test.c Invoking: GCC C Compiler avr-gcc -DF_CPU=4096000 -I"C:WinAVR-20070525avrinclude" -O3 -Wall -c -fmessage-length=0 -mmcu=atmega8 -MMD -MP -MF"test.d" -MT"test.d" -o"test.o" "../test.c" Finished building: ../test.c Building target: test.exe Invoking: GCC C Linker avr-gcc -o"test.exe" ./test.o Finished building target: test.exemake --no-print-directory post-build avr-objcopy -j .text -j .data -O ihex test.exe test.hex Build complete for project test
- Now open up a command line in your project folder. Create a batch file “flash.bat” to transfer the hex file to your controller. This depends on your controller, programmer, etc. Mine looks like this:
c:winavrbinavrdude -v -F -p ATmega8 -c avr910 -P com4 -U flash:w:%1:i.
The -F switch is in the to force writing, even if the device signature is not recognized. Its just reversed. Omit it if you have no problems with that. - Now start the batch file to program your controller.
C:dataavrtest>flash Releasetest.hex C:dataavrtest>c:winavrbinavrdude -v -F -p ATmega8 -c avr910 -P com4 -U flash:w:Releasetest.hex:i avrdude: Version 5.1cvs Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ System wide configuration file is "c:winavrbinavrdude.conf" Using Port : com4 Using Programmer : avr910 AVR Part : ATMEGA8 Chip Erase delay : 10000 us PAGEL : PD7 BS2 : PC2 RESET disposition : dedicated RETRY pulse : SCK serial program mode : yes parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 ByteDelay : 0 PollIndex : 3 PollValue : 0x53 Memory Detail : Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max W ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- --- -- --------- eeprom 4 10 128 0 no 512 0 0 9000 90 00 0xff 0xff flash 33 6 64 0 yes 8192 64 128 4500 45 00 0xff 0x00 lfuse 0 0 0 0 no 1 0 0 2000 20 00 0x00 0x00 hfuse 0 0 0 0 no 1 0 0 2000 20 00 0x00 0x00 lock 0 0 0 0 no 1 0 0 2000 20 00 0x00 0x00 calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00 signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00 Programmer Type : avr910 Description : Atmel Low Cost Serial Programmer Found programmer: Id = "AVR ISP"; type = S Software Version = 2.3; Hardware Version = 2.0 Programmer supports auto addr increment. Programmer supports the following devices: Device code: 0x1c = (unknown) Device code: 0x55 = ATtiny12 Device code: 0x01 = ATtiny13 Device code: 0x56 = ATtiny15 Device code: 0x13 = AT90S1200 Device code: 0x28 = AT90S4414 Device code: 0x20 = ATtiny84 Device code: 0x4c = AT90S2343 Device code: 0x30 = AT90S4433 Device code: 0x6c = AT90S4434 Device code: 0x38 = AT90S8515 Device code: 0x68 = AT90S8535 Device code: 0x41 = ATMEGA103 Device code: 0x46 = (unknown) Device code: 0x44 = (unknown) Device code: 0x03 = (unknown) Device code: 0x75 = ATMEGA6490 Device code: 0x74 = ATMEGA6450 Device code: 0x63 = (unknown) Device code: 0x64 = ATMEGA163 Device code: 0x79 = (unknown) Device code: 0x14 = (unknown) Device code: 0x15 = (unknown) Device code: 0x16 = (unknown) Device code: 0x17 = (unknown) Device code: 0x72 = ATMEGA32 Device code: 0x60 = ATMEGA161 Device code: 0x76 = ATMEGA8 Device code: 0x77 = (unknown) Device code: 0x3b = (unknown) Device code: 0x6a = (unknown) Device code: 0x5e = ATTINY26 Device code: 0x29 = (unknown) Device code: 0x2a = (unknown) Device code: 0x2b = (unknown) Device code: 0x06 = (unknown) Device code: 0x07 = (unknown) Device code: 0x08 = (unknown) Device code: 0x21 = (unknown) Device code: 0x09 = (unknown) Device code: 0x0a = (unknown) Device code: 0x22 = (unknown) Device code: 0x23 = (unknown) Device code: 0x24 = (unknown) Device code: 0x0b = (unknown) Device code: 0x0c = (unknown) Device code: 0x0d = (unknown) Device code: 0x18 = (unknown) Device code: 0x19 = (unknown) Device code: 0x25 = (unknown) Device code: 0x26 = (unknown) Device code: 0x27 = (unknown) Device code: 0x1a = (unknown) Device code: 0x1b = (unknown) Device code: 0x4b = (unknown) Device code: 0x4d = (unknown) Device code: 0x4e = (unknown) Device code: 0x4f = (unknown) avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.06s avrdude: Device signature = 0x07931e avrdude: Expected signature for ATMEGA8 is 1E 93 07 avrdude: safemode: lfuse reads as FF avrdude: safemode: hfuse reads as D9 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 "Releasetest.hex" avrdude: writing flash (122 bytes): Writing | ################################################## | 100% 0.53s avrdude: 122 bytes of flash written avrdude: verifying flash memory against Releasetest.hex: avrdude: load data flash data from input file Releasetest.hex: avrdude: input file Releasetest.hex contains 122 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 0.25s avrdude: verifying ... avrdude: 122 bytes of flash verified avrdude: safemode: lfuse reads as FF avrdude: safemode: hfuse reads as D9 avrdude: safemode: Fuses OK avrdude done. Thank you. C:dataavrtest>
- If all went well and you see an LED flashing, congratulations, you did it.
Notes
If you look closely at the steps where I program the controller, you will notice, that I do not use the avr-dude that came with the last WinAVR release. I tried it, but it refused to work, always complaining about not beeing able to verify the fuses. I went on with my old avr-dude which worked perfect.
Alex, thanks for taking the time to create this helpful log. I was able to successfully get your example to compile. I am trying a slightly more complex application that have built many times in the past. The one question I have that you might have some insight into is:
My project uses a series of files located in the source trees “/lib” directory which all have a “.a” extension. I was wondering how to include these into eclipse. I was guessing that I add them to the “Libraries (-l)” area in the “Libraries” section of the “CGG C Linker” setting in the “Tool Settings” tab of the “C/C++ Build” properties. Is that correct?
“C/C++ Build/Tool Settings/ GCC C Linker/Libaries/Libaries (-l)”
Any hints?
Thanks again for taking the time to help.
Richard
LikeLike
Hi Richard,
yes, the “-l” should do the job.
Regards,
Alex
LikeLike
Thx for nice tutorial…
I gave eclipse a serious effort, but sometimes i responds slow or worse freeze. ( A lot of nice stuff but very vital functions works slow or unreliable )
Then I tried CodeBlocks, http://www.codeblocks.org
In less then 1 hour I had everything working RockSolid compared to eclipse ( Reading the link below ). And better than CodeVision !!!
http://www.frozeneskimo.com/electronics/arm-tutorials/adapting-codeblocks-ide-for-arm-development/
Thanks a lot for very interesting blog Alex !! I will keep an eye on your gps solution.
/DarkWing
LikeLike
Alex, thanks for taking the time to post this. Quick question, do you know how to set up avrdude to work in a more “integrated” fashion with eclipse? (e.g., associate it with some kind of button or something… and take in the parameters configured for the project for cpu type, target, etc.) ? Thanks much!
(I’m working on a Mac but…should be more or less the same… FWIW I did a writeup for setting up the AVR tools on Mac here if anyone is looking: http://bot-thoughts.blogspot.com/2008/02/avr-programming-on-mac.html)
Thanks again!
Michael
LikeLike
Hi Michael,
take a look at https://tinkerlog.com/2007/08/01/avr-plugins-for-eclipse/
This plugin is able to use and control avrdude to upload your program.
I haven’t looked into it for a while, but I think there is a newer version available.
Cheers,
Alex
LikeLike
Hi Alex!
Thank you for this great tutorial!
I’ve a question for you,…
Are you able to do the same tutorial but for ecplise 3.3 ?
I really do not find the location of the eclipse3.2 propriety in the 3.3!
LikeLike
Hi Giona,
at the moment I am not using Eclipse, so I haven’t updated to 3.3. Sorry.
Cheers,
Alex
LikeLike
Thank you for tha answer, I find out the 3.3 plugin “Avr plugin” …. now it seems to work properly!
Thanks again!
LikeLike
I just tried AVR plugin version 2.2. Following steps are now already handled by the plugin: “gcc†to “avr-gccâ€, setting F_CPU, adding “avr/include” and setting -mmcu
The only thing that remains is to add avr-objcopy to post-build steps (unless your programer tool can handle ELF files).
LikeLike
Hello,
I am able to run Eclipse and compile my code for Atmega8. Can you help me with the programmer part as to where I can get the hardware and binaries to program
Thanks,
Vineet.
LikeLike
Hi Vineet,
search for the USBtinyISP programmer from Lady Ada. It’s cheap and works well.
Cheers,
Alex
LikeLike
Hi Alex!
I follow the steps just like you describe but when I try to compile my program occurs this error:
“multiple target patterns. Stop.”
Do you have any idea about what happening?
Thanks
Jordan
LikeLike
I am not familliar with the current Eclipse setup. But it looks like a problem with the Makefile to me.
LikeLike
Hi Alex,
thanks for this tutorial. However, in AVR/Target Hardware, my MCU is not recognized (none of them are). And I cannot edit a configuration in AVR/AVRDude/Programmer. Do you know why Eclipse doesn’t see the config files for ATmega168?
Cheers,
Pierre-Jean
LikeLike
Hi Alex,
thanks for taking the time to create this helpful tutorial. your tutorial helped me lot. could you please put some images like this blog http://puranranablog.blogspot.com/2011/05/winavreclipse-ide.html
LikeLike