Documentation

Getting Started with Embedded Coder Support Package for BeagleBone Black Hardware

This example shows you how to use Embedded Coder Support Package for BeagleBone Black Hardware to run a Simulink® models on BeagleBone Black hardware.

Introduction

Embedded Coder Support Package for BeagleBone Black Hardware enables you to create and run Simulink models on BeagleBone Black hardware. The support package includes a library of Simulink blocks for configuring and accessing BeagleBone Black peripherals and communication interfaces.

In this example you will learn how to configure a simple Simulink model to generate code for BeagleBone Black hardware and run the generated code on the board to periodically turn and LED on and off.

Prerequisites

If you are new to Simulink, we recommend completing the Interactive Simulink Tutorial. If you are new to Embedded Coder, visit the Embedded Coder product page for an overview and tutorials.

Required Hardware

To run this example you need the following hardware:

  • BeagleBone Black board

  • USB type A to Mini-B cable

Task 1 - Review BeagleBone Black Block Library

Embedded Coder Support Package for BeagleBone Black Hardware provides an easy way to create algorithms that use BeagleBone Black peripherals by using blocks that can be added 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 Libraries > Embedded Coder Support Package for BeagleBone Black Hardware. Right-click on the LED block and choose Add block to a new model. You will see a new Simulink model with an LED block.

3. Double-click the LED block. Review the block mask, which contains a description of the block and parameters for configuring the associated user LED. Click on View LED location button to see a diagram of user LEDs on BeagleBone Black hardware.

Task 2 - Configure model for code generation

In this task, you will configure a simple model blinking an on-board LED to run on BeagleBone Black hardware.

1. Open the unconfigured Getting Started with BeagleBone Black Support Package model. In order to configure the model for BeagleBone Black hardware follow the steps shown in the figure below:

For convenience, a configured Getting Started with BeagleBone Black Support Package model is also available.

2. Verify the connectivity parameters for your BeagleBone Black hardware by following the steps below:

If you connected your BeagleBone Black hardware to your host computer via a USB cable, the IP address of your board should be 192.168.7.2. The username and the password shown on the screen shot above shows the default username and password for the BeagleBone Black Debian Linux distribution.

3. Generate code for the model by clicking on the Build Model button:

4. The generated code is compiled and linked on the host computer, downloaded to the BeagleBone Black hardware and run automatically. When the model starts running on the BeagleBone Black hardware, observe that one of the blue LED's on the board blinks with a period of 1 second.

Task 3 - Stop Simulink model running on BeagleBone Black hardware

Embedded Coder Support Package for BeagleBone Black Hardware generates a Linux executable for each Simulink model you run on the BeagleBone Black hardware. The generated executable is an ELF file that has the same name as the Simulink model and is stored in your home directory on the BeagleBone Black hardware.

1. To run/stop a Simulink model, you use the runModel and stopModel methods of the beaglebone_black communication object. First, create a communication object to the BeagleBone Black hardware:

bbone = beaglebone_black;

This command generates a BeagleBone Black object that is your gateway to communicating with your BeagleBone Black hardware from MATLAB command line. Execute the following on the MATLAB command line to see if the beaglebone_gettingstarted_unconfigured model is running:

isModelRunning(bbone, 'beaglebone_gettingstarted_unconfigured')

The isModelRunning method of beaglebone_black returns true if the model is running on the BeagleBone Black hardware.

2. Execute the following on the MATLAB command line to stop the Simulink model you ran in Task 2:

stopModel(bbone, 'beaglebone_gettingstarted_unconfigured')

You should see USR0 LED stop blinking at this point. You can also use the isModelRunning method to test if the model has stopped.

3. To run a previously built Simulink model on your board, you use runModel method. In order to run the beaglebone_gettingstarted_unconfigured model, execute the following on the MATLAB command line:

runModel(bbone, 'beaglebone_gettingstarted_unconfigured')

4. The output of the executable running on the BeagleBone Black hardware is re-directed to a log file. To see the contents of the log file for the executable corresponding to the beaglebone_gettingstarted_unconfigured model, execute the following on the MATLAB command line:

system(bbone, ['cat beaglebone_gettingstarted_unconfigured.log'])

In case of unexpected results when running an Simulink model on hardware, examine the contents of the log file for diagnostic messages.

Summary

This example introduced the workflow for configuring and running a Simulink model on the BeagleBone Black Hardware.

Was this topic helpful?