MATLAB Answers

Simulink code generation for STM32: how to generate the .bin file?

95 views (last 30 days)
Dionisio Cagigas Fojaco
Dionisio Cagigas Fojaco on 13 Mar 2020
Edited: zini giacomo on 25 Feb 2021
Hi everyone,
I have bought a STM32F4-Discovery Board DTM32F429I-Disc1, and my intention is to work in Matlab-Simulink.
This is the process I have followed:
  1. INSTALLATION: Matlab/Simulink R2018b 64bit with toolboxes like Embedded Coder
  2. INSTALLATION: Matlab/Simulink HW support package "Embedded Coder Support Package for STMicroelectronics Discovery Boards"
  5. INSTALLATION: STM32CubeIDE_1.3.0 from ST
Within STM32CubeMX, generate the .ioc file for the right board/MCU in order to blink the green LED:
  1. Give it the name "BlinkLED"
  2. PG13 as GPIO_Output and with a name "GreenLED"
  3. Select Toolchain\IDE = STM32CubeIDE (Project Manager \ Code Generator)
Within Matlab-Simulink:
  1. Add the STM32-MAT/TARGET path to Matlab's path (pathtool)
  2. Create a new simulink model
  3. Within the configuration parameters:
  4. Solver: Fixed-step, stop time = inf, step time = 0.001
  5. Code generation: Select the target file as "stm32.tlc" (This takes a while...)
  6. Code generation: Within the STM32 options, update the STM32CubeMx path
  7. Open the Simulink library and at the bottom should be the library for "Target support package - STM32 adapter"
  8. Select block "STM32_Config" and link to the .ioc file generated within STM32CubeMx
  9. Select block GPIO_Write and configure the pin 13
  10. Build (Ctrl+B)
However, I can not find a .bin file that can programmed on the board using the "ST-Link Utility". Any ideas?
Other option is to open the .project generated within STM32CubeIDE, but there are seem to be some files missing?
Thanks a lot
Pascal Weller
Pascal Weller on 23 Feb 2021
Unfortunately, I do not remember which version I used back then. Anyways, thanks for your input on the topic.

Sign in to comment.

Answers (1)

Dionisio Cagigas Fojaco
Dionisio Cagigas Fojaco on 31 Mar 2020
Hi everyone and @Pascal Weller,
I have managed to get the LED blinking.
These are the things I had to modify:
  • Select: ProjectManager\Project\Toolchain\IDE = STM32CubeIDE
  • Select: Pinout&Configuration\SystemCore\NVIC\CodeGeneration\TimeBase:SystemTickTimer -> TICK ON "Generate IRQ handler"
  • Before launching the build of the Simulink model (Ctrl+B), create a separate folder, and go there (make it your working directory within Matlab)
  • Now, go to Simulink, and build (Ctrl+B)
  • This will prevent files getting mixed-up
  • If the build is successful, within the folder in which the .slx model is, a .project file will be generated. This is the project to be opened in STM32CubeIDE
  • Within the project tree (on the left hand side), navigate to the sub-folder of the project called like the simulink .slx model (it should contain a "Inc" and "Src" sub-folders)
  • Right click -> Properties -> C\C++ build -> Un-tick the option "exclude resource from build"
  • Connect the board
  • Within the project tree, go to the top level, right-click and "Debug-as"
  • This will generate the "Debug" folder, and within it, the .bin\.elf files
Hope it helps
zini giacomo
zini giacomo on 25 Feb 2021
similar problem here:
my procedure is this
1)Open CubeMX and create a simple project with atollic truestudio as toolchain, then i don't create the project just save the .ioc file in my workspace
2)open matlab, create a folder in the main workspace and in it i create an slx model
3)open simulink, in model configuration parameters:
stop dime=inf
fixed step
sample time= 1e-3
code generation:
system target file= stm32.slc
STM32 options:
tick on stm32cubeMX path
4)stm32_Config block i select the .ioc file
5)make a simple model of a blinking led
7)apps->Embedded Coder->Custom Target and select again stm32.slc
9) at this point i got a project with the main.c exactly as cubeMX had create it with the while(1) empty
10)now i can build and debug but of course the code don't do anything, because the function in the .c file with the simulink progect is never called
i 've solved selecting BASIC from application structure in cubeMX
actyally you need just to select BASIC from application structure, even if you have teh latest version of cubeMX, at leas it worked for me.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!