Plecs generate code for stm32cubeIDE

How do I load code generated by PLECS into STM32CubeIDE? Note: I set it up to generate code from a circuit in PLECS, but I just can’t load it as an STM32 project.

The procedure to deploy code via the STM32 Cube IDE is described in the section titled “Program the MCU from STM32CubeIDE” in the STM32 Target Support User Manual. This user manual can be downloaded on the Plexim website:

https://plexim.com/download/documentation

The steps are as follow:

  1. Download STM32CubeIDE and the STM32 Target Support Package.

  2. Open STM32CubeIDE. This will open a workspace.

  3. The STM32 Target Support Package includes archives that contain pre-configured projects for STM32CubeIDE. These archives are located in the projects folder. Which project needs to be used depends on the MCU target family (f3xx.zip or g4xx.zip).

  4. Import the pre-configured STM32CubeIDE project into your STM32CubeIDE workspace. To do so, open STM32CubeIDE, click on the File drop-down menu and then select Import… Click on General + Existing Projects into Workspace. Next, select “Select archive file” and browse to the directory your STM32 Target Support Package is located in. See the picture below to see what this step should look like.

  1. A project named cube_g4xx_v1_5 or cube_f3xx_v1_5 should now appear in your workspace. This project contains a folder named “cg”. Identify the path of this folder.

  2. Open PLECS and create your model using blocks from the STM32 Target Library. Open the Coder Options and select the target you want to generate code for and set the build type to “Generate code into STM32CubeIDE project”.

  3. For the STM32CubeIDE project directory, enter the path to the “cg” folder (see point 5).

  4. Click on “Build” to generate code.

  5. Go into the “cg” folder in STM32 Cube IDE. You should find all the generated files in this folder.

  6. Return to STM32 Cube IDE and right-click on your project and navigate to Build Configurations→Set Active. Select the target that you want to generate code for.

  7. Build and debug the STM32 Cube IDE project as you would build and debug any STM32 Cube IDE project.

I hope this guide is helpful - please let me know if you have any lingering questions!

1 Like

It worked, thanks for the help.