First you have to download the official STM 32 simulink package STM32-MAT URL link
Then unzip it to install, draw up the installation address by yourself, open the installation directory, you will see the startuop.bat file, double-click to run it will automatically open matlab
Click Set Path, then add the folder you installed, and then click Save
The first part is complete.
the second part
Open the cubemx you installed, select your chip model, configure the peripherals you need, I only configured a clock, download and LED here
Then configure the name of your project, select the project path, select your MDK, and then check the Code Generator to generate separate .c and .h
Finally select save project in File, you will see a blue ioc file in the path folder, which proves success
the third part
I suggest that the simulink project file you create and the ioc file are separated by a folder, or they are directly together.
If you open the project created by simulink directly, then the directory outside of matlab is probably not the directory of your project, remember to change this to the directory of your project