ARM's Articles

The Choices for Programming ARM® Cortex®-M Microcontrollers

h2. ARM Architecture and Development Tools

An increasing number of vendors offer 32-bit microcontrollers based on ARM® Cortex®-M processors, and at the same time, there are also new development environments introduced for these microcontroller products. Some programming languages and tools, previously available only for programming for desktop computers, are being ported to ARM microcontrollers too.

Technical advantages of the ARM Cortex-M architecture such as high performance, high code density, OS support and memory system flexibility also enable these software development methods to be used on ARM devices. To use these methods with legacy 16-bit or 8-bit devices could be very inefficient or even impossible.

The open nature of the ARM architecture allows software tool vendors to develop tools for a wide range of microcontrollers from different vendors, whereas tools developed for 8-bit and 16-bit processors’ architectures typically have a limited market reach.

Wider adoption also allows programming tools vendors to create application development environments for particular embedded segments, such as M2M (machine to machine) and IoT (Internet of things) and alternate programming languages. In this article we will cover some of these development environments such as Java and Simulink.

Java Technology

Java technology speeds up development and prototyping. Although there are multiple Java development environments available, this article will look at two.

Oracle® Java on ARM architecture targets IoT and M2M applications.

Programming using Java ME (Micro Edition) software development kit (SDK) is identical to the Java SE (Standard Edition) Embedded (e.g. Eclipse/Netbeans IDE), except, currently, the compiled object is optimized for embedded systems with small memory foot print and the GUI library or JavaFX are not available on Java ME.

For example, a microcontroller running the Java ME Embedded and Java applications can be stored on a SD card, or on chip. When the system is started, the Java ME Embedded can read a configuration file and identify the Java application to load and execute.

Figure:1 Design flow using Java ME Embedded

Figure 1  Design flow using Java ME Embedded

Typically 256KB of RAM and 1 to 1.5MB of program ROM are required to host the application and the JVM. Please note that applications running inside the JVM cannot guarantee real time behavior. However, the JVM can run as one of the application threads inside a system running RTOS, in parallel to other real time tasks and communicate with each other using an event communication mechanism.

Figure:1 Software architecture combining Java with real time applications

Figure 2  Software architecture combining Java with real time applications

Source level debugging is available in desktop and simulated environments and on hardware. The Java execution environment contains an optional debug agent (running on target hardware), which can communicate with the debugger via a built-in device manager (running on the debug host) via UART, TCP/IP or USB.

Java is highly portable: the codes can be used from microcontroller systems, to internet gateway, home server, or large database servers. Java ME and Java SE make it possible to develop applications that work across different embedded platforms.

For IoT and M2M applications, Java ME also provides TCP/IP communication APIs that allow Java applications to open TCP/IP sockets, communicate with other devices and add third party communication stacks, like Bluetooth. Optional APIs for server/client communications allow small microcontroller systems to talk to Oracle database servers seamlessly.

Java’s sandbox environment can improve security, but can be inconvenient for control tasks. Java ME has peripheral APIs to make this easier, but unlike traditional C programming, these APIs are fairly high level and might not able to support many device-specific features. Some I/O control tasks can be separated and run as application threads alongside the JVM in an RTOS environment.

There are many Cortex-M microcontrollers with only several hundred KB of flash and RAM. If you would like to use Java with these devices, IS2T’s MicroEJ®is most suitable. The development flow for MicroEJ is optimized for small microcontrollers that it optimizes, pre-processes and links the Java object off board, before loading to the microcontroller, instead of loading the code object directly to the VM.

Figure:1 Design flow using IS2T MicroEJ, which is available as part of the STM32Java SDK from STMicroelectronics

Figure 3  Design flow using IS2T MicroEJ, which is available as part of the STM32Java SDK from STMicroelectronics

MicroJvm can be booted up in 2ms running at 120MHz on ARM Cortex-M3/M4 processor-based microcontrollers and requires minimum of 28KB of flash memory and 1KB of SRAM (not including application code). Even with a GUI human machine interface (HMI) library, it only needs 90 to 140KB of flash in total.

The MicroEJ SDK contains choices of Java Platform (JPF), including the root components such as MicroJvm® and standard libraries ( B-ON + CLDC – core embedded Java API), and optional packages like MicroUI™ (embedded user interface), MWT (Micro Widget Toolkit, an embedded widgets framework), NLS (embedded national support), runtime PNG image decoder, and graphical tools. These features allow developers to create GUI quickly, and the object-oriented nature of Java and its automatic memory management make it excellent platform for handling dynamic GUI components.

Figure:1 Components in Java platform (JPF)

Figure 4  Components in Java platform (JPF)

Java applications can access device driver library functions through SNI (simple native interface, ESR012) or Shield Plug.

Figure:1 Software architecture in mixed Java and native code applications

Figure 5  Software architecture in mixed Java and native code applications

The MicroJvm can run as a single task within a third party OS, or run on its own because it contains its own task scheduler, called green thread.

MicroEJ provides an Eclipse-based IDE for creating Java applications on desktop, and a simulator called SimJPF which has a hardware-in-the-loop feature that allows simulations to run with true I/O. It also includes a Front Panel Designer tool to design a virtual device.

Figure:1 Transfer of software development environment

Figure 6  Transfer of software development environment

Scientific and Mathematic Applications

In Feb 2013 it was announced that programs created in MATLAB® and Simulink® from Mathworks® will be supported on ARM Cortex-M processor-based microcontrollers. The Embedded Coder feature generates C code from MATLAB or Simulink designs and utilizes the optimized CMSIS-DSP library for best performance.

