AtMega/JTaG

How to Debug software?

- write good code that is easy to understand

- try to explain your code in comments (unless trivial)

- log to serial port and examine the output:

- make some characteristic numbers available (counters, histograms) in mem or serial port (see benchstats)

- go through your program in AtMega/AvrStudio (note that this won't surely show the overflows!)

- make someone audit your code

There is also AtMega In Circuit Emulation possibility built into the AtMega128 (not sure in what way it is better for debugging than Avr Studio. It could probably be used for more detailed circuit-testing than from pure firware-based hw-test.)

NEW INFO:

A guy made a very simple and cheap (around 30 Euro) board with AtMega163, that works with AtMega/AvrStudio. A few still available here: http://www.x-dsl.hu/genboard/

Write a note here if you don't need it just now, but interested in it for later.

Some more info:


Where to buy JTAG ICE?

We had a few dozens of AVR JTAG. You can always buy one from atmel.com somewhat more expensive. Our developers never actually used it (firmware upload via ISP, and BootLoader, debug via serial.)


Howto make JTAG ICE (Compatible to Atmel AVR JTAG*ICE)

You can search for Freeice on internet.

ATmega163 (or Atmega16, need bootloader fix!!)

7.3728 Crystal

Standard UART Serial Driver (MAX232, etc)

VREF (pin 29) to VCC

ADC2 (pin35) to VCC

PD3 pull-down resistor 4k7

Connect some ATmega to your ICE

TDO - PB6(pin12) to target TDO

TDI - PB5(pin1) to target TDI

TMS - PB1(pin41) to target TMS

TCK - PB7(pin3) to target TCK

PB3(pin43) to LED (other side of LED to VCC) this is "JTAG Activity"

Program with bootice.rom see source bootice.bas (AVR Basic) use Pony Prog

(notice bootloader is for m163 only)

Set Fuses: BOOTSZ, BOOTRST all programmed, Clock all non-programmed see

Pony Prog screenshot

Connect your ATmega to COM port

Start AVRStudio 4

Launch AVRPROG

Select "Program Files\Atmel\AVR Tools\JTAGICE\Upgrade.ebn" as Flash file

Program Flash, close AVRPROG

Program Fuses using Pony Prog so that BOOTRST is not programmed see Pony Prog

screenshot

In AVRStudio 4, Tools-JTAGICE you should see following screenshot

Congratulations you have AVRStudio connected to JTAGICE!

Go ahead and use your own JTAGICE !


A guy published his success with a simple and cheap ice: AtMega/JTaG/Hungarian


It works!

I used a Mega16 as the Mega163 is an obsolete part. Use the special

bootloader 'bootice16.rom' from http://www.case2000.com/JtagIce/

This bootloader has one problem: When you load the firmware with

AVRPROG, it shows an verify error. Ignore this, it will work anyway.

Don't play around with AVRPROG after this, it may damage your

firmware. Simply reset the bootrst flag with ponyprog afterwards

and you are done. It should now work with AVRstudio 4 from scratch.

If not, erase the chip and repeat the whole procedure carefully.

As the JTAG interface gets it's supply from the target, ist is

possible to debug 3,3V parts, but it may be that the RS232 coverter

(MAX232) does not work with 3,3V. Use another part in this case

(MAX3323 may work, but not tested).

Everything you need (including sources and schematics) is inside the

archive http://home.sch.bme.hu/~cell/atmel/AVR_JTAG/avr_jtag.zip

Original bootice site is at http://www.case2000.com/JtagIce/bootice.html

Many thanks to Antti Lukats and Marcell Gál.

Good luck!


A command-line based DOS..XP program for the Atmel or clone JTAG:

http://www.avrfreaks.com/Tools/showtools.php?ToolID=470


See also