Jump to content

Mizar32/JTAG

From Wikibooks, open books for an open world

Introduction

[edit | edit source]

JTAG is a technology that allows you to debug digital hardware by reaching inside the chip on a board while they are running to read and change their contents.

You can use it to erase and reprogram the whole of the AVR32UC3A's flash memory, including the USB DFU boot loader that lives in the first 8KB.

While the AVR32 is running, you can use it to stop the program, examine the contents of CPU registers and memory, and set the program running again, as well as setting hardware breakpoint and more.

Hardware view

[edit | edit source]
An AVR JTAG ICE MKII programmer and Mizar32 board
An AVR JTAG ICE MKII and Mizar32

Every Mizar32 main board has a 10-pin JTAG connector. To use it you will need an external JTAG emulator such as Atmel's AVR32 JTAG ICE MKII.

Software view

[edit | edit source]

To talk to the Mizar32 via a JTAG converter, you will also need to install some programs.

Atmel now only support JTAG if you use their graphical development environment AVR32 Studio 6.

The command-line tools, avr32program and/or avr32gdbproxy, are now hard to find.

Installing command-line tools

[edit | edit source]

Finding them

[edit | edit source]

The ancient Atmel AVR32 GNU Toolchain version 2.4.2 contains some extra tools that were left out of the later releases. They no longer publicise it but you may still be able to download it from:

Installing avr32program on Debian/Ubuntu

[edit | edit source]

To be able to use a JTAG programming device, you need to install the avr32program command. It used to be included in Atmel GNU Toolchain up to version 2.4.2 but for some reason it is omitted from later versions. Here, we show how to install it on a modern 32-bit version of Debian or Ubuntu from the Atmel's Ubuntu 9.04 bundle:

mkdir tmp; cd tmp
wget http://www.atmel.com/Images/avr32_gnu_toolchain_2.4.2_ubuntu_904.zip
unzip avr32_gnu_toolchain_2.4.2_ubuntu_904.zip

This creates fifteen *.deb package files, most of which are not useful. Install the necessary packages:

sudo dpkg -i avr32program* libavr32ocd* avr32parts* libavrtools*

and if that complains about

dpkg: dependency problems prevent configuration of libavrtools:
 libavrtools depends on libboost-filesystem1.34.1 (>= 1.34.1-8); however:
  Package libboost-filesystem1.34.1 is not installed.
 libavrtools depends on libboost-thread1.34.1 (>= 1.34.1-8); however:
  Package libboost-thread1.34.1 is not installed.
...
 avr32program depends on libavr32ocd (>= 4.1.0); however:
  Package libavr32ocd is not configured yet.

fetch and install the ancient libraries it requires:

wget http://archive.debian.org/debian/pool/main/b/boost/libboost-filesystem1.34.1_1.34.1-14_i386.deb
wget http://archive.debian.org/debian/pool/main/b/boost/libboost-thread1.34.1_1.34.1-14_i386.deb
wget http://archive.debian.org/debian/pool/main/x/xerces-c2/libxerces-c28_2.8.0-3+lenny1_i386.deb
wget http://archive.debian.org/debian/pool/main/i/icu/libicu38_3.8.1-3+lenny3_i386.deb
sudo dpkg -i libboost* libxerxes* libicu*

and complete the installation:

apt-get -f install

Atmel's packages for Ubuntu 9.10 contain the same software as the ones for 9.04 but depend on obsolete library versions that are even more difficult to find.

If you have a 64-bit installation of Ubuntu, your life is even more difficult because:

  • Atmel only distributed 64-bit versions of their software for Ubuntu 9.10
  • avr32program and avr32gdbproxy require you to install libboost-thread1.38
  • Debian never shipped libboost-1.38 and Ubuntu's boost1.38 archive is mysteriously empty

This leaves you two options

  • find the boost-1.38 packages that the programs require
  • install the 32-bit packages from 9.04 and the 32-bit versions of all the libraries that they require

Good luck! Let me know how it turns out...

Installing avr32gdbproxy on Debian/Ubuntu

[edit | edit source]

Another program, avr32gdbproxy can be used with an AVR32 JTAGICE Mk.II JTAG programming device to debug C code running on the board. It needs similar magic as avr32program:

dpkg -k avr32gdbproxy* libavr32sim* libelfdwarfparser*

and, if it complains about libboost-date-time and libmpfr1ldbl being missing, go

wget http://archive.debian.org/debian/pool/main/b/boost/libboost-date-time1.34.1_1.34.1-14_i386.deb
wget http://archive.debian.org/debian/pool/main/m/mpfr/libmpfr1ldbl_2.3.1.dfsg.1-2_i386.deb
dpkg -i libboost-date-time*.deb libmpfr*.deb 

and finally

apt-get -f install

which should fetch and install libgmp3c2 if it wasn't already installed.

Using JTAG

[edit | edit source]

Programming the firmware using avr32program

[edit | edit source]

These days we usually use the USB DFU bootloader to reprogram the Mizar32. The last SimpleMachines firmware release to include JTAG programming commands and binaries was Mizar32 firmware release 20110320 for the 128K model but you can reuse that release's scripts and files with the eLua binaries from more recent ones.

The sequence of commands to erase and reprogram the whole device is fairly complicated, so download the above release and check program-mizar32-jtag.sh

You will need to connect an AVR32 JTAG ICE MKII programmer to your PC with its USB interface and to the Mizar32 via the 10-pin JTAG interface. Apply power to both.

Install the avr32program program (see above) then fetch and program the firmware:

wget http://mizar32.googlecode.com/files/mizar32-firmware-20110320.tgz
tar xfz mizar32-firmware-20110320.tgz
cd mizar32-firmware-20110320
sh program-mizar32-jtag.sh

This will reprogram the entire contents of the flash memory: the USB DFU boot loader, the ISP configuration word, the general-purpose fuse bits and the eLua interpreter. It will then start the board running.

Debugging eLua with avr32gdbproxy

[edit | edit source]

You will need:

  • avr32-gdb, as included in Atmel's GNU Toolchain releases
  • avr32gdbproxy - see above
  • An .elf on the your PC, the same one that you programmed to the Mizar32
  • A JTAG programmer device (USB-to-JTAG converter)

and with everything connected up, turned on and running, say on the PC:

 $ avr32gdbproxy &    # Start the proxy daemon, listening on port 4711
 $ avr32-gdb *.elf    # Whichever .elf file you programmed to the Mizar32
 gdb> target extended-remote localhost:4711
 gdb> run

Good luck!

Further Reading

[edit | edit source]