cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a custom build setup in STM32CubeIDE

B.Montanari
ST Employee

This article covers how to create a custom build setup to allow users to customize, modify, and add specific build settings for each file, folder, or project.

Introduction

Creating a custom build in STM32CubeIDE can be a powerful tool for developers looking to optimize their project's build process. Furthermore, to configure the build settings to meet specific needs and to improve project efficiency.

This feature is particularly useful when working on complex projects that require different build settings for various parts of the project. For example, a project may require different build settings for the firmware, bootloader, and application code. Using the “Manage Configurations” option, developers can easily create separate build configurations for each of these parts of the project. This makes it easier to manage and modify the build process options to specific projects, folders, or separate files.

In this article, we walk you through the steps to create a custom build in STM32CubeIDE and explore some of the benefits of this powerful feature.

So, let us get started and learn how to create a custom build in STM32CubeIDE!

1. Development

1.1 Basic steps

The steps below specify how to create the new compilation settings:

  1. Create an STM32 project, using the STM32CubeIDE.
  2. Right click on the Project > "Properties"
BMontanari_0-1705600232962.png
  1. Go to "C/C++ Build" > "Settings" > "Manage Configurations."
BMontanari_1-1705600232966.png

 

  1. In the "Manage Configurations" tab, click on "New."
BMontanari_2-1705600232967.png
  1. Give it a name and description > “Copy settings from: Existing Configuration (Debug)" > "OK."
BMontanari_3-1705600232968.png

The added build configuration might look like the following. Click OK and then “Apply and Close.”

BMontanari_4-1705600232968.png

2. Simple use case for a custom build

 After following the basic steps mentioned the user can, for example, exclude a file from building. This can be achieved by following the steps below.

  1. Back to the Project Tree > Right click in the file you would like to exclude from the build/debug configuration created > "Properties".
BMontanari_5-1705600232971.png

 

  1. Go to "C/C++ Build" > "Settings" > Select Configuration “Test” > Check the box "Exclude Resource from Build" > " Apply and Close."
BMontanari_6-1705600232972.png

 

  1. Right click on the Project > "Build Configurations" > "Set Active" > Be sure "Test" is selected.
BMontanari_7-1705600232974.png

 

 

  1. It looks like this (For this test, the file "sysmem.c" was selected not to be compiled):
BMontanari_8-1705600232975.png

The same steps can be replicated, so each selected build configuration only compiles the desired files.  

2.1 Adding compiling symbols

 A compilation symbol can be another extremely useful resource in the application code. Let us check a simple example using the custom build feature.

Add the code below:

  while (1)
  {
#ifdef BLINK_LED
	  HAL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin);
#endif
	  
#ifdef PRINTF
	  printf("Custom Build Message!");
#endif
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

In the "Project Properties", go to “C/C++ Build” > “Settings” > “MCU GCC Compiler” > “Preprocessor” > “Add New”

Note: Remember to specify the build configuration to be used, in this example, “Test.”

 

BMontanari_9-1705600232978.png

 Add “PRINTF” and “BLINK_LED” Symbols:

After applying the changes, the code within the #ifdef statement will be compiled in this building configuration.

BMontanari_16-1705600723726.png

2.2 Creating different build artifact names

Creating different build artifact names can be useful for quickly identifying which project settings were used to create the given application. Each binary file created can have a custom name associated to its build configurations.

  1. Right click on the Project > “Properties” > “C/C++ Build” > “Settings” > “Build Artifact” > “Artifact Name”:
BMontanari_10-1705600232980.png

After building with “Test” build configuration active, the compilation files will appear as:

BMontanari_11-1705600232981.png

3. Using the build settings tab

With the C/C++ Build option in “Project Properties”, users can perform a considerable set of configurations

  • Adding build variables
  • Enable or disable build logging and file location
  • Change and add option flags for the compiler, linker, and assembler tool
  • Post build outputs (convert to binary, hex etc.)
  • Optimization settings
  • Pre-build and post-build commands

Let us look at some of these options below:

3.1 Adding .BIN and .HEX files

In Project Properties > “C/C++ Build” > “Settings” > “MCU Post Build Outputs” > Check the boxes to generate the files after build.

BMontanari_12-1705600232986.png

3.2 Changing optimization level

In "Project Properties" > “C/C++ Build” > “Settings” > “MCU GCC Compiler” > “Optimization” > Select the desired “Optimization Level.”

BMontanari_13-1705600232990.png

3.3 Adding theFPU (Float Point Unit)

Using the Custom Build feature, user can easily enable or disable the FPU for each build configuration, by just selecting the Build configuration, for example “Test,” and defining the FPU.

BMontanari_14-1705600232994.png

Conclusion

In conclusion, creating a custom build setup in STM32CubeIDE can greatly benefit developers looking to optimize their project's build process and improve project efficiency.

By following the steps outlined, developers can take advantage of this powerful feature and customize their build process to meet their specific needs.

This article has also provided some simple use cases for custom build, such as:

  • Easy creation of separate build configurations for different parts of the project
  • Allowing for specific build settings to be applied to each file, folder, or project
  • Adding compiling symbols
  • Creating different binary names, and changing optimization levels 

Hope this all helps to improve your project efficiency!
See you soon!

Related links

STM32CubeIDE User Manual

 

Version history
Last update:
‎2024-06-18 12:55 AM
Updated by: