STM32JAVA
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 manufacturerMicroEJ
●
MicroEJ SDK lets you use Java for embedded system
development
●
Goals of this presentation
» Discover MicroEJAgenda
●
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
Software Complexity
●
32-bits MCU with important memory
Java
●
Modern object-oriented language
» Loose coupling
» Managing complexity
●
Portability
●
Memory management
» Garbage collector
» Ideal for event driven systems
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; /**
* Shows three views (bar, pie, text) that represents the same data model (a percentage value). * It is possible to resize the
JVM RTOS Libs JVM RTOS Libs JVM RTOS Libs Java language
Java Virtual Machines
(JVM - software processors)
Microprocessors
Java technology
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
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
Supported architectures
●
Available
» ARM Cortex-M » Cortex-A » Linux » Android » iOSOptimized JVMs for Embedded Systems
• Code quality • Productivity • Reliability • Portability • Scalability • Maintainability • Code density• High speed execution • Tiny footprint • Interface C/asm • Low power, Java Java Optimized implementation 32/64-bit
Java Runtime
●
Compiler version
» Java 7
●
Runtime library
» EDC (Embedded Device Configuration)
» Close to Java ME
MicroEJ Libraries
●
Available libraries
» EDC » B-ON » MicroUI » MWT » NLS » ECOM-COMM » Shielded Plug » SNI » ….●
Specifications by ESR Consortium
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
Applica t ion M e m or y Re quir e m e nt s
Flash 422KB RAM 42KB
Virtual Machine (runtime & GC) 28KB Virtual Machine 1KB Libraries (graphics, com, float…) 132KB Native Stack 28KB Graphical resources (images) 228KB
Example – Washing machine
● Hardware
» STM32F429 @ 180MHz » 32-bit col. WQVGA LCD » Touchscreen
● Performance
» Refresh rate = 50fps » CPU load = 24 % » Boot time < 2ms
Applica t ion M e m or y Re quir e m e nt s
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
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
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
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
Benefits
●
Keep hardware and software design cycles independent
●
Application prototype ahead of hardware development
●
Simplify design, tests, evolutions
Waterfall
Marketing Human factors Graphics Hardware dev. Software dev. HW/SW integrationMkt. specs HW ready 1st integration SW ready Release
time
Only few changes are possible © IS2T 2013
Agility
Marketing
Human factors & Graphics
Hardware dev.
Software dev. (continuous integration and iterative deliveries)
HW/JPF test
Mkt. specs HW ready JPF ready Release
Changes are possible anytime
Embedded Java Platform
© IS2T 2013
Simulated Java Platform
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
Launch Configurations
●
MicroEJ provides new launch configuration types
» MicroEJ Application
MicroEJ Application
●
A MicroEJ Application configuration lets you
» Select the kind of execution (SimJPF or EmbJPF)Execution Flow on SimJPF
●
Simulator is launched on the workstation
●
Java application is executed
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
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 3rd party tool)
●
Kickstart platforms are a special case
» They include precompiled driver and OS» They have special linker scripts
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 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
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) » …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
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
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
» 3rd 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
T I M E Immortals Java heap heapC Java methods C functions Call C Return to JavaGreen Thread Architecture
RTOS Native tasks (C/ASM) 1x native task (Java) GUI hardwareLCD, buttons, … Applicative hardwareSensors, actuators, …
Java threads
Shielded Plug (SP)
Simple Native Interface (SNI) SP SNI SP SNI © 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
Immortal Objects
●
B-ON library
●
Immortal objects
» Live in a separate heap (immortal heap)
» Are not touched by garbage collector
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
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
T I M E Immortals Java methods C functions Java heap heapCShielded Plug
●
Shielded Plug (often shorten as “SP”)
» Database to exchange dataShielded 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
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
Widgets
●
Widget = Window + Gadget
●
Widgets are graphical components of applications
» Interact with user : display data, receive inputs
» Should be reusable
Renderable
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
Loose Coupling
Application & user events Themes Data related to representation Data related to the application Application
Data Model Data ModelWidget
Widget Controller
Widget RenderersWidget