Practical
Embedded Java

Blink Level One


A practical engineering approach to using embedded Java in real-world applications.


...



This is a getting started tutorial for Systronix aJile based systems. It will introduce compiling, building, loading and running basic embedded java programs.

Blink Level One
Goals of Blink Level One This is a getting started tutorial for the JStamp, JStik and Saje real time Java modules. This tutorial will teach you how to create and load a simple program into an aJile native controller. You will be able to use the source code and instructions in this tutorial to build your own native Java programs.
Step One: Changing and compiling the example program

This step is needed to make sure that your Java development environment is set up correctly. Many vendors, including Sun, Systronix and the Eclipse project have published a great deal of information to help you to compile Java programs. This step will describe the general structure of the example program and provide links to this information.

You will need to recompile the example program to get your module's heartbeat led to blink. The build files included in this tutorial will only print an error message to the Charade console to begin with.

Step Two: Creating your first JemBuilder aJile project file This tutorial will explain how to set up your first project using the JemBuilder new project menu and will show you where all the settings you just added ended up in the user interface.
Step Three: Building your first native Java executable This step will explain how to save your new .ajp (aJile project file) file to disk for future use and how to build your first set of binaries. The files in your output directory will be briefly explained.
Step Four: Loading and running your program using Charade This step will show you how to load and run your program. The example program requires no input. Output will be on a light on your module and as debugging messages in the Charade console.
Tutorial Trouble Shooting This section describes some common problems and solutions.
What to expect in Blink Level Two

You are likely to have many questions on how to do various things with the tools. Blink Level Two is a tools tutorial that will explain the settings in both JemBuilder and Charade and will include detailed configuration and debugging instructions to help you solve common software problems.

Blink Level Two will give a description of all the settings in JemBuilder It will include a new example program that uses JemBuilder system properties to dynamically select which pin to blink to light your heartbeat led on Jstamp, JStik or Saje, without recompiling the example code. Blink Level Two will also show you how to include additional .jar class libraries in future projects and how to build programs to be loaded into flash for execution without a JTag connection.

Blink Level Two will also explain how to use Charade as a debugger by explaining how to set up watch variables, how to check on the status of a currently executing program, and how to determine whether you should run your program from flash or ram.


Required Files
aJile runtime and Systronix configurations You will need JemBuilder and Charade to successfully run java programs on JStamp, JStik and Saje.
Example Code

This zip file contains example source code, a pre-built classes directory and pre-built embedded java executables.


Step One: Changing and compiling the example program

This tutorial will be a step by step example of how to compile the example program using the Eclipse IDE. You will also be able to do this using your choice of development environment. We will try to explain each setting as we go along.

If you have not installed to tools below, visit http://www.practicalembeddedjava.com/tools/javatools.html for more information.

  • aJile Tools: Installed as a single package, includes JemBuilder and Charade.
  • Systronix Configurations: Required to load code onto Systronix modules.
  • Eclipse: This section of the tutorial will be from the perspective of developing with Eclipse. If you already have and prefer a different compiler, make sure you are able to compile the included source files and output your finished class files to the same directory as listed later in this tutorial.

First, unzip the example project into a convenient directory. Next, create a new project in Eclipse, select File->new, then Java->Java Project. Give your new project a logical name, uncheck the "Use default" checkbox and select your unzipped directory as the project contents to put it in as shown below.



Click next in the wizard. Eclipse should automatically locate the src directory as the location of your source code. Feel free to change the output directory to "classes", like we have used in our zip file, or whatever you prefer for a place to put your compiled java code. Next, click on the "libraries" tab to set up your classpath for the aJile runtime. Remove the JDK 1.4 runtime from the jars and class folders on the build path. Click on the "add External Jars" button and browse to the %AJILE_HOME%/Runtime_cldc directory. Open the "classes.jar" file. Next, you will need to add the %AJILE_HOME%/Runtime_cldc/Rts directory to include the needed files for driving leds. To do this, you will need to add a classes folder to your project and then link that folder to the appropriate directory. Click "Add class folder" in the wizard and then click "Create new Folder", then "Advanced". Type in an appropriate name in the Folder name field, click the checkbox to "Link to folder in the file system" and browse to the Rts directory. Click the OK buttons until you get back to the new project wizard and then click "Finish" to create the BlinkTutorialLevelOne project.

