MATLAB Examples

Getting Started with Simulink Coder Support Package for STMicroelectronics Nucleo Boards

This example demonstrates how to use the Simulink Coder Support Package for STMicroelectronics Nucleo Boards to run a Simulink® model on an STMicroelectronics Nucleo board.

Contents

Introduction

Simulink Coder Support Package for STMicroelectronics Nucleo Boards enables you to create and run Simulink models on supported STMicroelectronics Nucleo boards. The support package includes a library of Simulink blocks for configuring and accessing STMicroelectronics Nucleo peripherals and communication interfaces.

In this example you will learn how to configure a simple Simulink model to generate code for STMicroelectronics Nucleo F401RE board and run the generated code on the board to periodically turn an LED on and off. You can configure this model for other supported Nucleo boards by selecting them as the "Hardware board" on the Hardware Implementation pane of the Model Configuration Parameters.

Available versions of this example:

Prerequisites

Required Hardware

To run this example you will need the following hardware:

  • Supported STMicroelectronics Nucleo boards
  • USB type A to Mini-B cable

Task 1 - Configure model for code generation and download

In this task, you will configure a simple model to run on the STMicroelectronics Nucleo board.

1. Open the LED model. This model has been configured for the Nucleo F401RE board. Follow the steps shown in the figure below to configure the model for the appropriate Nucleo board:

2. The user LED is driven by GPIO Pin 13 on the Nucleo F401RE board. The user LED might be driven by a different Pin on different Nucleo boards.

3. Click on "Deploy To Hardware" to automatically download the generated bin file, stmnucleo_gettingstarted.bin, on to the connected Nucleo board.

4. You will see in the Diagnostic Viewer window that code is generated and downloaded on to the connected board for the model.

..
.....
......
### Created: ../stmnucleo_gettingstarted.elf
### Invoking postbuild tool Binary Converter ...
arm-none-eabi-objcopy -O binary ../stmnucleo_gettingstarted.elf ../stmnucleo_gettingstarted.bin
### Done invoking postbuild tool.
### Invoking postbuild tool Hex Converter ...
arm-none-eabi-objcopy -O ihex ../stmnucleo_gettingstarted.elf ../stmnucleo_gettingstarted.hex
### Done invoking postbuild tool.
### Invoking postbuild tool Executable Size ...
arm-none-eabi-size ../stmnucleo_gettingstarted.elf
   text	   data	    bss	    dec	    hex	filename
   4264	    196	   8308	  12768	   31e0	../stmnucleo_gettingstarted.elf
### Done invoking postbuild tool.
### Successfully generated all binary outputs.
### Downloading executable to the hardware on Drive: G:
      1 file(s) copied.
### Successful completion of build procedure for model: stmnucleo_gettingstarted
### Creating HTML report file stmnucleo_gettingstarted_codegen_rpt.html
Build process completed successfully

5. Observe that the LED turns ON for 0.5 second and switches OFF for 0.5 second periodically.

On the Nucleo board the binary file generated can be manually copied to the drive connected to Nucleo board.

Observe that the green LED turns ON for 0.5 second and switches OFF for 0.5 second periodically.

Task 2 - Configure the model just for the build

In this task, you will configure a simple model to build and generate out file for the STMicroelectronics Nucleo board.

1. Open the LED model corresponding to the target hardware from above.

2. The user LED is driven by GPIO Pin 13 on the Nucleo F401RE board.

3. Change the Build action to Build to only generate the hex,bin and elf executable files. Follow the steps below to set the Build action:

4. Generate code for the model by clicking on the Deploy To Hardware button:

5. You will see in the Diagnostic Viewer window that code is generated.

..
.....
......
### Created: ../stmnucleo_gettingstarted.elf
### Invoking postbuild tool Binary Converter ...
arm-none-eabi-objcopy -O binary ../stmnucleo_gettingstarted.elf ../stmnucleo_gettingstarted.bin
### Done invoking postbuild tool.
### Invoking postbuild tool Hex Converter ...
arm-none-eabi-objcopy -O ihex ../stmnucleo_gettingstarted.elf ../stmnucleo_gettingstarted.hex
### Done invoking postbuild tool.
### Invoking postbuild tool Executable Size ...
arm-none-eabi-size ../stmnucleo_gettingstarted.elf
  text	   data	    bss	    dec	    hex	filename
  4264	    196	   8308	  12768	   31e0	../stmnucleo_gettingstarted.elf
### Done invoking postbuild tool.
### Successfully generated all binary outputs.
C:\stmnucleo_gettingstarted_ert_rtw>exit /B 0
### Successful completion of build procedure for model: stmnucleo_gettingstarted

6. You can manually copy the "bin" file generated to the drive letter connected to the hardware.

Task 3 - Review Block Library for your board

The Simulink Coder Support Package for STMicroelectronics Nucleo Boards provides an easy way to create algorithms that use peripherals supported by the hardware. Dedicated blocks are provided in the block library that can be added to your Simulink model. Use these blocks to configure the associated sensors and actuators, read data from a peripheral or send data to a peripheral.

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

2. In the Simulink Library Browser, navigate to Simulink Coder Support Package for STMicroelectronics Nucleo Boards and open the Digital Write block:

Review the block mask, which contains a description of the block and parameters for configuring the associated STMicroelectronics Nucleo digital output pin.

Summary

This example introduced the workflow for running a Simulink model on the STMicroelectronics Nucleo boards. In this example you learned that:

  • You can configure a Simulink model to generate code for the STMicroelectronics Nucleo board.
  • Simulink Support Package for STMicroelectronics Nucleo Boards provides blocks for configuring, reading from and writing to STMicroelectronics Nucleo peripherals.