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

47 visualizzazioni (ultimi 30 giorni)
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"
  3. INSTALLATION: STM32-MAT/TARGET from ST
  4. INSTALLATION: STM32CubeMX from ST
  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)
  11. SUCCESSFUL!
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
  3 Commenti
GUILHERME VIANNA SANTOS
GUILHERME VIANNA SANTOS il 12 Feb 2021
Modificato: GUILHERME VIANNA SANTOS il 12 Feb 2021
Hello,
I also found problems to complete the generated code, as reported by @Pascal Weller. The code generated by simulink was produced separately from the codes generated by STM32cubeMx and another by simulink, for example two main files were generated. I used STM32cubeMx version 6.1.1
Would you remember which version you used @Pascal Weller was?
To solve the problem I revert the version of STM32CubeMx to version 5.6.0. The .c and .h files are generated correctly, but in the STM32CubeIDE interface it is necessary to add to the project the folders generated by the simulink code generator. After that the compilation takes place correctly.
Maybe you already solved the problem, but this solution can help others maybe...
Pascal Weller
Pascal Weller il 23 Feb 2021
Modificato: Pascal Weller il 23 Feb 2021
Hello,
Unfortunately, I do not remember which version I used back then. Anyways, thanks for your input on the topic.
Best,
Pascal

Accedi per commentare.

Risposte (2)

Dionisio Cagigas Fojaco
Dionisio Cagigas Fojaco il 31 Mar 2020
Hi everyone and @Pascal Weller,
I have managed to get the LED blinking.
These are the things I had to modify:
STM32CubeMX
  • Select: ProjectManager\Project\Toolchain\IDE = STM32CubeIDE
  • Select: Pinout&Configuration\SystemCore\NVIC\CodeGeneration\TimeBase:SystemTickTimer -> TICK ON "Generate IRQ handler"
Matlab\Simulink
  • 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
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
  4 Commenti
Muhammad Bilal Aziz
Muhammad Bilal Aziz il 28 Set 2020
Hi Dionisio Cagigas Fojaco, I am using Nucleo F746ZG LQFP144. I followed the same procedure as you mentioned. But the problem is simulink is creating the .c and .h files but they are not generating on my ide.(Keil or stm32cubeide). Please help how to run those files(.c and .h) on the ide.
Thanks alot .
zini giacomo
zini giacomo il 25 Feb 2021
Modificato: zini giacomo il 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
6)save
7)apps->Embedded Coder->Custom Target and select again stm32.slc
8)Build
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
EDIT:
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.

Accedi per commentare.


Sergio Jiménez Concha
Sergio Jiménez Concha il 7 Ago 2023
How can I install stm32.tlc?

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by