Figure:1 Microcontroller software development using Simulink with traditional tools

Figure 7  Microcontroller software development using Simulink with traditional tools

Model-based software development tools like Simulink can reduces design time. For example, a motor control system model can be created in, and tested using simulation inside Simulink. After the model is tested, the Embedded Coder can generate C code and you can test the design in hardware using processor-in-the-loop (PIL) configuration, and then finally complete the design by adding required peripheral control code. Since the control algorithm code is generated automatically, avoiding human errors in code porting.

Figure:1 Running a control application in Simulink with PIL

Figure 8  Running a control application in Simulink with PIL


National Instruments’ LabVIEW® is also a graphical programming environment which can handle model based design. Unlike most other tools, the designs are completely implemented in diagrams.

LabVIEW has a library of functions for DSP (e.g. filter and spectral analysis) , mathematic, array/matrix processing and these allow application software to be developed without an in-depth knowledge of programming or algorithms. For complex applications, software can be partitioned into Virtual Instruments (VIs) and subVIs. Figure 9 shows a LabVIEW subVI (right) which finds the largest variables from four input variables.

Figure:1 Hierarchical software design in LabVIEW

Figure 9  Hierarchical software design in LabVIEW

The LabVIEW C Code Generator takes graphical code and generates procedural C code which can be used in traditional programming environments (Keil® MDK-ARM, IAR Embedded Workbench). During development, the code can be tested by running it inside the LabVIEW environment on a PC.

Figure:1 Typical development flow for using LabVIEW C code generator

Figure 10  Typical development flow for using LabVIEW C code generator

Education and Hobbyists

A number of development platforms are available for education and hobbyists. For example, the Arduino™ IDE and boards are designed for students and hobbyists to learn embedded programming. The Arduino platform supports various architectures: for example, the Arduino Due is based on Atmel ARM Cortex-M3 processor-based SAM3X8E, and Arduino Uno is based on Atmel’s AVR ATmega328 microcontroller.

Figure:1 Arduino Due

Figure 11  Arduino Due

The Java-based IDE can be use with Windows, Linux and Mac OS. It has a large software library for peripheral control functions which simplify peripheral programming. And most of the APIs are hardware platform-independent so that the same program can be used on different Arduino boards.

An Arduino program contains “void setup()”, executed at the beginning of the program and “void loop()”, executed repeatedly after set up. Users program by inserting code into these two functions. During compilation, the IDE adds a software framework and the underlying code for the peripheral APIs.

The open source nature of Arduino allows developers to export the project to other development suites for further optimization.

Another similar platform is the mbed™, which is also for education, hobbyists and rapid prototyping. Its SDK contains rich set of peripheral APIs to create feature-rich applications. Currently, the mbed boards feature ARM Cortex-M3 (NXP LPC1768), Cortex-M0 (NXP LPC11U24) and Cortex-M0+ (Freescale™ KL25Z) microcontrollers. Its 40-pin DIP form factor is designed for easy connection to other development boards.

Figure:1 An mbed board with NXP LPC1768 microcontroller

Figure 12  An mbed board with NXP LPC1768 microcontroller

Uniquely, it is web-based and accessed via a web browser and can be used with Windows, Linux and Mac OS, without having to install software. Once a design is developed and compiled, the binary image can be downloaded to a PC.

Figure:1 Design flow with mbed platform

Figure 13  Design flow with mbed platform

From mbed SDK 2.0, the platform is open source and projects can be exported to traditional development suites directly. For designs with multiple application tasks, there is built-in RTOS support, using CMSIS-RTOS APIs.

Control and FSM Designs

In many embedded applications, especially control, system operations can be viewed as a finite state machine (FSM) and specialized development tools are available to make such designs easier.

One example is IAR VisualSTATE® which creates FSM designs from a graphic design environment. Available state can be defined, as well as the events that can cause state transitions and the corresponding operations.

The design environment is based on state diagrams and UML (Unified Modeling Language). Figure 14, shows a simple design.

Figure:1 A simple radio control state machine design in VisualSTATE

Figure 14  A simple radio control state machine design in VisualSTATE

VisualState has a formal verification tools for detecting errors like deadlocks, unreachable state, conflicting transitions or ambiguous behavior. The transition sequence that triggers these errors can be annotated for debugging, which is via the C Spy debugger with hardware target system. After the state machine is designed, VisualSTATE generates C/C++ codes which can be integrated into projects in IAR Embedded Workbench for ARM (EWARM).
Some other model based design tools previously target PC software design now also support ARM microcontroller code generation. For example, Verum® provides a development suite called ASD: Suite® (Analytical Software Design: Suite) that enables software system verification before coding and system level testing.

Figure:1 ASD:Suite IDE allows designers to define behavior

Figure 15  ASD:Suite IDE allows designers to define behavior

Once the models are verified, C, C++, C# or Java, code can be generated and is guaranteed to be equivalent to the defined model. Automatic code generation avoids human coding errors, thus reduce verification time.


The technical advantages and increasing popularity of the ARM Cortex-M processor-based microcontrollers enabled software tool providers to develop wider range of software development environment. The increasing user base also makes it feasible to have development suite for particular application space. In addition to the development suites mentioned in various section of this article, you can also program Cortex-M microcontrollers with ADA, eLua, Pascal, Basic, Python and Forth, and potentially new development languages.

As a result, embedded software developers are not limited to traditional software development method. And this also opens new opportunities for software tool vendors.
Some programming methods are targeted at specific users or applications, such as education or IoT. Their specific features enable faster time to market and better product quality.

Comments on this post:

There are currently no comments.

Login or Register to post comments.