Archive / HVprog2

RSS feed for this section

How To Use HVprog2

HVprog2 is an Atmel STK500 clone for programming in HVSP/PP, ISP, TPI, and PDI. This post explains how to use HVprog2.

Note: This and the previous posts are nothing to do with GoPro nor genlock. These discuss some programmers for AVR microcontrollers.

In the previous post we showed a hardware/software mod of original Atmel STK500. Inspired both by Atmel STK500 and its mod we designed a clone programmer called HVprog2.

There already exists another hardware clone of Atmel STK500 whose name is HVprog, and it claims to be able to program in HVSP/PP and ISP. HVprog2 is an improved version of HVprog, thus it has a similar name, and it can actually program AVR chips not only in HVSP/PP and ISP but also in TPI and PDI.

Comparison With STK500 original/mod, HVprog and HVProg2

The below is a comparison chart of AVR programmers:

STK500 STK500 mod HVprog HVprog2
Schematic available no need (*1) available available
Atmel official firmware OK NG OK OK (*2)
ScratchMonkey firmware NG OK NG OK (*2)
Recover RSTDISBL fuse OK OK NG (*3) OK
HVSP/PP, ISP programming OK OK unreliable (*3) OK
TPI/PDI programming NG OK NG OK (*2)

Note 1: STK500 mod is simply made of original STK500 with few chips removed/replaced.

Note 2: We can use Atmel official firmware if the microcontroller is ATmega8535 but TPI/PDI is not possible in this case. If the microcontroller is one of ATmega16/32/64/128 or ATmega164/324/644/1284 then not only HVSP/PP and ISP but also TPI/PDI is possible by using ScratchMonkey firmware.

Note 3: In order to recover the reset disable fuse the target voltage must be controlled. HVprog lacks the circuit for this, thus it’s impossible to unprogram the fuse bit. Moreover, examining STK500 and HVprog schematics we can find the former inverts XTAL1 signal but the latter where the same firmware is used. As a result, the inversion cause timing problems in every session and makes HVprog unreliable.

HVprog2 Overview

Here is the schematic of HVprog2:
HVprog2

If you are going to use ScratchMonkey exclusively then IC2 74HC165 and its bypass capacitor C3 can be omitted. These parts are for hardware version identification only by Atmel’s firmware.

We recommend you to use a DIP IC socket for IC1 because it enables upgrading/swapping the microcontroller in the future.


The following image is a copy of HVprog2 using PCB sold in our shop.
HVprog2

The PCB is designed for thru-hole electronic parts wherever available, and is easy to assemble/solder.

The 6 pins marked JP1 (top right) are for PC connection conveniently aligned for using ubiquitous Sparkfun FTDI breakout board or its clone: If you use 5V version of the breakout then the whole HVprog2 programmer runs in 5V logic, and this is necessary to program in HVSP/PP or TPI. Or using Sparkfun’s 3.3V version then HVprog2 is also in 3.3V logic that matches PDI programming.

The 20 pins marked HV_PROG (bottom right) are for target connections. These pins are ordered to be compatible with those of AVR Dragon. This means we can refer AVR Dragon’s comprehensible documentation for wiring/breadboarding in HVSP/PP.

Software

To burn a software JP2 on HVprog2 board must be set to 1-2 (SELF). Then connecting another ISP programmer to 6 pins marked ISP (near center left) will do the job.

As already stated in the above there are currently two possibilities for HVprog2’s firmware depending on which microcontroller is installed:

  1. ATmega8535: Atmel’s firmware for original STK500
  2. ATmegaATmega16/32/64/128 or ATmega164/324/644/1284: ScratchMonkey

Case 1. Atmel’s original firmware is included in any Atmel Studio 4/5/6/7 packages: The name of the binary is STK500.ebn but the file format is not usable with a usual programmer such as avrdude. We need to convert its format “.ebn” to “.hex” using EBN2HEX.exe before burning the binary to the microcontroller (please google and find a download site for EBN2HEX.exe as we cannot find its official webpage). For your information we set ATmega8535’s fuses as S8535C and CKOPT unprogrammed, SPIEN programmed and SUT_CKSEL=”Ext. Crystal/Resonator High Freq; Start-up time: 16K CK + 64ms”.

Case 2. We use ScratchMonkey. The preparation/compile/upload process is the same way described in our previous post.

Target Connections

