Main Content

Getting Started with Simulink Coder Support Package for NXP FRDM-KL25Z Board

This example shows you how to use Simulink® Coder™ Support Package for NXP FRDM-KL25Z Board to run a Simulink model on a NXP FRDM-KL25Z board.

Introduction

Simulink Coder Support Package for NXP FRDM-KL25Z Board enables you to create and run Simulink models on a NXP FRDM-KL25Z board. The support package includes a library of Simulink blocks for configuring and accessing NXP FRDM-KL25Z peripherals and communication interfaces.

In this example, you learn how to configure a Simulink model to generate code for NXP FRDM-KL25Z board and run the generated code on the board. This model sets the color of the onboard RGB LED to red.

Prerequisites

Required Hardware

To run this example, youneed this hardware:

  • NXP FRDM-KL25Z board

  • USB type A to Mini-B cable

Open Model

Open example model freedomboard_RGB_LED.

Task 1 - Connect an FRDM-KL25Z Board to Development Machine

Connect a FRDM-KL25Z board to your development machine.

1. Plug in a Mini USB cable from a USB port on the development machine to the OpenSDA mini-B USB connector on the FRDM-KL25Z board.

2. The FRDM-KL25Z board comes with the mass-storage device (MSD) Flash Programmer OpenSDA Application preinstalled.

On Windows®, the board appears as a removable storage drive with a volume label of FRDM-KL25Z.

On Mac, the board appears as a removable storage drive with a volume label of FRDM-KL25Z.

Task 2 - Review NXP FRDM-KL25Z Support Package Block Library

1. Start Simulink and open the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Simulink Coder Support Package for NXP FRDM-KL25Z Board > FRDM-KL25Z.

3. Double-click the RGB LED block. Review the block mask, which contains a description of the block and block inputs associated with the RGB LED.

Open Model

Open the FRDM-KL25Z block library.

Task 3 - Create a Model for NXP FRDM-KL25Z Board

Create a Simulink model that sets the color of the RGB LED to red.

1. In MATLAB, select HOME > New > Simulink Model. Under Simulink, select Blank Model > Create Model.

2. Add a Constant block to your the model. Set the value of the Constant block to 255.

3. From the FRDM-KL25Z library, add an RGB LED block to the model.

4. Connect the Constant block to the R input of the RGB LED block.

5. Make a copy of the Constant block and set the value to 0.

6. Connect the second Constant block to the G input of the RGB LED block.

7. Make another copy of the Constant block and set the value to 0.

8. Connect the third Constant block to the B input of RGB LED block.

Task 4 - Configure and Run the Model on NXP FRDM-KL25Z Board

Configure and run your model on the NXP FRDM-KL25Z board.

1. Connect the NXP FRDM-KL25Z board to your development computer with a USB cable.

2. In your Simulink model, click Configuration Parameters.

3. In the Configuration Parameters dialog box:

  • On the Hardware Implementation pane, set the Hardware board parameter to NXP FRDM-KL25Z.

  • On the Target Hardware Resources pane, set the Build action parameter to Build, load and run. This % parameter setting downloads the generated binary file onto the connected NXP FRDM-KL25Z board.

4. On the Solver pane, set the Solver parameter to discrete (no continuous states).

5. Click OK.

6. Deploy the model to the NXP FRDM-KL25Z board. In the toolstrip, click Build Model.

7. Observe that the color of the RGB LED is set to red.

8. Save your model.

Other Things to Try with RGB LED Block

  • Create and run a model that turns the RGB LED to a different color.

  • Create and run a model that toggles the RGB LED to red, green, and blue.