avrusb500v2 is a modern stk500 v2 protocol compatible programer
for Linux, Mac, Windows ... (and more).

http://tuxgraphics.org/electronics

0) Hardware
-----------
The circuit diagram can be found in the hw/ directory

1) The only supported chip for this circuit is atmega8
------------------------------------------------------
We have removed support for atmega88 and other 
microcontrollers due to issues with the uisp programmer tool.
The software and circuit is made for atmega8 and a 
18.432MHz crystal.

2) Compile
----------
You need a avr-gcc installation with avrlibc-1.2.X

To compile all software including hardware test programs
type the command:

make

The the test programs are called test*.hex and the actual
avrusb500v2 firmware is main.hex

See point 6) for details on how to load the software.

3) Pre-compiled software
------------------------
Pre-compiled software is available for the 18.4320MHz version
with atmega8:

avrusb500_pre.hex
   After loading set the high fuse to 0xc9 and 
   the low fuse to 0xee (in that order! high fuse first)


See point 6) for details on how to load the software.

4) Install the bitbang firmware loading program (uisp_ppbg)
-----------------------------------------------------------
Note: If you have ordered the avrusb500v2 kit from http://shop.tuxgraphics.org
then you can skip this step. Everything is already installed on the CD.

Loading of firmware is done under Linux only. The programer
is OS independent once you have loaded the firmware.

You can either use the pre-compiled uisp_ppbg binary from bin/
or build it from sources:
- install libusb http://libusb.sourceforge.net
- install uisp-20050207.tar.gz + uisp-20050207-usb-bbpg-patch.txt
  or install uisp-20050207-usb-bbpg.tar.gz
- copy the file called uisp into this directory and name it uisp_ppbg
- become root and execute the make load* commands (see further down)


5) Testing
----------
The hardware is tested in 3 steps:

5a - connect avrusb500v2 to the usb port of your Linux PC and 
     type 
     more /proc/bus/usb/devices

     Search in this text for "Vendor=0403 ProdID=6001" or "Manufacturer=FTDI".

     You can also just run the command:
     grep FTDI /proc/bus/usb/devices

     If the FTDI chip is visible in /proc/bus/usb/devices then the USB 
     part is working.
     If not check soldering and parts for the ftdi chip. A common
     mistake is to swap the D+/D- cables on the usb port.

5b - connect the pins on the little programmer bridge connector (CONN6)
     with a wire and execute the command:

     make load_test_1

     This will load the program test_1.hex to the microcontroller.

     Note: this command needs to be executed as root unless you use
     the avr programming CD from http://shop.tuxgraphics.org

     The LED on the board should start to blink.

5c - This test has only limited added value compared to 3b. Allmost
     all functionallity is already tested if 4a and 4b were passed. You can
     skip this test if you want.
     Connect the pins on the little programmer bridge connector (CONN6)
     with a wire and execute the command:

     make ttydevinit1152
     make load_test_2

     Note: the second command needs to be executed as root unless you use
     the avr programming CD from http://shop.tuxgraphics.org

     Remove the usb connector and plug it back in. Run the following
     command to see that the ftdi_sio module is loaded:
     /sbin/lsmod | grep ftdi

     If it is not loaded then execute the command (as root):
     modprobe ftdi_sio

     execute the commands:

     ./ttydevinit1152 /dev/usb/tts/0
     or (dependent on your Linux distribution):
     ./ttydevinit1152 /dev/ttyUSB0

     Open two shell windows (e.g xterm or Konsole) and execute in

     shell 1:
     cat /dev/ttyUSB0      
     (or cat /dev/usb/tts/0 but that is obvious, I guess...)

     in shell 2:
     cat > /dev/ttyUSB0

     In shell 2 you type now:
     1
     In shell 1 you should see now the text "on OK" and the LED should go on.

     In shell 2 you type:
     0
     and in shell 1 you should see now the text "off OK" ... and the LED 
     should go off.

     You can terminate the cat commands with crtl-c.


6) Loading the final firmware
-----------------------------
You still need the bridge cable (CONN6) in place in order to
execute this step.

After successful testing of the hardware (step 3) you can now load the final
firmware:

make load

This command is rather slow and will take about 40 minutes to 
complete (run it over lunch time). The loading is a bit faster
on a PC with USB 2.0.
You will need to do this firmware loading only once. After this step
you have a fast and modern AVR programmer.

The command "make load" will load the file main.hex into
the atmega8/. There is also a file avrusb500_pre.hex 
which can be loaded in case you do not have a working avr-gcc compiler.

To load the pre-compiled software you can use the command:
make load_pre


You can  remove the bridge once the loading procedure is complete.

7) Optional: Setting to SW version to keep avrstudio quiet
-------------------------------------------------------
A good serial terminal for Linux is gtkterm 
  http://www.jls-info.com/julien/linux/

Under windows you can use Hyperterminal

To talk to the avrusb500 in terminal mode you have to
attach your serial terminal to the com port (Linux /dev/ttyUSB0)
with the following settings: 
 Speed=115200 Parity=none Bits=8 Stopbits=1 Flow=none

Note to windows users: Hyperterminal crashes/hangs if you set Flowcontrol
accidently not to none.

Hit twice return and then you get a dialog on the screen
similar to this one (in this example we change ver=2.2 to ver=2.1):

	AvrUsb500 terminal mode
	Enter SW Version Major [2]: 2
	Enter SW Version Minor [2]: 1

	OK, my SW version is now: 2.1
	Ready. Just close the terminal. No reset needed.

An alternative to gtkterm is under linux also the ttydevinit1152 command included 
in this package:
Open 2 xterm windows. In one you type 
./ttydevinit1152 /dev/ttyUSB0
cat /dev/ttyUSB0

The other you use as input window (put mouse focus on it):
cat > /dev/ttyUSB0

8) Using the clock pulses from avrusb500 v2 to recover a chip
-------------------------------------------------------------
The clock output on the board provides a clock signal with about 1MHz
which can be used to recover a device which was accidently
programmed to external clock or wrong crystal type.

Procedure:
Connect the clock output to xtal1 pin on the target and then
program the target fuses with a very low sck freq. (avrdude option -B 20)
To recover eg. a atmega8 use:
avrdude -p m8 -c avrusb500 -u -v -U lfuse:w:0xe1:m -B 20

The low speed (set with -B 20) stays until you change it or unplug the usb
connector.

9) Change history
-----------------
2007-05-18:  avrusb500v2-1.0 first public version based on avrusb500-1.6
2007-07-20:  avrusb500v2-1.1 correct typo in bbpg_fuse. Improve this readme file.
                             (the firmware is identical to the previous release)

2007-11-25:  avrusb500v2-1.2 Fix 64k-Word flash bug, thanks to Andrzej Wolski
2010-05-21:  avrusb500v2-1.3 Updated readme file to make it clear that
                             a atmega8 chip shall be used to build this
			     programmer.
Author/Copyright/Links
----------------------
Guido Socher (guidosocher at gmail.com)

Idea for terminal mode by Florin-Viorel Petrov.
64K-Word flash addressing by Andrzej Wolski.

Copyright: GPLv2 (see http://www.gnu.org/licenses/gpl.html )
Homepage of the avrusb500: 
    http://tuxgraphics.org/electronics/