Getting Started with Simulink Coder Support Package for NXP FRDM-K64F Board
This example shows you how to use Simulink® Coder™ Support Package for NXP FRDM-K64F Board to run Simulink model on a FRDM-K64F board.
Introduction
Simulink Coder Support Package for NXP FRDM-K64F Board enables you to create and run Simulink models on a NXP FRDM-K64F board. The support package includes a library of Simulink blocks for configuring and accessing NXP FRDM-K64F peripherals and communication interfaces.
In this example, you will learn how to configure a simple Simulink model to generate code for NXP FRDM-K64F board and run the generated code on the board. This model will set the on-board RGB LED to a red color.
Prerequisites
If you are new to Simulink, we recommend completing the Interactive Simulink Tutorial.
If you are new to Simulink Coder, visit the Simulink Coder product page for an overview and tutorials.
If you would like to update your FRDM-K64F board with Segger J-Link firmware, follow the steps described in the section Install Segger J-Link Firmware on FRDM-K64F Board.
If you would like to update your FRDM-K64F board with mbed CMSIS-DAP firmware, follow the steps described in the section Install mbed CMSIS-DAP Firmware on FRDM-K64F Board.
Required Hardware
To run this example, you will need the following hardware:
NXP FRDM-K64F board
USB type A to Micro-B cable
open_system('freedomk64f_RGB_LED');
Task 1 - Connect an FRDM-K64F Board to Host Machine
In this task, you will connect FRDM-K64F board to host machine.
1. Plug in a Micro USB cable from a USB port on the host machine to the OpenSDA micro-B USB connector on the FRDM-K64F board.
2. mbed CMSIS-DAP Firmware: If your FRDM-K64F board is loaded with mbed OpenSDA v2 firmware, then it will appear as a removable storage drive with a volume label of MBED on Windows®.
On Mac, It will appear as a removable storage drive with a volume label of MBED.
Segger J-Link Firmware : If your FRDM-K64F board is loaded with Segger's J-Link OpenSDA v2 firmware, then it will appear as a removable storage drive with a volume label of JLINK on Windows.
On Mac, It will appear as a removable storage drive with a volume label of JLINK.
Task 2 - Review NXP FRDM-K64F Support Package Block Library
1. Enter slLibraryBrowser at the MATLAB® prompt.
2. In the Simulink Library Browser, navigate to Simulink Coder Support Package for NXP FRDM-K64F Board.
3. Double-click the Digital Write block. Review the block mask, which contains a description of the block and block inputs associated with Digital Write block.
open_system('frdmk64flib');
Task 3 - Create and Run a Model on NXP FRDM-K64F Board
In this task, you will create a simple Simulink model that sets the color of the RGB LED to red.
1. In MATLAB, select HOME > New > Simulink Model. This opens the Simulink Start Page. In the Simulink Start Page, expand the Simulink and select the Blank Model Template. Now click on the Create Model button.
2. Drag the Constant block from the Simulink Sources library to your model. Set the value of Constant block to 1.
3. Drag the Digital Write block from FRDM-K64F library to the model.
4. Double click the Digital Write block and select RED_LED from the Pin drop-down list.
5. Connect the Constant block to the input of Digital Write block.
6. Connect the NXP FRDM-K64F Board to your computer with a USB cable.
7. In your Simulink model, click on the Configuration Parameters button.
8. When the Configuration Parameters page opens up, navigate to Hardware Implementation pane.
Set the Hardware board parameter to NXP FRDM-K64F.
On the Target Hardware Resources pane, Set the Build action to Build, load and run to automatically download the generated binary file on to the connected NXP FRDM-K64F board.
9. Click OK.
10. In your Simulink model, click the Build Model button on the toolbar. The model will now be deployed to the NXP FRDM-K64F Board.
11. Observe that the RGB LED is set with RED color.
12. Save your model.
A pre-configured model
is included for your convenience.
Other Things to Try with Digital Write Block
For example:
Create and run a model that turns the RGB LED to different colors.
Create and run a model that toggles the RGB LED to R, G, and B colors.