Skip to content

Re-programming And/Or Modifying The DFU Bootloader

Published On:
May 19, 2015
Last Updated:
May 19, 2015

The AT32UC3 series of microcontrollers come with a pre-loaded USB bootloader. This allows you to program the devices through a USB connection with a computer without the need for an ISP or JTAG programmer.

This tutorial explains how to re-program, and/or modify the AT32UC3 bootloader. Atmel does not make this an easy task. Think again if you thought you could do it with a few clicks from within Atmel Studio 6. The documentation is sparse, the downloads (yes it requires many different programs) scattered around the back corners of their website, it involves many command-line operations, and the process filled with little gotchas and workarounds. Anyway, always look on the bright side of life? Right? Let us continue…

Choose An Operating System To Work Within

I choose Linux because command-line utilities such as make are more at home within Linux than Windows.

Getting The Source Code

The first thing to do is get the bootloader source code. This is contained within the AVR UC3 Software Framework (currently at v1.7.0). This can be found at https://code.google.com/p/goddac/downloads/detail?name=AVR-UC3-SoftwareFramework-1.7.0.zip. Since we will be modifying files in this project, unzip it in your home directory.

Terminal window
$ unzip AVR-UC3-SoftwareFramework-1.7.0.zip

This should put all the files into a directory called 1.7.0-ATUC3. Sweet! Now you can find the bootloader source code at 1.7.0-AT32UC3/SERVICES/USB/CLASS/DFU/EXAMPLES/ISP. In this directory you should find the source code and associated headers (isp.c/h, usb_dfu.c/h). There are also sub-directories containing files specific to the different sub-families of the AT32UC3 (e.g. AT32UC3A, AT32UC3A3, AT32UC3B, …).

At this point I will pick a particular sub-family for the rest of the tutorial, the AT32UC3A. Obviously, replace all occurrences of this name with your particular sub-family. If you navigate into the AT32UC3A sub-folder, you will find an IAR and a GCC folder. Since we are using Linux, and the license for GCC does not cost any money, we will choose GCC. Go into the GCC folder.

Your path should now be:

1.7.0-AT32UC3/SERVICES/USB/CLASS/DFU/EXAMPLES/ISP/AT32UC3A/GCC

If you just run make, you get the error:

*** multiple target patterns. Stop.

So, it turns out someone at Atmel forgot to do a make clean before zipping up the project. The folder structure has residual .d files from a previous build step. These .d files contain Windows style paths. The Makefile is trying to parse these .d files and this is what is causing the multiple target patterns error. So you need to deleting all of the .d files to fix this.

Downloading The Toolchain

Linux

Install AVR Toolchain for Linux from http://www.atmel.com/tools/atmelavrtoolchainforlinux.aspx .(Windows versions can be found at http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx). Note you have to install both the source code (.tar.gz file) and the headers (.zip file) to /opt:

Terminal window
$ sudo tar xzf avr-32-gnu-tool-chain-linux_x86_64

and

Terminal window
$ sudo unzip atmel-headers-6.1.3.1475.zip

Add /opt/avr32-gnu-toolchain-linux_x86_64/bin to the PATH variable.

You will then get an error similar to:

../../BOOT/boot.S:47:22: error: avr32/io.h: No such file or directory

Add /opt/atmel-headers-6.1.3.1475/ to the end of the INC_PATH variable in the config.mk file to fix this

Then run make and it should actually work! But…it is probably not configured for your exact microcontroller.

Tweaking config.mk

As previously mentioned, the file . The default is:

Part: &#123none|ap7xxx|uc3xxxxx&#125

PART = uc3a0512

You will need to change this to suit your exact microcontroller. For example, I changed it too:

PART = uc3a3256

You will also have to change the board.

Building

Run the command make.

Ohoh, the size of the .bin file is more than 8kB! I believe this is because Atmel used the IAR compiler, which results in slightly less code than the GCC compiler, even with the -Os optimisation flag set (this is set by default in config.mk). The pre-compiled bootloader binary that Atmel provides for the AT32UC3A3 microcontroller family (at32uc3a3-isp-1.0.3.bin) clocks in at a tidy 7,617B.

Modifying The Bootloader Size

In conf_isp.h, you’ll want to change:

#define PROGRAM_START_OFFSET 0x00002000

to

#define PROGRAM_START_OFFSET 0x00004000

Post-Build Programming

Now for post-build steps…

Need to change permissions of post-build.sh file.

Terminal window
$ sudo chmod +x post-build.sh

Run it. You should get the error: cannot find avr32program. To fix this, download the linux version of AVR32 Studio v2.6 (it must be v2.6, v2.5 does not have the available tools) from
http://www.atmel.com/tools/Archive/AVR32STUDIO2_6.aspx to /opt/. Unzip with
unzip avr32studio-ide-2.6.0.753-linux-gtk.x86_64.zip. This will unzip all the files into a directory called as4e-ide.

avr32program should be found at as4e-ide/plugins/com.atmel.avr.utilities.linux.x86_64_3.0.0.201009140848/os/linux/x86_64/bin. This needs to be added to your path.

But wait, what about atprogram, the newer replacement for avr32program, can we use that? Yes. And this would be the way I recommend. The commands to program the bootloader are:

Terminal window
atprogram -t jtagice3 -i jtag -d at32uc3a3256 chiperase
atprogram -t jtagice3 -i jtag -d at32uc3a3256 write -o 0x808001FC --values 0x929E2A9E
atprogram -t jtagice3 -i jtag -d at32uc3a3256 program -o 0x80000000 -f at32uc3a3-isp.bin --verify write -fs -o 0xFFFE1410 --values FFF7FFFF

This was designed for the JTAG ICE 3 and the AT32UC3A3256. Change these accordingly.