UPDATE: 2022 |
WINAVR is (or was) a great project. Its most “recent” package is from 2010-01-20. In other words, it is outdated. There are many projects that attempted to replace it but none of them (AFAIK) is extremely popular. We’ve put together a very detailed guide on how to setup everything manually – AVR GCC Toolchain – Setup for Windows. |
This is a guide how to install, setup and use the WinAVR for programming the Tinusaur Board and the ATtiny85 microcontrollers in general as well as some sample programs and useful tips.
Note: This guide was tested under Microsoft Windows 8.1 operating system.
Note: The example source code was tested on ATtiny85 micro-controller installed on a Tinusaur Board and programmed using USBasp ISP programmer.
Installation
WinAVR http://winavr.sourceforge.net
WinAVR (pronounced “whenever”) is a suite of executable, open source software development tools for the Atmel AVR series of RISC microprocessors hosted on the Windows platform. It includes the GNU GCC compiler for C and C++.
Download the latest WinAVR distributive from http://sourceforge.net/projects/winavr/files/
Note: This guide was tested by using “WinAVR-20100110-install.exe” file downloaded from sf.net website.
Run the “exe” file.
Note: The OS may ask you to grant permissions to execute the file, answer “yes”.
- Choose language: English.
- Agree with the terms.
- Choose where to install. The default is probably “C:\WinAVR-20100110” which should OK.
- Choose to install all components.
This will:
- Install all files that are need for WinAVR to work properly.
- Add WinAVR to PATH environment variables.
- Install Programmers Notepad text editor.
This will add to the PATH:
- “C:\WinAVR-20100110\bin”
- “C:\WinAVR-20100110\utils\bin”
There is “WinAVR-user-manual.html” file in the “C:/WinAVR-20100110/” folder that describes WinAVR components.
Testing WinAVR
All command will be executed from a text console (similar to commend prompt and DOS prompt) that is called “shell”. The shell is part of WinAVR and is located under the “C:\WinAVR-20100110\utils\bin” folder.
IMPORTANT: Under the shell all texts are case sensitive – that means “hello” is completely different from “Hello”.
Note: Under certain versions of Windows (Ex.: 8.1) this may cause error messages to be printed out. One solution that was found is to run the “sh” command as an Administrator. This could be done like this …
- Open Windows Explorer and go to the “C:\WinAVR-20100110\utils\bin” folder.
- Locate “sh” (or “sh.exe”), do a “right click” and choose to “Run as administrator”.
For convenience you could create a short-cut of the “sh” to the desktop and then change the short-cut to run as an administrator:
- Right-click on the sort-cut, then choose Properties.
- under the “Compatibility” tab check the box “Run as administrator”
Run the shell.
First we need folder where all our projects will reside, so let’s go the our home folder and create one such folder …
$ cd /c/Users/MY_USER_NAME/ $ mkdir AVR_Projects $ cd AVR_Projects
To test the WinAVR we need to create a new project and that project requires its own folder.
Go to a folder where all other projects will reside (if you are not already there):
$ cd /c/Users/MY_USER_NAME/AVR_Projects/
Create project folded and go into it:
$ mkdir test_winavr $ cd test_winavr
Create new file in that folder:
$ touch test_winavr.c
Open the file:
(or from Windows Explorer with your favorite text editor)
$ notepad test_winavr.c
Write an “empty” program:
(it does not do anything)
int main(void)
{
return 0;
}
Close the file.
Now we need what is called a “Makefile” file.
There is MFile tool that is part of WinAVR and helps creating “Makefile” file – a file that is needed to build our programs. Start the MFile program – it creates new Makefile from a template.
- Open menu “Makefile / main file name” and choose “test_winavr”.
- Open menu “Makefile / MCU type” and choose “attiny85”.
- In the text find the F_CPU and make sure it is 1000000 which corresponds to 1MHz CPU clock. Before that you will need to “Enable editing …” from the “Makefile” menu.
- Open menu “File / Save as” and save file as “Makefile” in the folder where “test_winavr.c” is – i.e. in the “project folder”.
- Close the MFile program.
Building the program …
- From the shell go to the project folder (if not already there).
- Build the project:
$ make
If this completes without any error messages that means the WinAVR was succressfully installed.
This should created some additional files:
test_winavr.eep test_winavr.elf test_winavr.hex test_winavr.lss test_winavr.lst test_winavr.map test_winavr.o test_winavr.sym
The “test_winavr.hex” contains the compiled program that should be programmed to the micro-controller. Please note that this is an empty program and does not do anything.
Before programming the micro-controller with the testing program and the USBasp programmer some driver maybe needed.
USBasp Driver Installation
USBasp is a USB in-circuit programmer for Atmel AVR controllers. It simply consists of an ATMega88 or an ATMega8 and a couple of passive components. The programmer uses a firmware-only USB driver, no special USB controller is needed.
Under MS Windows operating systems drivers are required for the USBasp to work. No such driver are required under Linux and OS X.
The Windows drivers are available at http://www.fischl.de/usbasp/. On the website look for the Drivers section – the ZIP file name should be something like “usbasp-windriver.2011-05-28.zip” or similar. Unzip the ZIP file and follow the instruction on the website.
Note: This guide was tested using “usbasp-windriver.2011-05-28.zip” file.
Windows Vista/7/8 Issues
Under MS Windows Vista/7/8 there are some issues while installing the USBasp drivers. You may need to temporary disable the “Driver Signature Enforcement”. Detailed guide is available at this location: http://letsmakerobots.com/node/36841
Checking Device Manager
Connect the USBasp programmer to the computer.
Open the Device Manager and see if the “USBasp” is present under the “libusb-win32 devices” section. In most cases that means the driver function properly.
Testing the USBasp Programmer
The USBasp programmer could be tested by writing very simple program that makes a LED to blink.
Modify the testing program “test_winavr.c” file to …
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRB |= (1 << PB0);
while (1) {
PORTB |= (1 << PB0);
_delay_ms(100);
PORTB &= ~(1 << PB0);
_delay_ms(200);
}
return (0);
}
This is a program will make a LED connected to the PB0 (pin 5 on the chip) to blink.
Run the make command to rebuild the program.
$ make
Connect the USBasp programmer to the micro-controller board.
Note: The board should have a LED connected to PB0 with a 300 ohm resistor in series.
Run the AVRDUDE to transfer the program to the micro-controller.
$ avrdude -c usbasp -p t85 -B 0.5 -U flash:w:"test_winavr.hex":a
The program should start running immediately after the AVRDUDE finishes and the LED should start blinking rapidly.
That’s it!
References
References to the software and tools that were used in this guide and other useful stuff.
WinAVR
http://winavr.sourceforge.net/
WinAVR ™ is a suite of executable, open source software development tools for the Atmel AVR series of RISC microprocessors hosted on the Windows platform. Includes the GNU GCC compiler for C and C++.
SourceForge: http://sourceforge.net/projects/winavr/
Portable WinAVR
http://www.chip45.com/index.pl?page=PortableWinAVR&lang=en
Portable WinAVR is based on the regular WinAVR suite of software development tools for the Atmel AVR microprocessor series and is preconfigured to run directly from any removable medium (e.g. USB memory stick) without prior installation.
WinAVR AVR-GCC Tutorial
http://winavr.scienceprog.com/
WinAVR AVR-GCC Tutorial.
… and projects.
Step-by-step how to install AVR dev tools
http://www.ladyada.net/learn/avr/setup-win.html
USBasp
How to install USBasp drivers on Windows 8
http://letsmakerobots.com/node/36841
AVRDUDE
AVRDUDE – AVR Downloader/UploaDEr
http://www.nongnu.org/avrdude/
AVRDUDE is a utility to download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers using the in-system programming technique (ISP).
Starting out with avrdude
http://www.ladyada.net/learn/avr/avrdude.html
AVRDUDE Tools
AVRDUDESS – A GUI for AVRDUDE
http://blog.zakkemble.co.uk/avrdudess-a-gui-for-avrdude/
(note: shows generated command line options)
AVRdude GUI
http://sourceforge.net/projects/avrdudegui/
GUI Software for USBasp based USB AVR Programmers.
http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/
Khazama AVR Programmer
Please make the following correction:
The instruction was to create “test_winavr.c” but while creating the makefile, the main file name was instructed to be given as “main” which does not match with “test_winavr.c” so it throws an error.
kindly correct it.
Shankar, thanks a lot for noticing and reporting that.
It is fixed now.
It is always great seeing other people care about things that you do.
My pleasure Neven. After all you have taken your time to write this neat article, which has been very helpful!
Thanks again 🙂
USBaps driver installation can be a pain if you don’t have a signed driver. I’ve just uploaded a signed driver to http://www.protostack.com/index.php?main_page=library which should make things a lot easier.
Thanks for the suggestion PROTOSTACK,
Can you explain – to me and other readers: (1) how the signing works; (2) why is that the fischl.de/usbasp/ driver does not have signature but your does.
The other thing is … why this driver is 11 MB ZIP file while the fischl.de/usbasp/ is only 350 KB?
Installing unsigned drivers is real trouble especially under Windows 8/8.1.