Import projects from STM32CubeMX to Embedded Studio

From SEGGER Wiki
Revision as of 10:35, 6 October 2021 by Nino (talk | contribs)
Jump to: navigation, search

This Wiki article describes how to import STM32CubeMX projects into Embedded Studio. With Embedded Studio you get great benefits like a run time library and toolchain specifically tailored for embedded target devices, native J-Link support and many more.

Setup

The following software and hardware has been used to create the following example project and tutorial:

  • STM32CubeMX 6.3.0.
  • NUCLEO-G474RE MB1367C Evalboard
  • SEGGER Embedded Studio V5.62

Reference Project: NUCLEO-G474RE_Blinky_Test.zip

The reference project will blink an LED on the eval board mentioned above.

Import tutorial

This tutorial will show the steps necessary to get the resulting example project from above. But the same steps apply for any of the ST boards and MCUs in STM32CubeMX.

  • Start a new project in STM32CubeMX (in this example we start one for the NUCLEO-G474RE Board)
  • Configure your STM32CubeMX project as usual.
  • Go to the Project Manager tab in your STM32CubeMX project.
  • Set the project name and location.
  • Set the Toolchain/IDE to STM32CubeIDE. All other settings can be kept as is.
STM32CubeMX project manager settings
  • Press the Generate Code button.
  • You will now be prompted if you want to open the projects folder. Select Open Folder and keep that folder open.
  • Open Embedded Studio.
  • Select File -> Import Project... -> Import Eclipse Project
  • Navigate to the folder where the STM32CubeIDE project is located at and select the .project file and press Open.
STM32CubeMX project folder
  • Now select Internal Toolchain and press OK.
Embedded Studio importer settings
  • If everything worked successfully you will be greeted with as success screen.
Embedded Studio import success
  • In Embedded Studio now right click the Core folder in the Project Explorer window and open the folder options.
  • Set the build configuration from Debug Internal to Common in the options window and edit option Folder->Dynamic Folder Exclude.
  • Edit the Exclude Specifications line to Core/;syscalls.c;sysmem.c;startup_*.s and press OK.
Resulting folder exclude options
  • From now on the project should already build successfully, but we are not done yet.
  • Now download your device family's CPU Support Package in Embedded Studio via Tools->Package Manager, select your device family and install the package.
  • In this example we used a STM32G474RE as a device so the package we installed is the STM32G4xx package.
  • Next go to the package folder via File->Open Studio Folder->Packages Folder and open the just installed package folder, in this case /STM32G4xx.
  • In the project folder where the STM32CubeMX project and Embedded Studio project are located at create a new folder e.g. /ES and enter it.
  • Now copy the following files from the package folder to the project folder. In this example from /STM32G4xx -> /ES.
    • STM32G4xx/Source/<DeviceName>_Startup.s and STM32G4xx/Source/<DeviceName>_Vectors.s
    • The linker script from STM32G4xx/Scripts/<DeviceFamily>_Flash.icf.
    • The memory map from STM32G4xx/XML/<DeviceName>_MemoryMap.xml.
    • The registers file from STM32G4xx/XML/<DeviceName>_Registers.xml.
Resulting folder after copying files over
  • Now add that /ES folder via drag and drop to your Embedded Studio project in the Project Explorer window.
  • Open project options and change the build config to common. Set the Linker Script file and the memory map file in project options to the .icf file and .xml file just copied from the packages folder.
  • Set the registers file to the Registers.xml file just copied if available.
  • Exclude file Internal Files/Cortex_M_Startup.s from the project by right clicking it and selecting Exclude From Build.
  • Done, now you can add your own code to the application and debug and develop in Embedded Studio.

Troubleshooting

  • The project builds, but debugging is not working properly and unexpected code is being jumped to.
    • Check your debug config settings. Unfortunately most CubeMX projects will have code optimization set to -Os (optimize for size) even for debug builds. Change the code optimization to 'None' instead.
  • I can not find a CPU support package for my device.
    • Generally the import can also be done without the device specific files from the CPU support packages as the generic files should also work for most cases. In such case simply make sure that the memory segments set in project options also fit your target device properly.
    • Alternatively you can always contact our support team to see if a CPU support package could be added. You can reach the team under segger.com/ticket