This process can be simplified by setting up a new JRE system library in Eclipse. That method of setting up your aJile classpath will be discussed in Blink Tutorial Level Two. The method shown here illustrates the basic ways you can include your existing .jar archives and class folders in your java build path. You can return to the classpath setup windows shown here by right clicking on your finished project root folder, selecting "properties" in the menu, and then selecting "Java build path".

Next, open your source file as shown below in java perspective (click the icon with a "J" on it in the far left toolbar as shown in the screen shot). You should not see any red X marks as shown in the screen shot below. All the files and resources in the project should appear in the left hand pane and the BlinkTutorialLevelOne.java source file should appear in the editor window to the right.

To successfully get your module's led to blink, you will have to change the highlighted text from UNDECIDED_LED to the led identifier corresponding to your hardware. For example, if you are using a JStik, change UNDECIDED_LED to JSTIK_LED.
One of the great features of Eclipse is that all you have to do to compile your source file is to save the file using the disk icon in the top toolbar. Once the asterisk no longer appears next to the filename in the title bar of the editor frame, you will know that the class file in your classes or bin directory has been compiled to the source code in the window.

Step Two: Creating your first Jembuilder aJile project file

JemBuilder has been a great tool to help Systronix and other OEM developers configure hardware and set up semi-custom peripherals such as Ethernet and One Wire adapters. However, it has proven to be a challenge to beginning users due to a lack of online help and a large number of options irrelevant to simple projects. These instructions are meant to help you set up simple java programs with the minimum amount of custom configuration. See Blink Tutorial Level Two for an in depth discussion of JemBuilder options. Example JemBuilder configuration files will be provided in the tutorial .zip file to serve as a reference point. In general these files are not portable and will not work with user systems because of a large number of absolute file system paths.

To begin configuring your Systronix real time module, open jembuilder from the Start->aJile->JemBuilder menu. Select File->new project from the menu bar to enter the new project wizard. Click on the three dots next to the text box to browse for an appropriate output directory. This browse button does not use native controls, so may be a little tricky to use. You will need to create a directory to put your finished binary files to select it in the control and the directory under "File Name" must exist for the Open button to work. An empty text box will prevent you from selecting the current directory, so you must use the up arrow to move up a directory. Watch out for the middle folder button because it will send you back to your home directory without an easy way to get back. All the browse buttons in JemBuilder work this same way.

Press the next button to select your hardware. Make sure "Runtime_cldc" is selected as the runtime and your module is selected under configuration. For this tutorial, make sure to select a ram configuration.

Click "Finish" to move on to creating your first JVM (Java virtual Machine). The next step of the wizard simply asks for you to name your jvm. I like describing the project here so that I can recognize which project I am working on more easily. I have chosen "BlinkTutorialLevelOne" as my JVM name. Click Next, type the name of the example main class for the tutorial, "com.systronix.examples.BlinkTutorialLevelOne" into the main class text box. Click Next, and the three dots to the right of the classpath text box to enter your classpath. Browse to the Eclipse project directory for this tutorial and single click on your Eclipse output folder. Click "Add", then "OK" to get back to the classpath New JVM step 3 of 4 window. Your Eclipse output directory should now appear in the "Enter the Classpath for this JVM" text box.

Click next to get to the "Add drivers to JVM" step. To enable aJile output pins, like are used to blink Systronix module heartbeat leds, "Port_A" and "Port_B" drivers must be included as shown below. The other drivers are used to enable other hardware. To add a driver, click its name in the box on the left and then click the right arrow. To remove a driver, click its name in the right hand box and click the left arrow.

Click Finish to complete your new JemBuilder project. Save your project by selecting File->Save. To build the project, click the red box in the toolbar, or select "Project->Build" from the menu bar.


Step Three: Building your first native Java executable

Now that you have created your JemBuilder project file, you can create or rebuild an executable program for JStamp, JStik, or Saje at any time by clicking on the red circle button in the toolbar or by selecting Project->Build from the menu bar. You can save your project to be built later by selecting file->save and reload your project from file->recent files, or file->open project.

