Hempl/Flashing firmware

Flashing firmware images edit

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

With the USB DFU bootloader edit

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 edit

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):

sudo apt-get install dfu-programmer

Fetch the firmware:

wget http://simplemachines.it/files/mizar32-firmware-latest.tgz
tar xfz mizar32-firmware-*.tgz
cd mizar32-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:

dfu-programmer at32uc3a0512 erase
dfu-programmer at32uc3a0512 flash hempl_at32uc3a0512.hex
dfu-programmer at32uc3a0512 start

For the Mizar32 model B:

dfu-programmer at32uc3a0256 erase
dfu-programmer at32uc3a0256 flash hempl_at32uc3a0256.hex
dfu-programmer at32uc3a0256 start

For the Mizar32 model C:

dfu-programmer at32uc3a0128 erase
dfu-programmer at32uc3a0128 flash hempl_at32uc3a0128.hex
dfu-programmer at32uc3a0128 start

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:

chown root $(which dfu-programmer)
chmod 4755 $(which dfu-programmer)

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:

chown root:admin $(which dfu-programmer)
chmod 4750 $(which dfu-programmer)

Note that the Debian/Ubuntu program "dfutool", included in the "bluez" package, is something completely different.

Bugs in old versions of dfu-programmer edit

There is a bug in dfu-programmer v0.5.1 which very occasionally misprograms the flash. The symptom is

$ dfu-programmer at32uc3a0256 flash hempl_at32uc3a0256.hex
Validating...
Image did not validate.

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

dfu-programmer --version 2>&1 | head -1

and you can install a more recent version by compiling from source:

apt-get install libusb-dev build-essential
# Visit http://sourceforge.net/projects/dfu-programmer/files/latest/download
# and save the file it gives to your browser
tar xfz dfu-programmer-*.tar.gz
cd dfu-programmer-*
./configure
make
sudo make install                     # Installs under /usr/local
sudo apt-get purge dfu-programmer     # Remove the old version

Further reading edit

Using batchisp3 edit

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):

apt-get install openjdk-6-jre
cd /usr/local
wget http://www.atmel.com/dyn/resources/prod_documents/flip_linux_3-2-1.tgz
tar xfz flip_linux_3-2-1.tgz
rm flip_linux_3-2-1.tgz

cat > bin/batchisp3 << \EOF
#! /bin/sh
FLIP_HOME=/usr/local/flip.3.2.1/bin
JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre
USB_DEVFS_PATH=/dev/bus/usb
export FLIP_HOME JAVA_HOME USB_DEVFS_PATH
exec /usr/local/flip.3.2.1/bin/batchisp3.sh "$@"
EOF

chmod 755 bin/batchisp3

(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
 batchisp3 -hardware usb -device at32uc3a0128 -operation erase f memory flash blankcheck loadbuffer $PWD/hempl_at32uc3a0128.elf program verify start reset 0

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

Using Batchisp under Windows Vista/7 32bit edit

  • 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:
PATH c:\Program File (x86)\Atmel\Flip 3.4.3\bin 
  • Restart Windows. Now Windows is able to find the Batchisp.exe program
  • Download [1] 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):
batchisp -device at32uc3aXXXX -hardware usb -operation erase f memory flash blankcheck loadbuffer \Mizar32_firmware_directory\elua_lualong_at32uc3aXXXX.elf program verify start reset 0

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:

batchisp -device at32uc3a0256 -hardware usb -operation erase f memory flash blankcheck loadbuffer C:\Users\Simplemachines\Desktop\project\hempl_firmware\0256\hempl_at32uc3a0256.elf program verify start reset 0

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

Please report any feedback or suggestions on this procedure to support@simplemachines.it

Using Batchisp under Windows Vista/7 64bit edit

  • 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:
c:\Program Files (x86)\Atmel\Flip 3.4.3\usb 
  • 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 [2] 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):
batchisp -device at32uc3aXXXX -hardware usb -operation erase f memory flash blankcheck loadbuffer \Mizar32_firmware_directory\hempl_at32uc3aXXXX.elf program verify start reset 0

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:

batchisp -device at32uc3a0256 -hardware usb -operation erase f memory flash blankcheck loadbuffer C:Users\Simplemachines\Desktop\project\elua_firmware\0256\hempl_at32uc3a0256.elf program verify start reset 0

Further reading

With a JTAG programmer edit

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