STM32JAVA Embedded Java Solutions for STM32
What is STM32Java? Solution to develop and to deploy software applications on STM32F0 to STM32F7 microcontrollers using Java Help to reduce the total cost of ownership of embedded system design (development, BOM, maintenance and updates) This solution is designed in partnership with:» STMicroelectronics: STM32 manufacturer» IS2T: Software editor (provider of the MicroEJ software platform)
MicroEJ Overview
MicroEJ MicroEJ SDK lets you use Java for embedded system development Goals of this presentation» Discover MicroEJ
Agenda Embedded Java» Why using Java for embedded system development? MicroEJ SDK» What is MicroEJ? Java platforms» What is the concept of software platform? Execution» How do I execute my Java application? Interactions with the native world» How can C and Java communicate? GUI» How to design a rich graphical application?
Embedded Java
Software Complexity 32-bits MCU with important memory Increasing complexity with GUI and IoT
Java Modern object-oriented language» Loose coupling» Managing complexity Portability Memory management» Garbage collector» Ideal for event driven systems Widely used
Java Platform Concept /** * Java Copyright 2009-2012 IS2T. All rights reserved. * For demonstration purpose only. * IS2T PROPRIETARY. Use is subject to license terms. */ package com.is2t.appnotes.microui.mvc; import java.io.ioexception; import ej.microui.eventgenerator; import ej.microui.io.display; import ej.microui.io.flyingimage; import ej.microui.io.image; import ej.microui.io.pointer; Java language /** * Shows three views (bar, pie, text) that represents the same data model (a percentage value). * It is possible to resize the Java technology RTOS JVM Libs RTOS JVM Libs RTOS JVM Libs Java Virtual Machines (JVM - software processors) Microprocessors IS2T 2012
Software Portability Portability is needed when» You want to use the same code for several projects» Your hardware platform becomes obsolete» You target several hardware platforms with the same application When switching to a new hardware platform» You only change the hardware specific parts» You re-create an isofunctional computing platform» Your software runs the same on this new platform Hardware abstracted software is the key point for portability
MicroEJ SDK
MicroEJ SDK Create platforms and software running on these platforms MicroEJ SDK provides» MicroEJ IDE, based on Eclipse» Tools to build platforms» Tools for application development like code coverage or simulation» Libraries to code with Java as high-level language» Native libraries and mechanism to allow developers to use C and to create interactions between C and Java features
MicroEJ IDE
Supported architectures Available» ARM Cortex-M» Cortex-A» Linux» Android» ios Additional architectures on demand
Optimized JVMs for Embedded Systems 32/64-bit CPU Optimized implementation 32-bit MCU/MPU Java Code quality Productivity Reliability Portability Scalability Maintainability Code density Java High speed execution Tiny footprint Interface C/asm Low power,
Java Runtime Compiler version» Java 7 Runtime library» EDC (Embedded Device Configuration)» Close to Java ME MicroJvm virtual machine
MicroEJ Libraries Available libraries» EDC» B-ON» MicroUI» MWT» NLS» ECOM-COMM» Shielded Plug» SNI». Specifications by ESR Consortium» http://www.e-s-r.net/
Example Washing machine Hardware» STM32F2x (Cortex-M3) 120MHz» 16-bit bpp QVGA LCD» Touchscreen Libraries» B-ON, CLDC, MicroUI, MWT, SNI Boot time < 2 ms Application M em ory Requirem ents Flash 422KB RAM 42KB Virtual Machine (runtime & GC) 28KB Virtual Machine 1KB Libraries (graphics, com, float ) 132KB Native Stack 28KB Graphical resources (images) 228KB Application 34KB Application 13KB
Example Washing machine Hardware» STM32F429 @ 180MHz» 32-bit col. WQVGA LCD» Touchscreen Performance» Refresh rate = 50fps» CPU load = 24 %» Boot time < 2ms Application M em ory Requirem ents FLASH 161KB RAM 11KB Java engine & Smart RAM optimizer 28KB Java engine 1KB Firmware (STUI libs, BSP, ) 114KB C Stack 5KB Graphical resources (images, fonts) 7KB Application 12KB Application 5KB
Java Platforms
Java Platforms JPF = Java PlatForm Java is used to code the application C (or any other native language) is used along with MicroEJ libraries, drivers and operating system to construct the platform Decoupling software from hardware
Application Point of View Application sees the JPF as a framework» It offers several libraries» It executes the application Abstraction barrier hiding hardware details» Application is agnostic to hardware specifications» Application uses high-level functions given by the platform APIs» JPF translates high-level functionalities to level-low operations
Abstraction Example Strong coupling with hardware particularity» Application waits for a push button pressed event to start a motor» What if the order is now sent through a serial link? Bad abstraction! Software not aware of hardware details» Application should be waiting for a start motor even» No matter how the order is given, semantic is not changed Good abstraction!
Target Specific A JPF targets» A specific microcontroller architecture since one JVM is made for one microcontroller specific instruction set» A specific board and how peripherals are connected to the microcontroller A JPF also depends on the compiler» Keil s ARMCC» GCC» IAR Embedded Workbench»
Dual platforms : SimJPF & EmbJPF JPF is composed of two platforms» SimJPF : for simulation (on workstation)» EmbJPF : for embedded execution (on microcontroller) Parallel update» You should update both when adding a new feature» Create mock objects to simulate hardware features
Java Platform Content A JPF includes» MicroJvm Java Virtual Machine» Simulator» Java and native libraries» Drivers» Operating system» Native code provided by developers» Mock objects»
Drag Emb Drop TM
Benefits Keep hardware and software design cycles independent Application prototype ahead of hardware development Simplify design, tests, evolutions Reduce development time
Waterfall Mkt. specs HW ready 1 st integration SW ready Release Marketing Human factors Graphics Hardware dev. Only few changes are possible Software dev. HW/SW integration IS2T 2013 time
Agility Mkt. specs HW ready JPF ready Release Marketing Human factors & Graphics Software dev. (continuous integration and iterative deliveries) Simulated Java Platform Hardware dev. Embedded Java Platform HW/JPF test Changes are possible anytime IS2T 2013
Execution
Execution Flows
Launch Configurations Launch Configurations» Eclipse provides the concept for launch configurations» A launch configuration tells what is executed, what is the runtime environment, what are the execution options» Available through the Run menu A Launch Configuration can be executed as» A Run Configuration to simply run an application» A Debug Configuration to debug this application External Tool Configuration to run an external program
Launch Configurations MicroEJ provides new launch configuration types» MicroEJ Application» MicroEJ Tool
MicroEJ Application A MicroEJ Application configuration lets you» Select the kind of execution (SimJPF or EmbJPF)» Configure libraries and memory usage
Execution Flow on SimJPF Simulator is launched on the workstation Java application is executed Simulator uses mock objects to simulate hardware features
SimJPF Simulator engine is a Java SE application» Works on Windows, Linux and OS X Same byte code is executed by both SimJPF and EmbJPF Features» Debugging inside Eclipse / MicroEJ (JDWP)» Heap dumping for analysis» Code coverage» Partial simulation of the EmbJPF characteristics
Execution Flow on EmbJPF General case» Java application is compiled and link with libraries» An object file is generated» This file is linked with drivers and operating system to produce executable files (done by a 3 rd party tool) Kickstart platforms are a special case» They include precompiled driver and OS» They have special linker scripts» MicroEJ create executable files
MicroEJ and C IDE MicroEJ provides» Java application as an object file» Java runtime environment as library files» Header files with types and functions provided by these libraries C IDE provides» Drivers» Operating system» LLAPI implementation C IDE compiles C code, link application and deploy binary file
C IDE Configuration Modify include path» MicroEJ header files must be on the path Modify linker configuration» MicroEJ libraries and Java application object file must be used during link edition Start Java from your C program» sni.h provides functions to initialize and start the JVM
Low Level API Generic programing and implementation details» JVM and libraries integrate everything that is generic» But some functions cannot be generic since they are specific to the hardware target along with BSP» Platform developers must implement these functions in C Several modules come with Low Level APIs (LLAPIs) to implement» Runtime (LLMJVM)» Display (LLDISPLAY)» Input (LLINPUT)» LED (LLLED)» ECOM-COMM (LLCOMM)»
Executable Generation
Interactions with Native World
Interactions with Native World Not everything can be done in Java» Access to hardware peripherals (registers) Not everything should be done in Java» Intense computation, especially with matrices» Useless to translate legacy code to a new language overall application is in fact composed of Java and C need for interactions between Java and native worlds
Interactions with Native World You may need to create your own API to access your specific hardware peripheral» SNI / HIL to call a C function from a Java method You may need to share data between Java and C» Shielded Plug to create a database to exchange data» B-ON s Immortal Objects to share segments of memory Java application should be hardware agnostic» Design high-level APIs» Find the good abstraction level
SNI
SNI Java Side SNI = Simple Native Interface Java offers the native keyword» Declares a method which is not implemented in Java» Must be static (visibility doesn t matter)» Example: public static native void log(int id); SNI connects a Java native method to a C function» Defines a naming convention to create a symbol» Defines the calling convention at runtime
SNI Native Side Implementation» Developers write the corresponding functions» They name these functions after the ESR naming convention» sni.h provides compatible type definitions Link edition» Java object file generated by MicroEJ contains unresolved symbols» 3 rd party IDE links the Java object file with the C functions» All dependencies are revolved during link edition hence no surprise at runtime
Naming Convention package GPIO; public class Main { public static native void toggle(); } public static void main(string[] a) throws InterruptedException { while(true){ toggle(); Thread.sleep(10); } } #include <sni.h> #include gpio.h void Java_GPIO_Main_toggle(){ GPIOE->ODR ^= GPIO_Pin_2 ; }
Flow Immortals Java methods C functions Call C Java heap C heap Return to Java T I M E
Java threads Green Thread Architecture 1x native task (Java) Native tasks (C/ASM) Shielded Plug (SP) Simple Native Interface (SNI) SP SNI RTOS SP SNI GUI hardware LCD, buttons, Applicative hardware Sensors, actuators, IS2T 2013
SNI-GT SNI and SNI-GT Advantages» Easy integration with OS» Can be used without any OS» Clear separation between native and Java Restrictions» Not possible to call Java from C» Java objects cannot be used as parameters or return values» Calling a native method pauses the VM scheduler
Immortals
Immortal Objects B-ON library Immortal objects» Live in a separate heap (immortal heap)» Are not touched by garbage collector» Have fixed addresses so they can be shared with the native world
Immortal Object Creation Generally, objects are created and then turned into immortal objects» int[] array = new int[10]; Immortals.setImmortal(array); Immortals.isImmortal(array); Objects can be created directly in the immortal heap» public static void run(runnable runnable) Impossible to free memory» OutOfMemoryErrors can be thrown
Share with Native World package com.corp.examples; public class Hello { static int[] array = (int[])immortals.setimmortal(new int[50]); public static native int getdata(int[] array); } public static void main(string[] args){ int nb = getdata(array); } #include <sni.h> jint Java_com_corp_examples_Hello_getData(jint* array){ array[0] = 0xBEEF; return 1 ; }
Flow Immortals Java methods C functions Java heap C heap T I M E
Shielded Plug
Shielded Plug Shielded Plug (often shorten as SP )» Database to exchange data» Publish / subscribe model
Shielded Plug Purpose Isolate processes» Well-defined segregation between producers and consumers» Processes run independently with no interactions except data exchanges» Producers and consumers are not necessarily aware of each others Data exchange» Database is made to share data between several software components» It is neither a one-to-one relation nor a C-to-Java relation only» Can share data from Java to C, from Java to Java, from C to C
GUI
Core of the Framework MicroUI is the core the UI framework» ESR002 MicroUI module provides a Java library that gives access to every feature MicroUI relies on stacks» MicroUI module on its own is just a Java library that offers APIs» Additional modules translate these features to simulated or hardware functions
Stacks EmbJPF relies on several stacks SimJPF relies on the Front Panel, a mock object for these stacks
MicroUI vs. MWT MicroUI (Micro User Interface) = Mechanisms for GUI» Hardware abstraction (screens, joysticks, buttons)» Display and event management management» Low level library MWT (Micro Widget Toolkit) = concepts for widgets on top of MicroUI» High level library» Developers will generally code their applications with MWT
Layers
Widgets Widget = Window + Gadget Widgets are graphical components of applications» Interact with user : display data, receive inputs» Should be reusable Renderable Widget
Renderers Widgets are not responsible for their rendering» They carry only graphical data» They contains the logic to interact with the user Model and Controller of MVC pattern Renderers are responsible for rendering widgets graphically View of MVC pattern
Loose Coupling Widget Controller Application & user events Application Data Model Widget Data Model Data related to the application Data related to representation Widget Renderers Widget Renderers Themes
Composite Widget A composite widget is a widget that contains widgets Allow to lay out widgets Create complex hierarchized structures Widget 1 Widget 2 Composite Widget 3
Widget Hierarchy Display Desktop Panel Composite Widget
Examples
Any Questions?