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, STM32F746G-Discovery, or STM32F769I-Discovery board.
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:
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.
If you have not yet installed ST-Link/V2 USB drivers, follow the steps as described in Install Drivers for STMicroelectronics STM32 Discovery boards.
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
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.
2. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box. Go to Hardware Implementation > Hardware board.
3. Select STM32F4-Discovery as Hardware board.
4. Go to Hardware board settings > Operating system/scheduler > Operating system options and select Operating system > Baremetal or CMSIS-RTOS RTX
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.
5. For the green LED (LED4) to work correctly, GPIOD Pin 12 must be configured as follows:
Go to Hardware Implementation > Target Hardware Resources > GPIO D
Select Show GPIOD settings for: > Pin 12
Select Select output speed for Pin 12: > Fast speed
Select Select pull mode for Pin 12 > Pull-up
Note: You can either select GNU Tools for ARM Embedded Processors or Armclang Compiler toolchain for code generation. For more information, see Setup and Configure Armclang Compiler Toolchain for Code Generation.
6. Change Build action to Build, load and run and click OK to automatically download the generated hex file, stm32f4discovery_gettingstarted.hex, on to the connected STM32 Discovery board.
7. Go to Hardware tab and Click Build, Deploy & Start > Build Stand-Alone to generate code for the model.
8. 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 communication 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
9. Observe that the green LED turns ON for 0.5 second and switches OFF for 0.5 second periodically.
10. 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.
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.
2. Open the Modeling tab and press CTRL+E to open Configuration Parameters dialog box. Go to Hardware Implementation > Hardware board and select STM32F746G Discovery
3. The green LED (LD1) is driven by GPIO Pin D13 on the STM32F746G Discovery.
4. 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.
5. Go to Hardware tab and Click Build, Deploy & Start > Build Stand-Alone to generate code for the model.
6. 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
7. Observe that the green LED turns ON for 0.5 second and switches OFF for 0.5 second periodically.
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.
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.