Documentation

Getting Started with Embedded Coder Support Package for STMicroelectronics Discovery Boards

This example demonstrates how to use the Embedded Coder Support Package for STMicroelectronics Discovery Boards to run a Simulink® model on an STMicroelectronics STM32F4-Discovery board or STM32F746G-Discovery board or STM32F769I-Discovery board.

Introduction

Embedded Coder Support Package for STMicroelectronics Discovery Boards enables you to create and run Simulink models on STMicroelectronics STM32F4-Discovery development kit , STM32F746G-Discovery board and STM32F769I-Discovery board. The support package includes a library of Simulink blocks for configuring and accessing STMicroelectronics STM32F4-Discovery, STM32F746G-Discovery and STM32F769I-Discovery peripherals and communication interfaces.

In this example you will learn how to configure a simple Simulink model to generate code for STMicroelectronics STM32F4-Discovery board or STM32F746G-Discovery board and run the generated code on the board to periodically turn an LED on and off.

Available versions of this example:

Prerequisites

Required Hardware

To run this example you will need the following hardware:

  • STMicroelectronics STM32F4-Discovery board or STM32F746G-Discovery board

  • USB type A to Mini-B cable

Task 1 - Configure the model for automatic load and run of the generated code on STM32F4-Discovery Board

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

1. Open the LED model. This model has been configured for the STM32F4-Discovery board. Follow the steps shown in the figure below to configure the model for the appropriate STM32 Discovery board :

2. You can either choose 'Baremetal' or 'CMSIS-RTOS RTX' as the operating system for the LED model to run on the STMicroelectronics STM32F4-Discovery board. Both selections will provide similar behaviors but will use different scheduling techniques. Prefer 'Baremetal' for efficiency and full visibility of the scheduler code, choose 'CMSIS-RTOS RTX' to generate code compatible with legacy code depending on the 'CMSIS-RTOS RTX'.

  • 'Baremetal' uses the interrupt selected in 'Base rate trigger' to run a rate monotonic scheduler for the model.

  • 'CMSIS-RTOS RTX' leverages the CMSIS-RTOS RTX provided by ARM to schedule the rates present in the model.

Follow the steps in the below figure to configure the scheduler options for the STMicroelectronics STM32F4-Discovery board.

3. The green LED (LED4) is driven by GPIOD Pin 12 on the STM32F4-Discovery board.For the LED to work correctly, GPIOD Pin 12 must be configured as an output in pull-up mode. To configure the GPIOD Pin 12 according to these specifications, follow the steps below:

4. Change Build action to Build, load and run to automatically download the generated hex file, stm32f4discovery_gettingstarted.hex, on to the connected STM32 Discovery board. Follow the steps below set the Build action:

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

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

..
.....
......
### Created: ../stm32f4discovery_gettingstarted.elf
### Invoking postbuild tool Binary Converter ...
arm-none-eabi-objcopy -O binary ../stm32f4discovery_gettingstarted.elf ../stm32f4discovery_gettingstarted.bin
### Done invoking postbuild tool.
### Invoking postbuild tool Hex Converter ...
arm-none-eabi-objcopy -O ihex ../stm32f4discovery_gettingstarted.elf ../stm32f4discovery_gettingstarted.hex
### Done invoking postbuild tool.
### Invoking postbuild tool Executable Size ...
arm-none-eabi-size ../stm32f4discovery_gettingstarted.elf
  text	   data	    bss	    dec	    hex	filename
  4264	    196	   8308	  12768	   31e0	../stm32f4discovery_gettingstarted.elf
### Done invoking postbuild tool.
### Successfully generated all binary outputs.
C:\Users\rkandur\AppData\Local\Temp\tp4d4ce2b8_bgl-rkandur\stm32f4discovery_gettingstarted_ert_rtw>exit /B 0
### Launching openOCD server "C:\MATLAB\SupportPackages\R2015aPrerelease\openocd-0.8.0\bin\openocd-0.8.0.exe" -f board/stm32f4discovery.cfg: Success
### Open telnet port for communction with openOCD server.
### Reset and halt the processor.
### Erase flash sectors.
### Download the executable ../stm32f4discovery_gettingstarted.elf: Success
### Reset and run the board.
### Close the server.
### Successful completion of build procedure for model: stm32f4discovery_gettingstarted

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

8. You can also run the download utility command codertarget.stm32f4discovery.utils.downloadToTarget('-f board/stm32f4discovery.cfg', 'stm32f4discovery_gettingstarted.hex'); from the MATLAB command prompt to load and run the generated hex file.

Task 2 - Configure the model for automatic load and run of the generated code on STM32F746G-Discovery Board

In this task, you will configure a simple model to run on the STMicroelectronics STM32F746G-Discovery board automatically.

1. Open the LED model. This model has been configured for the STM32F746G-Discovery board. Follow the steps shown in the figure below to configure the model for the appropriate STM32 Discovery board :

2. The green LED (LD1) is driven by GPIO Pin D13 on the STM32F746G Discovery.

3. Change Build action to Build, load and run to automatically download the generated hex file, stm32f746gdiscovery_gettingstarted.hex, on to the connected STM32 Discovery board. Follow the steps below set the Build action:

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

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

..
.....
......
C:/MATLAB/SUPPOR~1/R2016B~1/GCC-AR~2/bin/arm-none-eabi-objcopy -O binary ../stm32f746gdiscovery_gettingstarted.elf ../stm32f746gdiscovery_gettingstarted.bin
"### Done invoking postbuild tool."
"### Invoking postbuild tool "Hex Converter" ..." ...
C:/MATLAB/SUPPOR~1/R2016B~1/GCC-AR~2/bin/arm-none-eabi-objcopy -O ihex ../stm32f746gdiscovery_gettingstarted.elf ../stm32f746gdiscovery_gettingstarted.hex
"### Done invoking postbuild tool."
"### Invoking postbuild tool "Executable Size" ..." ...
C:/MATLAB/SUPPOR~1/R2016B~1/GCC-AR~2/bin/arm-none-eabi-size ../stm32f746gdiscovery_gettingstarted.elf
   text	   data	    bss	    dec	    hex	filename
16880	    416	    620	  17916	   45fc	../stm32f746gdiscovery_gettingstarted.elf
"### Done invoking postbuild tool."
"### Successfully generated all binary outputs."

### Successful completion of build procedure for model: stm32f746gdiscovery_gettingstarted

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

Task 3 - Review Block Library for your board

The Embedded Coder Support Package for STMicroelectronics Discovery Boards provides an easy way to create algorithms that use peripherals supported with dedicated blocks that can be added to your Simulink model. Use the STM32 Discovery 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 Embedded Coder Support Package for STMicroelectronics Discovery Boards and open the GPIO Write block for STM32F4-Discovery or Digital Write from STM32F746G-Discovery boards:

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

Summary

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

  • You can configure a Simulink model to generate code for the STMicroelectronics STM32F4-Discovery board and STM32F746G-Discovery board.

  • Simulink Support Package for STMicroelectronics STM32 Microcontrollers provides blocks for configuring, reading from and writing to STMicroelectronics STM32F4-Discovery and STM32F746G-Discovery peripherals.

Was this topic helpful?