UM1718

STM32CubeMX user interface

 

 

Figure 53. Formula when input parameter is set in No Check mode

4.4.11User Constants configuration window

An User Constants tab is available to define user constants (see Figure 54). Constants are automatically generated in the STM32CubeMX user project within the main.h file (see Figure 55). Once defined, they can be used to configure peripheral and middleware parameters (see Figure 56).

Figure 54. User Constants tab

UM1718 Rev 41

87/453

STM32CubeMX user interface

UM1718

 

 

Figure 55. Extract of the generated main.h file

Figure 56. Using constants for peripheral parameter settings

88/453

UM1718 Rev 41

UM1718

STM32CubeMX user interface

 

 

Creating/editing user constants

Click the Add button to open the User Constants tab and create a new user-defined constant (see Figure 57).

A constant consists of:

A name that must comply with the following rules:

It must be unique.

It shall not be a C/C++ keyword.

It shall not contain a space.

It shall not start with digits.

A value

The constant value can be (see Figure 54 for examples):

a simple decimal or hexadecimal value

a previously defined constant

a formula using arithmetic operators (subtraction, addition, division, multiplication, and remainder) and numeric value or user-defined numeric constants as operands

a character string: the string value must be between double quotes (example: “constant_for_usart”).

Once a constant is defined, its name and/or its value can still be changed: doubleclick the row that specifies the user constant to be modified. This opens the User Constants tab for edition. The change of constant name is applied wherever the constant is used. This does not affect the peripheral or middleware configuration state. However changing the constant value impacts the parameters that use it and might result in invalid settings (e.g. exceeding a maximum threshold). Invalid parameter settings are highlighted in fuchsia.

Figure 57. Specifying user constant value and name

UM1718 Rev 41

89/453

STM32CubeMX user interface

UM1718

 

 

Deleting user constants

Click the Remove button to delete an existing user-defined constant.

The user constant is then automatically removed except in the following cases:

When the constant is used for the definition of another constant. In this case, a popup window displays an explanatory message (see Figure 58).

Figure 58. Deleting an user constant is not allowed when it is already used for another constant definition

When the constant is used for the configuration of a peripheral or middleware library parameter. In this case, the user is requested to confirm the deletion since the constant removal results in a invalid peripheral or middleware configuration (see Figure 59).

Figure 59. Confirmation request to delete a constant for parameter configuration

Clicking Yes leads to an invalid peripheral configuration (see Figure 60).

Figure 60. Consequence when deleting a user constant for peripheral configuration

90/453

UM1718 Rev 41

Соседние файлы в папке STM