Support this project:
or send me something from my Amazon wishlist.

The NanoVM - Java for the AVR

The NanoVM is a java virtual machine for the Atmel AVR ATmega8 CPU, the member of the AVR CPU family used e.g. in the DLR Asuro robot, manufactured by AREXX engineering. With the NanoVM, the Asuro can be programmed in the popular Java language using the standard Sun JDK. The NanoVM and its tools are distributed under the GPL and can be used on other AVR based systems as well.

The NanoVM for Asuro replaces the original firmware of the Asuro with a Java virtual machine capable of running a subset of the virtual machine command set. This enables e.g. the Asuro to interpret java bytecode and to run simple java programs like e.g. this one.

The NanoVM is a very resource aware implementation of the java vm. The Asuro version including a boot loader and several native classes fit into the 8kBytes flash rom of the Asuros AVR ATmega8 CPU. The complete 512 Byte EEPROM space of the CPU are available as Java program space and 75% of the 1 kByte RAM space are available to the running Java program.

The current version of the NanoVM for Asuro includes:

What the NanoVM is and what it isn't

There seems to be some confusion about what the NanoVM is and can do and what it can't and isn't.

It is not a full featured Java VM and it will never be. It will always be limited to a small subset of the java language and the standard java libraries and a few application specific methods. Furthermore, it is not meant to replace C as the standard way of programming microcontrollers. It is less flexible and has a lower performance than C or assembler programs.

The NanoVM is a way to provide a limited but controllable programming interface to a microcontroller based device. With most of the most hardware specific code being part of the NanoVM itself, the user can focus on the application itself. If a user is given a device equipped with the NanoVM he is not required to think about the hardware itself. Furthermore, he doesn't need any target specific compilers or the like. All he needs is a standard java compiler and the NanoVMTool which itself is written in java. Thus, the whole development chain works on any device that has a java compiler and can run java code. With the hardware abstraction the NanoVM provides, the user doesn't even have to care about the microcontroller type the target is based on. The same java compiler and the same NanoVMTool can be used with any NanoVM based system running on any type of microontroller.

Supported devices

Although the NanoVM can be used for various purposes, it somehow became especially popular with robotic development kits. The latest NanoVM supports:

Files

The NanoVM is distributed in three parts: The NanoVM itself to be installed on the target (the Asuro), a Converter and Upload tool to convert java class files into NanoVM format and to upload them onto the target and finally some demo projects for the Asuro.

Installing and using the NanoVM

The NanoVM is a complete replacement of the 8kBytes program code available inside the AVR CPU (see figure). Unlike the original Asuros bootloader, which loads the applicaton into flash memory, the NanoVM uses the EEPROM to store the program code. The usual C development chain translates any application source code directly into native AVR specific code. Unlike this, the NanoVM works with portable Java byte code which is interpreted by the NanoVM during runtime.

Some AVRs like e.g. the ATmega8 that comes with the Asuro are delivered preprogrammed to the user. The pre-installed bootloader allows the user to upload further code onto the CPU. The Asuro e.g. comes with a bootloader that allows to upload code via the IR transmitter delivered with the Asuro. The NanoVM cannot be installed using this mechanism, since the bootloader itself has to be replaced as well. Instead the complete contents of the AVR CPU including the bootloader have to be replaced. This requires the CPU to be placed in some programming board like e.g. the STK-500. Alternally, a simple interface (photo of installed interface) allows you to reprogram the entire chip while its still placed in the Asuro. In both cases the connection to the PC is done via a special AVR ISP programming cable (see e.g. these DIY instructions if you want to build one yourself) connected to a PCs printerport. The NanoVM itself is then being uploaded onto the chip using a software like Ponyprog or UISP.

Since there's currently no way of making a backup of or to restore the original bootloader in the ATmega8 shipped with the Asuro it is strongly recommended to use a seperate ATmega8 CPU for the NanoVM. New unprogrammed AVR ATmega8 CPUs are cheap!

The NanoVM itself contains its own bootloader. Once it is installed in the target system like e.g. the Asuro it can use the IR interface to install Java client programs. A special NanoVM tool (formerly Convert tool) is available for the NanoVM to uplaod Java programs to the Asuro.

Download

As of 9/15/2005, the complete NanoVM incl. the source code and the binaries for the asuro and other officially supported plattforms is distributed in one archive. The rxtx installation script is meant to simplify the installation of the gnu/rxtx java extension on linux PCs. This extension is required to allow the NanoVMTool to access the PCs serial port to directly upload applications to a NanoVM equipped device.

Find the latest version at the NanoVM download page at sourceforge.

Old versions:

If you are interested in the latest changes and are interested in contributing to the NanoVM development, you can take a look at the NanoVM CVS repository.

Your contribution

You want to contribute? Great! Here are some of the things that would be a great contribution to NanoVM:

History

Version 2006/06/13:

Version 2005/12/17: Version 2005/12/04: Version 2005/12/01: Version 2005/09/26: Version 2005/09/15:

TODO

What's left? The VM itself is finished. It is not a full Java VM, since it does not support exceptions, threads, floating point arithmetic and various other things like e.g. inheritance from native classes. Due to memory limitations, these things will probably never be implemented for the Asuro and its ATmega8 CPU (keep in mind, that everything has to fit into 8kBytes of code memory). The generic version lacks a complete set of native classes in order to be really useful to the end user.

The complete NanoVM is open source. Due to that, a plugin for Eclipse might be possible to write. Furthermore, the NanoVM may easily be ported to various other AVR based systems.

A generic NanoVM for the Atmel AVR family

It is possible to use the NanoVM for other projects than the Asuro. The NanoVM for Asuro includes Asuro specific native classes only. The NanoVM distribution includes several more generic native classes for the AVR which can e.g. be used to directly work with the AVRs IO ports, the AD converters, the PWM unit and the serial interface. These native classes are now included in the source archive. Several simple examples are included which show how to use these generic native classes to build your own java controlled AVR application.

The ATmega8 will very likely be the smallest AVR capable of running the NanoVM. There's not much memory left in its 8kBytes flash (about 700 bytes are still free), so there isn't space for plenty of generic native classes. With the bigger CPUs (there are AVRs with up to 32 times the code memory of the ATmega8), even the most complex native classes should be possible incl. e.g. networking and wireless support.

External documentation and discussion

Links