Import projects from STM32CubeMX to Embedded Studio

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

This Wiki article describes how to import STM32CubeMX projects into Embedded Studio. With Embedded Studio you get great benefits such as a runtime 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:

Reference Project: NUCLEO-G474RE_Blinky_Test.zip

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

Project Import

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

  • Start a new project in STM32CubeMX. (In this example we create a project for the NUCLEO-G474RE Board)
  • Configure your STM32CubeMX project as usual.
  • Go to the Project Manager tab in your STM32CubeMX project.
  • Set Project Name and Project Location.
  • Set the Toolchain/IDE to STM32CubeIDE.
STM32CubeMX project manager settings
  • Press the Generate Code button.
  • You will be prompted whether 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 Project Location, select the .project file and press Open.
STM32CubeMX project folder
  • Select Internal Toolchain and press OK.
Embedded Studio importer settings
  • Embedded Studio imports the project, generates a project file project.emProject, and shows a success message.
Embedded Studio import success
  • In Embedded Studio 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

The basic project import and setup is done. The project can be further tweaked for the selected target device, by using target-specific files from the CPU Support Package:

  • Download your device family's CPU Support Package in Embedded Studio via Tools->Package Manager, select your device family and install the package. (For the STM32F474RE install 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 example /STM32G4xx/)
  • In the Project Location create a new folder /ES/ and enter it.
  • Copy the following device-specific files from the package folder to this folder. (In this example from $(PackagesDir)/STM32G4xx/ to $(ProjectDir)/ES/)
    • The startup code, /Source/<DeviceName>_Startup.s. (Source/STM32G4xx_Startup.s)
    • The vector table, /Source/<DeviceName>_Vectors.s. (Source/STM32G474_Vectors.s)
    • The linker script, /Scripts/<DeviceFamily>_Flash.icf. (Source/STM32G4xx_Flash.icf)
    • The memory map, /XML/<DeviceName>_MemoryMap.xml. (/XML/STM32G474RETx_MemoryMap.xml)
    • The registers file, /XML/<DeviceName>_Registers.xml. (/XML/STM32G474xx_Registers.xml)
Resulting folder after copying files over
  • 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 *_MemoryMap.xml file just copied from the packages folder.
  • Set the registers file to the *_Registers.xml file just copied if available.
  • In the projects Explorer remove the generic startup code in Internal Files/Cortex_M_Startup.s.

Done. The project is imported, setup, and tweaked for your target system. You can now add your code and debug your application 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