• No results found

STM32JAVA. Embedded Java Solutions for STM32

N/A
N/A
Protected

Academic year: 2021

Share "STM32JAVA. Embedded Java Solutions for STM32"

Copied!
72
0
0

Loading.... (view fulltext now)

Full text

(1)

STM32JAVA

(2)

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

(3)
(4)

MicroEJ

MicroEJ SDK lets you use Java for embedded system

development

Goals of this presentation

» Discover MicroEJ

(5)

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

(6)
(7)

Software Complexity

32-bits MCU with important memory

(8)

Java

Modern object-oriented language

» Loose coupling

» Managing complexity

Portability

Memory management

» Garbage collector

» Ideal for event driven systems

(9)

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

(10)

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

(11)
(12)

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

(13)
(14)

Supported architectures

Available

» ARM Cortex-M » Cortex-A » Linux » Android » iOS

(15)

Optimized 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

(16)

Java Runtime

Compiler version

» Java 7

Runtime library

» EDC (Embedded Device Configuration)

» Close to Java ME

(17)

MicroEJ Libraries

Available libraries

» EDC » B-ON » MicroUI » MWT » NLS » ECOM-COMM » Shielded Plug » SNI » ….

Specifications by ESR Consortium

(18)

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

(19)

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

(20)
(21)

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

(22)

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

(23)

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!

(24)

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

(25)

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

(26)

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

(27)
(28)

Benefits

Keep hardware and software design cycles independent

Application prototype ahead of hardware development

Simplify design, tests, evolutions

(29)

Waterfall

Marketing Human factors Graphics Hardware dev. Software dev. HW/SW integration

Mkt. specs HW ready 1st integration SW ready Release

 

time

Only few changes are possible © IS2T 2013

(30)

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

(31)
(32)
(33)

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

(34)

Launch Configurations

MicroEJ provides new launch configuration types

» MicroEJ Application

(35)

MicroEJ Application

A MicroEJ Application configuration lets you

» Select the kind of execution (SimJPF or EmbJPF)

(36)

Execution Flow on SimJPF

Simulator is launched on the workstation

Java application is executed

(37)

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

(38)

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

(39)

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

(40)

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

(41)

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) » …

(42)
(43)

Interactions with

Native World

(44)

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

(45)

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

(46)
(47)

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

(48)

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

(49)

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 ; }

(50)

Flow

T I M E Immortals Java heap heapC Java methods C functions Call C Return to Java

(51)

Green Thread Architecture

RTOS Native tasks (C/ASM) 1x native task (Java) GUI hardware

LCD, buttons, … Applicative hardwareSensors, actuators, …

Java threads

Shielded Plug (SP)

Simple Native Interface (SNI) SP SNI SP SNI © IS2T 2013

(52)

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

(53)
(54)

Immortal Objects

B-ON library

Immortal objects

» Live in a separate heap (immortal heap)

» Are not touched by garbage collector

(55)

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

(56)

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 ;

(57)

Flow

T I M E Immortals Java methods C functions Java heap heapC

(58)
(59)

Shielded Plug

Shielded Plug (often shorten as “SP”)

» Database to exchange data

(60)

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

(61)
(62)

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

(63)

Stacks

EmbJPF relies on several stacks

SimJPF relies on the Front Panel, a mock object for these

stacks

(64)

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

(65)
(66)

Widgets

Widget = Window + Gadget

Widgets are graphical components of applications

» Interact with user : display data, receive inputs

» Should be reusable

Renderable

(67)

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

(68)

Loose Coupling

Application & user events Themes Data related to representation Data related to the application Application

Data Model Data ModelWidget

Widget Controller

Widget RenderersWidget

(69)

Composite Widget

A composite widget is a widget that contains widgets

Allow to lay out widgets

Create complex hierarchized structures

W idget 1

W idget 2

W idget 3

(70)

Widget Hierarchy

Display Desktop Panel Composite Widget

(71)
(72)

References

Related documents

Given the restricted use of e-signatures to include internal use only and the requirement that all users must be authenticated to the Authority domain for an e-signature to be

Service Oriented Architecture, Java 2 Enterprise Edition, Object Relational Mapper, Data Access Object, Data Transfer Object, Java Naming and Directory Interface, Structured

Java Enterprise Edition, Sun Java System Application Server, Java Servlet API, JavaServer Pages, JavaServer Faces, Enterprise Java Beans, Java Persistence API, Java Web

On the second course use the other AB Dublin half (1/2) length piece with the split side facing out and toward the next section of the wall panel.. Step 5:

1) Open any document in Microsoft Word. On installation, Zetadocs creates shortcut buttons within Microsoft Office applications to make it simpler to use. If you are using Office

J2SE: Java 2 standard edition J2EE: Java 2 enterprise edition J2ME: Java 2 micro edition... Definition of J2SE, J2EE

The Cisco MDS 9506 multilayer director provides an open platform that delivers the intelligence and advanced features required to make multilayer intelligent SANs a reality,

Activities: Foreign counterintelligence Policies: To avoid comment or advice regarding government policy, not to use clandestine means to gather information, to avoid