HVSP/PP. In either Cases, to program in HVSP/PP we can follow the connections to target described in Device Connection Sheets, AVR Dragon’s manual: Refer the connector named HV_PROG.
Note: No need to connect VCC to JTAG as HVprog2 has no such connectors.


ISP. To program in ISP use the ISP connector (JP2 must be set to 2-3).
Note: The VCC pin on HVprog2’s ISP6 connector is always powered by FTDI’s VCC pin.


TPI/PDI. Since HVprog2 is a clone of STK500 or STK500 mod, avrdude requires to be modified as we did in the previous post.

To program a TPI microcontroller two external 510 ohm resistors are required. The HVprog2 board must be powered by 5V version of FTDI breakout board. And use the connection in the following schematic:
TPI
5V, MOSI, MISO, SCK, and GND are located at “ISP” connector (JP2 must be set to 2-3). And VTARGET is at pin 19 of “HV_PROG” connector, RESET5V at pin 5 of “HV_PROG”, and RESET12V is at pin 5 of “ISP” or pin 18 of “HV_PROG” connector. Use signals in TPI connector of the schematic if the reset disable fuse is not programmed. Otherwise use signals in TPI HV connector since high voltage TPI requires the target voltage to be controlled.

To program a PDI microcontroller two external 510 ohm resistors are required. The HVprog2 board must be powered by 3.3V version of FTDI breakout board. And use the connection in the following schematic:
PDI2
(The parts included in dashdots are unnecessary.)

3V3, MOSI, MISO, SCK, and GND are all located at “ISP” connector (JP2 must be set to 2-3).

Atmel STK500 mod

The post addresses Atmel STK500 starter kit mod as not only HVPP/SP and ISP but also TPI and PDI programmer.

NOTE: This post is nothing to do with GoPro nor Genlock although they are the main topics in this blog.

Introduction

Atmel STK500 is a long-lived product from Year 2001 to now. We consider nowadays most of its users are utilizing it as a simple programmer, and not as starter kit for DIP-package microcontrollers.

STK500 has two microcontrollers ATmega8535L (main) and ATtiny2313V (sub) on its board, and has following features:

  • HVPP (High Voltage Parallel Programming) programmer
  • HVSP (High Voltage Serial Programming) programmer
  • ISP (In-System Programming) programmer

Our mod replaces its main ATmega8535L to a pin-compatible microcontroller that has more flash memory, and removes its sub ATtiny2313V. The latter mod is feasible because since Atmel haven’t offered any new main microcontroller’s firmware after Year 2009 until now sub’s only role of updating main’s firmware is considered to be dead. Once the STK500 board gets a memory-rich microcontroller we can burn an open-source firmware such as ScratchMonkey originally by Matthias Neeracher (modified by Orangkucing Lab) and can also add supports for TPI and PDI.

Hardware Mod

We remove the following four parts from original STK500:

  • U200 : ATtiny2313V
  • U202 : ATmega8535L
  • C200 : Capacitor 47n
  • R200 : Resistor 10k

Remove orange parts. Add red parts.

Remove orange parts. Add red parts.


(The figure above is taken from Atmel’s original “STK500 component placement: STK500_asm.pdf”. And also the part numbers are adopted from “Atmel STK500 schematic: STK500.pdf”.)

After removing these parts the board looks like the following image:

After removing four parts from STK500

After removing four parts from STK500

Then we add the following parts:

  • U202 : ATmega1284P
  • R213 : Jumper 0ohm (or solder jumper will do)
  • J200 : 2×3 header pins

The new microcontroller will be any pin-compatible one to ATmega8535, namely ATmega16/32/64/128 or ATmega164/324/644/1284 families. We used unnecessarily-very-very-high-spec ATmega1284P here because we don’t want to remove/resolder such a delicate SMD chip again in the future.

After soldering these parts STK500 hardware mod has been completed and looks like this:

A STK500 mod board. A sticker (1) indicates the 1st pin of ISP6 connector.

A STK500 mod board. A sticker (1) indicates the 1st pin of J200 ISP6 connector.

Software

To burn a firmware to the main microcontroller sit on U202 another ISP programmer is required. We don’t explain here in detail how to upload a firmware or what is an ISP programmer or so since many reader of this post already know these kind of things better than us. 🙂

