MATLAB Examples

Getting Started with Tiva TM4C123G LaunchPad

This example shows how to use Embedded Coder Support Package to run a Simulink® model on TIVA Tiva TM4C123G LaunchPad using Energia Toolchain.


Supported Hardware:

TIVA TM4C123G LaunchPad.

Available versions of this example:

Tiva TM4C123G LaunchPad: Tiva123_gettingstarted

The provided model is pre-configured for Tiva TM4C123G LaunchPad and can be run on any of the board listed in the "Supported Hardware" section, by changing the "Target Hardware" parameter in the configuration parameters of the model as described in Task 3 of this example.


Embedded Coder Support Package for Tiva TM4C123G LaunchPad enables you to create and run Simulink models on for Tiva TM4C123G LaunchPad. The target includes a library of Simulink blocks for configuring and accessing sensors, actuators and communication interfaces. Library of Simulink blocks uses source and include files provided by Energia IDE. Additionally, the target enables you to monitor and tune algorithms running on for Tiva TM4C123G LaunchPad from the same Simulink models from which you developed the algorithms.

In this example you will learn how to create and run a simple Simulink model on Tiva TM4C123G LaunchPad. See other examples for Tiva TM4C123G LaunchPad to learn how to use External mode and to learn how to implement more complex algorithms.


If you are new to Simulink, we recommend completing Interactive Simulink Tutorial, reading the Getting Started section of the Simulink documentation and running Simulink Getting Started example.

Required Hardware

To run this example you will need the following hardware:

• Tiva TM4C123G LaunchPad

• USB cable


The following figure shows the example model:


Task 1 - Review Tiva TM4C123G LaunchPad Block Library supported by Energia

Embedded Coder Support Package for Tiva TM4C123G LaunchPad provides an easy way to create algorithms that use sensors and actuators by using the blocks that you can add to your Simulink model. The blocks are used to configure the associated sensors and actuators, as well as to read and write data to them.

1. Enter simulink at the MATLAB® prompt. This opens the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Embedded Coder Support Package for Tiva TM4C123G LaunchPad.

3. Double-click the Digital Output block. Review the block mask, that contains a description of the block and parameters for configuring the associated Tiva TM4C123G LaunchPad digital output pin.

Task 2 - Create a Model for Tiva TM4C123G LaunchPad Hardware

In this task, you will create a simple Simulink model where blocks are supported by Energia third party library that changes the state of the Tiva TM4C123G LaunchPad digital output pin.

1. In MATLAB, select HOME > New > Simulink Model.

2. Drag the Pulse Generator block from the Simulink Sources library to your model.

3. Double-click the Pulse Generator block. Set the Pulse type to parameter to Sample based and set the Sample time parameter to 1 second.

4. Drag the Digital Output block to the model. Use the default block settings.

5. Connect the Pulse Generator block to the Digital Output block.

Task 3 - Configure and Run the Model on Tiva TM4C123G LaunchPad Hardware

In this task, you will configure and run your model on the Tiva TM4C123G LaunchPad.

1. Connect the Tiva TM4C123G LaunchPad to your computer with a USB cable.

2. Open the Configuration Parameters in the model. Click the Code Generation and select ert.tlc as the System target file under Target selection. Set the Hardware implementation->Hardware board parameter to “Tiva TM4C123G LaunchPad” which is connected to your computer. You will observe Energia Tiva selected as a Toolchain Code Generation pane. Do not change any other settings.

3. Click Apply and OK.

4. In your Simulink model, click the Deploy to Hardware button on the toolbar. The model will now be deployed to the connected Tiva TM4C123G LaunchPad hardware.

5. Look at the on board LED attached to digital pin 39. The LED blinks once for every second.

6. You can change the pin number as 30 for Red LED and 40 for Blue LED,

7. Save your model.

A pre-configured model "TIVA123_gettingstarted" is included for your convenience.

Other Things to Try

Experiment with other blocks in the Tiva TM4C123G LaunchPad block library. For example:

• Create and run a model that turns the LED on if a signal is applied to a digital input pin.

• Create and run a model that repeatedly brightens and dims an LED. Hint: use the PWM block.


This example introduced the workflow for creating an algorithm from a Simulink model and then running it on the Tiva TM4C123G LaunchPad. In this example you learned that:

• Embedded Coder Support Package for Tiva TM4C123G LaunchPad provides blocks for configuring, reading from and writing to sensors and actuators.

• You can use the Deploy To Hardware button to configure and run the model on Tiva TM4C123G LaunchPad.