This step of the tutorial will explain how to view and change the settings you just entered in the new project wizard. You will have to know how to change these settings to use JemBuilder .ajp files provided in other Systronix tutorials and app notes due to issues with absolute, user dependant paths. There will be many visible settings that will not be explained until the next blink tutorial.

The most commonly used setting in JemBuilder is the "Output Files" setting. This setting contains the "Output Directory" which contains the .bin file to be loaded into Charade. The highlighted text illustrates that any text that can be input by the user, as well as the build output, can be copied to the windows clipboard with the Ctrl-C keyboard combination. This is true even though the edit menu does not contain a cut or copy option.

The target module and runtime can be changed from the Project->Properties menu bar menu item. To change modules, change the "Target Configuration" text box. Multiple Java programs can be run at the same time by clicking the "New JVM" button. See the AJ-100 reference manual for details.

The classpath can be changed with the JVM (In this case BlinkTutorialLevelOne)->Classpath tree folder item in the left hand frame. It works the same way as the new JVM wizard. Drivers can be changed with the Project->Drivers menu. This will bring up the same tool as the new JVM wizard uses to add and remove drivers to the JVM.


Step Four: Loading and running your program using Charade

Charade is the runtime debugger for aJ-100 and aJ-80 based modules. You must have your module powered and connected to your JTag adapter before starting Charade. Each Systronix development kit includes a "Swap Memory" jumper used to select between a boot from Ram and a boot from Flash. This jumper must be installed for the proper operation of this example because we selected a Ram configuration in a previous step. Consult your module's quick reference for additional details.

JStamp and JStamp+ are aJ-80 based and JStik and Saje are aj-100 based. You must select the proper processor in the Charade Device menu as shown below. It is also a good idea to use the cd command to change directories to the JemBuilder output directory as shown in the Charade command line in the illustration.

The target directory is highlighted to remind you that you can copy and paste the JemBuilder output directory to the Charade command window using the Ctrl-C key even though JemBuilder's edit menu does not have these options. Warning: if the jembuilder output directory contains spaces, it will not be possible to change directories to the output directory. Remove all white space from your project paths.

After you have connected your module to your JTag adapter, started Charade and changed directories to your JemBuilder output directory, you will be ready to load your new java program onto your module to be executed. Click the "Load" button in Charade, or type "@load" into the command prompt to load the example program into Ram. Click the "Go" button to halt, reset and run your program, or click the "run". If you have not re-compiled the program, you will get the following output in Charade:

-> @load.sod
[load]-> -- aJile Charade load script file
[load]-> -- This file was auto-generated
[load]->
[load]-> Halt
[load]-> Reset
[load]->
[load]-> load J:/USER/landrews/PROJECTS/lessons/examples/Blink/JStampRamBuild/build.jcf
Reading file: j:/user/landrews/projects/lessons/examples/blink/jstamprambuild/build.jcf
Reading file: J:\USER\landrews\PROJECTS\lessons\examples\Blink\JStampRamBuild\build.bin
Configuration: JStampRamConfiguration
Runtime: Runtime_cldc Version 3.16.09
ucode version: 0x45
J:\USER\landrews\PROJECTS\lessons\examples\Blink\JStampRamBuild\build.bin
jemcfg 2.00.02 November 10, 2003 8:25:07 PM MST executive
e:\aJile\Runtime_cldc\ucode\aJ-100_uram.bin
created on Sat Jan 25 21:07:02 2003 (GMT)
Loaded 101976 bytes
== SYSTEM ===========================
=+ Bin file: J:\USER\landrews\PROJECTS\lessons\examples\Blink\JStampRamBuild\build.bin
== [jemcfg 2.00.02 November 10, 2003 8:25:07 PM MST executive]

-- VM #0 ----------------------------
-- RAM start: 000042f8 end: 00050edb (307.0 KB)
-- ROM start: 00050edc end: 00065bbb (83.2 KB)
-+ Map file: J:\USER\landrews\PROJECTS\lessons\examples\Blink\JStampRamBuild\BlinkTutorialLevelOne.map

