AVRISP-MKII Clone Programmer Project

AVRISP MKII Programmer Project

# Project Compatibility

The following list indicates what microcontrollers are compatible with this project.

- Series 7 USB AVRs (AT90USBxxx7)
- Series 6 USB AVRs (AT90USBxxx6)
- Series 4 USB AVRs (ATMEGAxxU4)
- Series 2 USB AVRs (AT90USBxx2, ATMEGAxxU2) - 8KB versions with reduced features only

# USB Information

The following table gives a rundown of the USB utilization of this project.

USB Mode: | Device
USB Class: | Vendor Specific Class
USB Subclass: | N/A
Relevant Standards: | Atmel AVRISP MKII Protocol Specification
Supported USB Speeds: | Full Speed Mode

# Project Description

Firmware for an Atmel Studio compatible AVRISP-MKII clone programmer. This project will enable the USB AVR series of microcontrollers to act as a clone of the official Atmel AVRISP-MKII programmer, usable within Atmel Studio or with any software capable of driving a real Atmel AVRISP-MKII programmer. In its most basic form, it allows for the programming of AVR TINY, MEGA and XMEGA devices at the programmer's VCC voltage from within Atmel Studio with no special hardware other than the USB AVR and the parts needed for the USB interface. If the user desires, more advanced circuits incorporating level conversion can be made to allow for the programming of target AVRs running at a different voltage to the programmer.

This device spoofs Atmel's official AVRISP-MKII device PID so that it remains compatible with Atmel's AVRISP-MKII drivers. It is currently tested working under the following configurations:

- Windows: Atmel Studio 7, with alternative driver
- Windows: AVRDUDE 6.2, with alternative driver
- Linux: AVRDUDE 6.1

Note that this clone requires an alternative driver under Windows, due to an incompatible change in the official Jungo based driver. The alternative driver given here will function with both real and clone AVRISP devices in Atmel Studio 7 onwards under Windows - and as a bonus, also provides AVRDude access to the programmer.

Note that this design currently has the following limitations:

- No reversed/shorted target connector detection and notification
- A separate header is required for each of the ISP, PDI and TPI programming protocols that the user wishes to use

On AVR models with an ADC converter, the USB AVR's AVCC pin should be tied to 5V (e.g. VBUS) and the `VTARGET_ADC_CHANNEL` token should be set to an appropriate ADC channel number in the project makefile for VTARGET detection to operate correctly. On models without an ADC converter, VTARGET will report a fixed 3.3V level at all times which should allow the programmer to remain compatible at the protocol level with all AVR devices.

While this application can be compiled for USB AVRs with as little as 8KB of FLASH, for full functionality 16KB or more of FLASH is required. On 8KB devices, ISP or PDI/TPI protocol programming support can be disabled to reduce program size.

# Known Issues:

XMEGA EEPROM programming fails in some cases.
  Several users have reported that XMEGA EEPROM programming fails unless the chip is erased first. If a non-blank EEPROM is present, writing further EEPROM data causes corruption. LUFA issue tracker entry.

# Installation

The programmer supports multiple platforms, both Windows and Linux.

## Linux Installation

On Linux systems, the programmer should be usable out of the box with no special setup other than (on some systems) editing of the system permissions to allow the programmer to be used from a non-elevated (root) context. The programmer is compatible with the free open source AVRDude programming software project.

## Windows Installation

On Windows systems, due to an unfortunate limitation of the USB AVR devices and the Atmel Studio platform, the programmer requires an alternative libUSB based driver. Uninstall the existing Jungo driver for the device (if installed) and replace it with the driver that ships with this project, to enable access to the programmer in Atmel Studio and AVRDUDE.

# ISP Connections

Connections to the device for SPI programming (when enabled):

Programmer Pin: | Target Device Pin: | ISP 6 Pin Layout:
--- | --- | ---
MISO | PDO | 1
ADCx 1 | VTARGET | 2
SCLK | SCLK | 3
MOSI | PDI | 4
PORTx.y 2 | /RESET | 5
GND | GND | 6

In addition, the AVR's OCR1A pin will generate a 4MHz clock, to act as an external rescue device clock if the fuses have been mis-set. To use the recovery clock, connect the OCR1A pin of the USB AVR to the target AVR's XTAL1 pin, and set the ISP programming speed to 125KHz (note: other ISP speeds will not work correctly).

1 Optional, see Project Options section - for USB AVRs with ADC modules only
2 See AUX line related tokens in the Project Options section

# PDI Connections

Connections to the device for PDI programming (when enabled):

