cancel
Showing results for 
Search instead for 
Did you mean: 

Project generated using STM32-MAT-TARGET and Discovery board with STM32F407VG, compiles but does nothing.

MGonz.1
Associate

First of all, English is not my first Language, I hope you can undestand me. I'll try to explain all the details of my problem.

I'm trying to get started using STM32-MAT-TARGET, and I've tried a very simple project but it does not work. First I started the project from STM32CubeMX V 6.0.1. I selected the MCU, not the board (to keep it simple).

The push but (PA0) was set as input and the LEDS (PD12 to PD15) as output

0693W000004Ht8oQAC.jpg

The clock configuration was left as default:

Then I made a very simple model in MATLAB Simulink (2020a) with the

following Model Settings for STM32-MAT-TARGET.

The simulink model is very simple. If the push button is pressed, the LEDs will be on and if the push button is released, the LEDs will be off.

I used the .ioc file generated by STM32CubeMX0693W000004Ht8yQAC.jpg

the model was saved as "C:\Temp\Test0\T0.slx". Then I built the model by using rtwbuid in the matlab command line.

Then I loaded the generated project in STM32CubeIDE 1.4.0 and built it. I was built with 0 errors and 0 warnings.

My problem is that it does not run in the board. I tried to debug it by software and noticed that the project has two main functions and two "main.c" files:

0693W000004Ht9xQAC.jpg

I guess the first one is generated by STM32CubeMX and the second one by simulink. The first one has an empty infinite loop. The second main function (in the second "main.c" file), has a program that does what the simulink model says. If I debug the program executes the first main function and does nothing (empty infinite loop).

I don't know how to actually generate code that works.

THANKS IN ADVANCE

Notes:

If I save the simulink model with the same name as the .ioc file or the project, it does not buid in STM32CubeIDE and also have two main functions.

3 REPLIES 3
LMI2
Lead

I wonder if there is a misunderstanding. CubeMX creates code to set up your IO, but it does not drive or use them. You have to write code to use your IO.

Thank you for you answer. Yes, I know, I have written programs in STM32CubeIDE, uVision and Mbed and they work, but I want simulink to generate the code through ST32-MAT-TARGET.

I tried to follow this tutorial:

https://www.youtube.com/watch?v=hnZ622Fkwkg&t=457s

I used STM32CubeIDE instead of EWARM, a newer version of Matlab and I made a different simulink Model. I don't know what i did wrong.

Tomas DRESLER
Senior II

Hello, generally the Matlab working directory shall be the MAT-TARGET directory before project generation. The two main()-containing functions is a failure of the generator, possibly because CubeMx can't find the Simulink-generated main.

You can try cd'ing to the MAT-TARGET directory, or manually combine the two main.c files.

Tomas