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:
- Support for standard java bytecode
- Tested on AVR Mega8 and Mega32
- Configurable 15/31 bit integer arithmetic
- Optional float support
- Garbage collection
- Bootloader for simple application upload
- Tested with Suns JDK and IBMs jikes
- Supports inheritance
- Unified stack and heap architecture
- Requires less than 8kBytes of code memory
- at least 512 Bytes code storage for java byte code (e.g. the complete 512 eeprom bytes available on the AVR ATmega8 CPU)
- at least 768 Bytes application RAM available (of 1k total RAM available on the AVR ATmega8 CPU)
- About 20k Java opcodes per second on 8 Mhz AVR
- Native classes include:
- java/lang/Object (object handling)
- java/lang/System (IO handling)
- java/io/PrintStream (console output)
- java/lang/StringBuffer (string processing)
- asuro (asuro control)
- Native support for LCDs, AVR io etc
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.
Although the NanoVM can be used for various purposes, it somehow became especially popular with robotic development kits. The latest NanoVM supports:
- The Asuro was the first robot supported by the NanoVM,
- it was then ported to the c’t-Bot,
- and the Nibo was even designed for NanoVM support.
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.
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.
- Linux rxtx installation script
For more detail: Java virtual machine for the Atmel AVR ATmega8