File 'j:/user/landrews/projects/lessons/examples/blink/jstamprambuild/build.jcf' loaded successfully
[load]->
[load]-> -- Run User Defined Startup Macro(stored in f.sod file)
[load]-> @setup
Textio mode (tx): on
[load]->
[load]->
[load]->
vm.0 charadeIO active
vm.0 heap monitor active
vm.0 heap monitor active
[TEXTIO.0]->Hello from Systronix JStamp, JStik and Saje blink example
[TEXTIO.0]->This code has not decided which pin to blink.

[TEXTIO.0]->Please start the tutorial over by editing the source file to selecteither JSTAMP_LED, JSTIK_LED, or SAJE_LED for LED_PIN
.
[TEXTIO.0]->No pin will blink.

As stated, no LEDs will blink. If you did successfully recompile and build the program, the LED will blink and the only Charade message will be:
[TEXTIO.0]->Hello from Systronix JStamp, JStik and Saje blink example

Congratulations on your first embedded Java program. If you have run into some problems in any of the previous steps, see the trouble shooting section for possible solutions. For more information about using the aJile runtime tools, see the Blink Level Two tutorial.


TroubleShooting
Problem Solution
Compiler error "Missing Type, java.lang.Object"

This is caused by an incorrect java classpath. Make sure to include %AJILE_HOME%\Runtime_cldc\classes.jar in your classpath. See Step One for Eclipse based instructions.

Compiler errors "Missing Type, com.ajile.*drivers and a bunch of different stuff* This is caused by an incorrect java classpath. Make sure to include %AJILE_HOME%\Runtime_cldc\Rts in your classpath. See Step One for Eclipse based instructions.
Jembuilder error: Unable to find class "com/systronix/examples/BlinkTutorialLevelOne" This is caused by an incorrect JemBuilder classpath This will occur if you attempt to use the unmodified .ajp files included with this tutorial. This can be fixed by changing the JemBuilder classpath as described in Step Three.
Jembuilder error: Unable to find class {anything other than com/systronix/examples/BlinkTutorialLevelOne} This is caused by incorrectly typing in the main class name of the jvm. Enter "com/systronix/examples/BlinkTutorialLevelOne" into JVM->Main->Name of main method as described in Step Three. Do not include the quotes.
Jembuilder error: ** (Fatal): unable to open batch file: This is caused by a JemBuilder output folder setting that corresponds to a folder Jembuilder cannot create. This will occur if you attempt to use the unmodified .ajp files included with this tutorial. This can be fixed by changing the JemBuilder output directory as described in Step Three. Make sure that you have Windows permissions to write to the disk and directory this folder points to.
Charade: ***** ERROR ***** Cannot open

This is caused by attempting to load something into Charade without first completing building in JemBuilder, or by loading from an incorrect directory. Rebuild your JemBuilder project, make sure it successfully builds. Next, change directories in Charade as described in Step Four and try loading again.

Charade: Program loads successfully, no output from program when attempting to run Make sure that you have selected the correct device in the Charade device menu. Jstamp and JStamp+ should have aJ-80 selected, JStik and Saje should have aj-100 selected.
Charade: Target power removed status below console window title bar, multiple message boxes.

Make sure your device is properly powered and the JTag pod is connected to the proper JTag connector. Also check the other end of the cable to make sure the cable is connected to your PC. The green light of your JTag pod should be on and the red light should blink.

When Charade starts printing out large amounts of information to the console or starts displaying multiple message boxes, you can usually get it to stop by pressing the esc key.

Charade: Processor not responding message box Make sure your device is powered and the JTag pod is connected. After that, press "Reset" and go to the another trouble shooting entry if code does not begin to load.

 


 
Systronix® 939 Edison St, Salt Lake City, Utah, USA 84111
Tel +1-801-534-1017, Fax +1-801-534-1019
contact us     Time Zone: MDT (UTC-6)
 

Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Systronix is independent of Sun Microsystems, Inc.
TStik, JStik, JCX, JStamp, JSimm, JDroid, and JRealTime are trademarks of Systronix, Inc.
1-Wire, iButton and TINI are trademarks of Dallas Semiconductor
Simmstick is a trademark of Dontronics
LEGO® is a trademark of Lego A/S, Denmark