# Flashing firmware images

There are several ways to write new firmware images to the Mizar32:

## With the USB DFU bootloader

The first 8KB of the Mizar32 flash memory comes pre-programmed with Atmel's USB DFU boot loader, which is able to write to the rest of the flash memory. To talk to it, you can use Atmel's closed-source 'flip' and 'batchisp3' tools, which are awful, or the free and open-source 'dfu-programmer' which is OK.

### Using dfu-programmer

dfu-programmer is an open-source program to talk to the USB DFU boot loader. It is included in Debian and Ubuntu, for which the installation step is (as root):
Fetch the firmware:
Now
* Connect the Mizar32 to your PC with a USB cable
* Power the Mizar32 on (or press its reset button) while holding the user button (SW2) depressed
* On the PC, issue the commands:
If you have the Mizar32 model A:
For the Mizar32 model B:
For the Mizar32 model C:
If it says dfu-programmer: no device present., try running it as root. If so, and you want anyone to be able to run it, you can go, as root:
though this opens a security hole so, if you may have malicious users logged into your system, it might be better to add yourself to group "admin" in /etc/group and go:
Note that the Debian/Ubuntu program "dfutool", included in the "bluez" package, is something completely different.

#### Bugs in old versions of dfu-programmer

There is a bug in dfu-programmer v0.5.1 which very occasionally misprograms the flash. The symptom is
The bug is fixed in dfu-programmer-0.5.2 and later.
As if that weren't enough, the Mizar32A carries the automotive-quality ultra-robust version of the AT32UC3A chip with 512KB of flash memory, which takes a few seconds longer to erase its flash memory than dfu-programmer expects (about 14 seconds instead of 10).
This is fixed in dfu-programmer-0.5.5 and later but Debian and Ubuntu still have 0.5.4. You can check the version of your installed dfu-programmer by saying
and you can install a more recent version by compiling from source:

#### Further reading

* The Atmel USB DFU Programmer project at sourceforge

### Using batchisp3

Atmel publishes closed-source programs to talk to the USB DFU boot loader: the graphical "flip" and the command-line "batchisp3". They are both of poor quality and only the second one is currently usable with AT32UC3 parts.
Note that the Debian/Ubuntu package "flip" is something completely different.
Installation on Ubuntu (as root) is (adapted from eLua's AVR32 platform info):
(on Red Hat systems, the USB_DEVFS_PATH runes should be omitted).
To get flip to work at all, you have to cd /usr/local/flip.3.2.1/bin first, and it doesn't yet support AT32UC3 parts so we can only use the command-line batchisp3 program:
* Connect the Mizar32 to your PC with a USB cable
* Power the Mizar32 on (or press its reset button) while holding the user button (SW2) depressed.
* On the PC, issue the command
Note that you have to explicitly give the full pathname of the firmware file (the $PWD/ trick here). Otherwise it looks for the firmware file in /usr/local/flip.3.2.1/bin/.
Further reading
* The Atmel USB DFU Bootloader Datasheet
* The FLIP home page

#### Using Batchisp under Windows Vista/7 32bit

* Download the latest version of Flip for Windows from Atmel's web site (BATCHISP.EXE is inside the Flip installer) and follow the instructions for installation. At the moment, only Batchisp supports AT32UC3A microprocessors while Flip does not support its yet, so you must install Flip but can't use it.
* Activate the DFU Bootloader: connect the Mizar32 to your PC with a USB cable, connect the power plug and press and hold the reset button while holding the user button (SW2), then release the reset button, then release the user button.
* Go to the Windows Control Panel, right-click on Computer → Properties → Device Manager → right-click on 'AT32UC3A DFU' → Update Driver Software → 'Browse my computer for driver software' and select the path Flip\usb (here, it's c:\Program Files (x86)\Atmel\Flip 3.4.3\usb\) and click OK. Now Windows tells you 'Windows can't verify the publisher of this driver software' click on 'Install this software anyway'. Now your Mizar32 driver for Batchisp is installed.
* Open your Windows Command Processor: Start → type 'cmd' in 'Search command and file' → Right-click on cmd.exe → Start as Administrator. Type 'PATH' followed by entire path of your Batchisp.exe directory; on our machine the command is:
* Restart Windows. Now Windows is able to find the Batchisp.exe program
* Download and decompress this file in some directory. Run your Windows Command Processor: Start → type 'cmd' in 'Search command and file' → Right-click on cmd.exe → Start as Administrator. Type the following command (this command is case sensitive):
where:
* at32uc3aXXXX is your Atmel device that can be: at32uc3a0128, at32uc3a0256 or at32uc3a0512.
* \Mizar32_firmware_directory\ is the entire PATH where you stored the Mizar32 firmware.
* elua_lualong_at32uc3aXXXX.elf is the firmware version.
For example, you can flash a Mizar32 B (the 256Kb version) with this command line:
If batchisp can't run because "MSVCR71.dll is missing"
* download the file msvcr71.dll into your Flip\bin directory (on this PC it's c:\Program Files (x86)\Atmel\Flip 3.4.3\bin\)
* Re-type the batchisp command above to update Mizar32 firmware.
Further reading
* The Atmel USB DFU Bootloader Datasheet
* The FLIP home page
Please report any feedback or suggestions on this procedure to support@simplemachines.it

#### Using Batchisp under Windows Vista/7 64bit

* Download the latest version of Flip for Windows from the Atmel web site (Batchisp.exe is inside Flip installation). Follow the video instructions for installation. At the moment only Batchisp supports AT32UC3A microprocessors; Flip does not support it yet, so you have to install Flip but can't use it.
* Download and unzip this USB driver, because Atmel's original drivers are unsigned and Windows Vista/7 64bit does not let you install unsigned driver. Unpack the .zip file downloaded in the Flip\usb folder; on our machines the folder is:
* Activate the DFU Bootloader: connect the Mizar32 to your PC with a USB cable Connect the power plug and press and hold the reset button while holding the user button (SW2), release the reset button, then release the user button.
* Go to the Windows Control Panel with: right-click on Computer --> Properties --> Device Manager --> right-click on 'AT32UC3A DFU' --> Update Driver Software --> 'Browse my computer for the driver software' and select the path where you copied the new USB signed driver (on this machine c:\Program Files (x86)\Atmel\Flip 3.4.3\usb\atmel-flip-3.4.2-signed-driver) and click OK. Now your Mizar32 driver for Batchisp is installed.
* Open your Windows Command Processor: Start --> type 'cmd' in 'Search commands and files' --> Right-click on cmd.exe --> Start as Administrator. Type 'Path' followed by entire path of your Batchisp.exe directory; on our machine the command is:
Path c:\Program File (x86)\Atmel\Flip 3.4.3\bin
* Restart Windows. Now Windows is able to find the Batchisp.exe program.
* Download and unpack this file, then run your Windows Command Processor: Start --> type 'cmd' in 'Search commands and files' --> Right-click on cmd.exe --> Start as Administrator and type the following command (this command is case sensitive):
where:
* at32uc3aXXXX is your Atmel device that can be: at32uc3a0128, at32uc3a0256, at32uc3a0512.
* \Mizar32_firmware_directory\ is the entire PATH where you stored the Mizar32 firmware.
* hempl_at32uc3aXXXX.elf is the firmware file version.
We flash our Mizar32 B (256KB version) with this command line:
Further reading
* The Atmel USB DFU Bootloader Datasheet
* The FLIP home page

## With a JTAG programmer

A JTAG programmer is a device that lets you do more than the USB DFU bootloader, including updating the USB DFU bootloader itself, and requires special software on your PC to drive it.
If you need to do this, please contact support@simplemachines.it