Programmer Pin: | Target Device Pin: | PDI 6 Pin Layout:
--- | --- | ---
Tx/Rx 2 | DATA | 1
ADCx 1 | VTARGET | 2
N/A | N/A | 3
N/A | N/A | 4
XCK | CLOCK | 5
GND | GND | 6

1 Optional, see Project Options section - for USB AVRs with ADC modules only
2 The AVR's Tx and Rx become the DATA line when connected together via a pair of 220 ohm resistors

# TPI Connections

Connections to the device for TPI programming (when enabled):

Programmer Pin: | Target Device Pin: | TPI 6 Pin Layout:
--- | --- | ---
Tx/Rx 2 | DATA | 1
ADCx 1 | VTARGET | 2
XCK 2 | CLOCK | 3
N/A | N/A | 4
PORTx.y 3 | /RESET | 5
GND | GND | 6

1 Optional, see Project Options section - for USB AVRs with ADC modules only
2 The AVR's Tx and Rx become the DATA line when connected together via a pair of 220 ohm resistors
3 See AUX line related tokens in the Project Options section

# Project Options

The following defines can be found in this project, which can control the project behaviour when defined, or changed in value.

Define Name: | Location: | Description:
--- | --- | ---
AUX_LINE_PORT | AppConfig.h | PORT register for the programmer's AUX target line. The use of this line varies between the programming protocols, but is generally used for the target's /RESET line. Ignored when compiled for the XPLAIN board.
AUX_LINE_PIN | AppConfig.h | PIN register for the programmer's AUX target line. The use of this line varies between the programming protocols, but is generally used for the target's /RESET line. Ignored when compiled for the XPLAIN board.
AUX_LINE_DDR | AppConfig.h | DDR register for the programmer's AUX target line. The use of this line varies between the programming protocols, but is generally used for the target's /RESET line. Ignored when compiled for the XPLAIN board.
AUX_LINE_MASK | AppConfig.h | Mask for the programmer's AUX target line. The use of this line varies between the programming protocols, but is generally used for the target's /RESET line. Must not be the AVR's /SS pin. Ignored when compiled for the XPLAIN board.
VTARGET_ADC_CHANNEL | AppConfig.h | ADC channel number (on supported AVRs) to use for VTARGET level detection, if NO_VTARGET_DETECT is not defined. Ignored when compiled for targets lacking an ADC.
ENABLE_ISP_PROTOCOL | AppConfig.h | Define to enable SPI programming protocol support. Ignored when compiled for the XPLAIN board.
ENABLE_XPROG_PROTOCOL | AppConfig.h | Define to enable PDI and TPI programming protocol support. Ignored when compiled for the XPLAIN board.
NO_VTARGET_DETECT | AppConfig.h | Define to disable VTARGET sampling and reporting on AVR models with an ADC converter. This will cause the programmer to report a fixed 3.3V target voltage to the host regardless of the real target voltage. Ignored when compiled for targets lacking an ADC.
VTARGET_REF_VOLTS | AppConfig.h | Indicates the programmer AVR's AVCC reference voltage when measuring the target's supply voltage. Note that the supply voltage should never exceed the reference voltage on the programmer AVR without some form of protection to prevent damage to the ADC.
Ignored when compiled for targets lacking an ADC, or when NO_VTARGET_DETECT is defined.
VTARGET_USE_INTERNAL_REF | AppConfig.h | Selects the internal 2.56V ADC reference voltage, instead of using the AVR's VREF pin. When enabled, this option will override the VTARGET_REF_VOLTS configuration option. Ignored when compiled for targets lacking an ADC, or when NO_VTARGET_DETECT is defined.
VTARGET_SCALE_FACTOR | AppConfig.h | Indicates the target's supply voltage scale factor when applied to the ADC. A simple resistive divider can be used on the ADC pin for measuring the target's supply voltage, so that voltages above the programmer AVR's AVCC reference voltage can be measured. This should be the reciprocal of the division performed - e.g. if the VTARGET voltage is halved, this should be set to 2.
Ignored when compiled for targets lacking an ADC, or when NO_VTARGET_DETECT is defined.
XCK_RESCUE_CLOCK_ENABLE | AppConfig.h | Define to move the ISP rescue clock to the AVR's XCK pin instead of the OCR1A output pin. This is useful for existing programming hardware that does not expose the OCR1A pin of the AVR, but may cause some issues with PDI programming mode.
INVERTED_ISP_MISO | AppConfig.h | Define to invert the received data on the ISP MISO line. This is sometimes needed depending on the level translation hardware used, if the translator hardware inverts the received logic level.
FIRMWARE_VERSION_MINOR | AppConfig.h | Define to set the minor firmware revision nunber reported to the host on request. By default this will use a firmware version compatible with the latest Atmel IDE version, however if desired the reported minor value can be adjusted here.