Introducing Energia MT for MSP432

What is Energia MT?

Aside from bug fixes, the release of Energia 15 with Multitasking (MT) adds support for the new ARM Cortex M4F-based MSP432 LaunchPad. This time it’s a bit different though. The framework is powered by TI-RTOS, letting you run your Sketches in parallel. Yes, in parallel! How awesome is that?! This release supports MT for the MSP432 LaunchPad with support for other boards coming in future releases.  Download Energia 15 with MT now!


How it Works

Each tab in Energia MT is its own task, which will have a setup() and a loop() component.  The setup() and loop() pair need to have matching names, but the specific names don’t matter.  For example, to blink 3 LEDs at different rates, we would set up the Energia project like this: setupBlink1()/loopBlink1(), setupBlink2()/loopBlink2() and setupBlink3()/loopBlink3().




As long as the setup/loop pairs match, the naming in the tabs doesn’t matter.  Energia MT will automatically find the setup/loop pairs and turn them into individual tasks.  Setting up a multitask application is as simple as that!

Energia MT also allows for global variable for inter-task communication.  All global variables are truly global and must be declared in the first tab. Once they are declared in the first tab, they can be called from any other tab/task, but you cannot reuse the variable name in another task.


Examples in Energia MT

MultiBlink: Multiple Sketches each blinking one of the RGB LEDs at a different rate.
ButtonEvent: An example for the Button event library. One Sketch is reading the button and another sketch waiting for the button to be pressed. This library uses the TI-RTOS events module.
EventLibrary: An example for using the Event library. This library enables you to send an event from one task to the other. One Sketch sends events while the other Sketch waits for an event to happen and sleeps otherwise.
Monitor: This is an awesome utility Sketch that displays CPU utilization, task memory usage, etc. There are a couple of VT100 features in this sketch so best would be to use a VT100 terminal rather than the build in Serial monitor. For example, to continuously display the CPU load, type stats <space> <enter> and the CPU load will be updated in the terminal continuously.
MultiTaskSerial: Shows 2 threads sending a string to the Serial monitor at different rates.

You can find these examples in Energia MT under File->Examples->MultiTasking

Additional Benefits

Even when you are writing a single-threaded sketch for the MSP432, Energia will still compile it into the TI-RTOS.  While this will result in a larger code-size, it also brings the power and computational benefits of an RTOS.  For example, if you use a delay(500) at the end of your loop instead of ticking for 500 milliseconds, TI-RTOS will set an interrupt and go into deep sleep until the 500 milliseconds is up.


See Also

Examples and tutorials

Multitasking Tutorial