So just connect another ISP programmer to newly installed J200 pin header and burn the firmware obtained from here (this link is ScratchMonkey’s fork of us but we expect our branch will be pulled and merged to the trunk soon). To compile the source code Arduino IDE and its DIP-40 core are needed. To do this follow the instruction here. And since STK500 uses a crystal of 7.3728MHz the board.txt file must be edited to have the following lines:

ATmega1284-7372800.name=ATmega1284-7372800Hz
ATmega1284-7372800.upload.tool=avrdude
ATmega1284-7372800.build.mcu=atmega1284
ATmega1284-7372800.build.board=AVR_ATMEGA1284-7372800
ATmega1284-7372800.build.f_cpu=7372800L
ATmega1284-7372800.build.core=arduino:arduino
ATmega1284-7372800.build.variant=ATmega1284
ATmega1284-7372800.upload.maximum_size=128000

Remark: The above example shows the case that the microcontroller is ATmega1284. If your microcontroller is a different one please edit the file in the same way.

And for your information we set microcontroller’s fuses to:

  • CKDIV8/CKOUT unprogrammed
  • SPIEN programmed
  • SUT_CKSEL = FSOSC_16KCK_65MS_XOSC_SLOWPWR

Now the STK500 mod board should be recognized as an original Atmel STK500 by Atmel Studio 4/5/6/7 and by avrdude (as stk500v2 for ISP or stk500pp for HVPP or stk500sp for HVSP).

Moreover it is now usable also as a TPI or PDI programmer. The details will be in the next section.

Using STK500 mod as TPI/PDI programmer — Software

Regrettably Atmel Studio doesn’t recognize STK500 mod as a TPI/PDI programmer. The only way is to apply a patch to avrdude’s source code and always use STK500 mod from avrdude in case you need a TPI/PDI programmer.

The patch for avrdude consists of eight parts:

Since avrdude has been distributed in many forms/versions the patch is for your reference only and it usually cannot be applied automatically by using the patch tool. So it is normal that you need to edit the stk500v2.c file manually by yourself.

The first section (1254,1263) of patch enables PGMTYPE_STK500 for XPROG (TPI and PDI).

The second (3712,3719) and third (3724,3736) sections for calculating flash/eeprom sizes, and the fourth (3795,3801) and fifth (3806,3811) are modified to reporting these sizes to the STK500 mod.

And the rest of patch is for TPI fuse programming that needs “a mystic erase prior to writing”.

Using STK500 mod as TPI/PDI programmer — Connections

After avrdude has been patched you can program any TPI/PDI chips.


To program a TPI microcontroller two external 510 ohm resistors are required. And use the connection in the following schematic:
TPI
5V, MOSI, MISO, SCK, and GND are located at J200 ISP6 connector. And VTARGET is at any pin marked “VTG” (jumper “VTARGET” must be set), RESET5V at pin 5 of “PROG DATA”, and RESET12V at “ISP6PIN” or “ISP10PIN” connector. Use signals in TPI connector of the schematic if the reset disable fuse is not programmed. Otherwise use signals in TPI HV connector since high voltage TPI requires the target voltage to be controlled.


To program PDI not only two external 510 ohm resistors but also a quad 5V-tolerant 3-state buffer 74LVX125 are required. And use the connection in the following schematic:
PDI2
3V3 is at “VADJ” or pin 13 of “EXPAND0” connector (jumper “AREF” must be set), and MOSI, MISO, SCK, and GND are at J200 or “ISP6PIN” or “ISP10PIN”. MOSI_GATE is located at RESET pin of “ISP6PIN” or “ISP10PIN”.

Note: The PDI programming voltage is 3.3V. Since STK500 is in 5V logic some kind of logic level translation is necessary. Thus we tried to use automatic level conversion chips such as MAX3002, GTL2003, TXB0104, and FXMA108 but NONE OF THEM WORKED RELIABLY. It’s a pity we must use a 3-state buffer like 74LVX125. What naive/stupid signals Atmel’s PDI protocol uses!!


Lastly we show example invocations of avrdude:

avrdude -c stk500v2 -p t10 -P /dev/tty.usbXXXXX -vvvv # show detailed transaction and tiny10's signature
avrdude -c stk500v2 -p x128a1 -P /dev/tty.usbXXXXX -U flash:w:hehehe.hex:i # flash hehehe.hex to xmega128a1

where tty.usbXXXXX is the serial port your STK500 mod is connected.

Enjoy!