cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] SIMULINK compilation successful but how to continue within STM32CubeIDE and deploy to the board? Some files appear to be missing

DCagi.1
Associate II

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:
    1. Matlab/Simulink R2018b 64bit with toolboxes like Embedded Coder
    2. Matlab/Simulink HW support package "Embedded Coder Support Package for STMicroelectronics Discovery Boards"
    3. STM32-MAT/TARGET from ST
    4. STM32CubeMX from ST
    5. STM32CubeIDE_1.3.0 from ST
  2. 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: ProjectManager\Project\Toolchain\IDE = STM32CubeIDE
    4. Select: Pinout&Configuration\SystemCore\NVIC\CodeGeneration\TimeBase:SystemTickTimer -> TICK ON "Generate IRQ handler"
  3. 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:
      1. Solver: Fixed-step, stop time = inf, step time = 0.001
      2. Code generation: Select the target file as "stm32.tlc" (This takes a while...)
      3. Code generation: Within the STM32 options, update the STM32CubeMx path
    4. Open the Simulink library and at the bottom should be the library for "Target support package - STM32 adapter"
    5. Select block "STM32_Config" and link to the .ioc file generated within STM32CubeMx
    6. Select block GPIO_Write and configure the pin 13
    7. Build:
      1. Create a separate empty folder
      2. Make it your working folder -> In here, all the files generated by the Simulink build will be generated, and not mixed up
      3. Simulink model: Ctrl+B (Build)
      4. SUCCESSFUL!
      5. A .project is generated
  4. STM32CubeIDE:
    1. Open the .project generated (double-click on it)
    2. Within the project tree, right-click on the sub-folder "BlinkLED", select "Properties"
    3. Within the properties tree, select C/C++ build, configuration "DEBUG"
    4. Remove the TICK from the box "Exclude resource from build"
    5. Do the same for the configuration "RELEASE"
    6. Apply and close
    7. Within the project tree, right-click on the top-folder -> Debug as: STM32 Cortex M C/C++ Application
  5. BUILD FAILED, 4x ERRORs! -> These errors should not appear anymore

C:/Users/isc2tr/Documents/MATLAB/Examples/BlinkLED/Debug/../Src/main.c:124: undefined reference to `BlinkLED_initialize'

C:/Users/isc2tr/Documents/MATLAB/Examples/BlinkLED/Debug/../Src/main.c:145: undefined reference to `BlinkLED_step'

C:/Users/isc2tr/Documents/MATLAB/Examples/BlinkLED/Debug/../Src/main.c:134: undefined reference to `BlinkLED_M'

collect2.exe: error: ld returned 1 exit status

make: *** [makefile:44: BlinkLED.elf] Error 1

What am I missing?

How can I deploy the code generated in Simulink to the board, by using the STM32CubeIDE?

Thanks

SOLVED: Follow the updated step-by-step process above.

14 REPLIES 14
DCagi.1
Associate II

Another option to avoid the STM32CubeIDE, could be to generate directly from Matlab-simulink a .bin file and load it to the board with the ST-Link Utility. But the Build (Ctrl+B) process in Simulink does not generate this .bin file. Is there a certain tab/option that needs to be enabled? Thanks

Cyril FENARD
ST Employee

Hi @DCagi.1​ ,

What you did seems right.

The problem you encountered is that it is a link error, which means that some files are not compiled properly in your STM32CubeIDE project.

Can you check that files that are missing are not excluded from build in the STM32CubeIDE project(have a look at the properties of BlinkLED items).

Regards.

Cyril

PS: These kinds of issue are already reported on STM32-MAT/TARGET forum also.

DCagi.1
Associate II

Hi @Cyril FENARD​ 

These are the files before compiling the SIMULINK model:0693W000000U7XMQA0.jpg

These are the files after:

0693W000000U7XbQAK.jpg

As you can see, a ".project" is generated, which is the one I open within STM32CubeIDE.

Not sure what you mean by "check the properties of BlinkLED items".

Is this something to modify within the BUILD configuration in SIMULINK? If so, how?

Thanks a lot

Cyril FENARD
ST Employee

Hi @DCagi.1​ ,

I share an example of build properties under the STM32CubeIDE view:

0693W000000U7j3QAC.png

Regards,

Cyril

DCagi.1
Associate II

Thanks a lot @Cyril FENARD​ 

I get no more errors in STM32CubeIDE.

However, the LED does NOT light on.

I tried to load the .bin generated making use of the STM32-Link Utility, but does NOT work either.

Which part of the code should I check? Which file actually contains "the logic" modelled in Simulink?

This is the Simulink model, and I have attached the Simulink build log file (.txt):0693W000000UVLZQA4.jpg

Thanks everyone.

Cyril FENARD
ST Employee

Hi @DCagi.1​ ​ ,

You have built the final application with the IDE you choose, that is to say the STM32CubeIDE in your case.

You can debug directly using the STM32CubeIDE tool.

BlinkLED.h/c are files generated by the Simulink coder.

You can add a breakpoint in the BlinkLED_step () function. This function should call the HAL GPIO functions.

Regards,

Cyril

DCagi.1
Associate II

Hi @Cyril FENARD​ 

It seems, it never gets to the "BlinkLED_step ()" function, since this variable is always 1: remainAutoReloadTimerLoopVal_S == 1

Could it be related to any configuration of the clock within Stm32CubeMx (.ioc file)?

With the "System Core", selecting the "SYS", the timebase source is set to "SysTick":

0693W000000UymjQAC.jpg

Any ideas?

Regards

DCagi.1
Associate II

Forgot to attach the main.c file

Cyril FENARD
ST Employee

Hi @DCagi.1​ ,

May you also share the stm32xxxx_it.c file?

SysTick_Handler() should be called periodically in you use-case.

Regards.

Cyril