En DM00629856
En DM00629856
En DM00629856
User manual
Introduction
STM32CubeIDE is an all-in-one multi-OS development tool part of the STM32Cube software ecosystem. It contains an
advanced C/C++ development platform supporting software development of STM32-based products.
This document details the STM32CubeIDE features and usage, including how to get started, create and build projects, debug
with standard and advanced techniques, and many other software analysis solutions. STM32CubeIDE is based on the Eclipse
C/C++ Development Tools™ (CDT™) and GCC toolchain, which cannot be entirely described in this user manual. Additional
information on Eclipse® is available from STM32CubeIDE embedded help system. Special documents covering the details of
the toolchain and GDB servers are included within the product.
1 Getting started
STM32CubeIDE supports STM32 products based on the Arm® Cortex® processor. Refer to STMicroelectronics
documents listed in Section 10 References for details.
Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
Integrated STM32CubeMX
debugging
Build Analyzer
Import
SFRs view
Project wizard Debug configuration and launch
Note: macOS® is a trademark of Apple Inc. registered in the U.S. and other countries.
All other trademarks are the property of their respective owners.
1.1.4 License
STM32CubeIDE is delivered under the Mix Ultimate Liberty+OSS+3rd-party V1 software license agreement
(SLA0048).
For more details about the license agreement of each component, refer to [ST-02].
1.1.5 Support
There are several different support options provided by STMicroelectronics. For instance, the ST Community is
offering places to meet people with similar mind-set all over the world at any time. Choose the support option by
visiting my.st.com/content/my_st_com/en/support/support-home.html.
Workspaces
When starting STM32CubeIDE, a workspace is selected. The workspace contains the development environment
to be used. Technically, the workspace is a directory that may hold projects. The user may access any project
within the active workspace.
A project contains files, which may be organized into sub-directories. Files existing somewhere else on the
computer can also be linked to the project.
A single computer may hold several workspaces at various locations in the file system. The user may switch
between workspaces, but only one workspace can be active at a time. Switching workspace is a quick way of
switching from one set of projects to another.
In practice, the workspace and project model facilitate a well-structured hierarchy of workspaces, containing
projects, which in turn contain files.
Information center
The first time STM32CubeIDE is started and a workspace is selected, the Information Center is opened. The
Information Center provides quick access to start a new project, read STM32CubeIDE documentation, or get
access to ST support & community. The Information Center can be easily accessed at any time via the
Information Center toolbar button or from the Help menu.
STM32CubeIDE window
Name of current workspace Menu bar Toolbar Editor area Outline view
Windows®
If a desktop shortcut is created during the installation of the product, the shortcut can be used to start
STM32CubeIDE. The product can also be started from the Windows® start menu under STMicroelectronics
programs.
Otherwise:
1. Locate where STM32CubeIDE is installed, for instance in C:\ST\STM32CubeIDE_1.0.2
2. Open the STM32CubeIDE folder
3. Start the stm32cubeide.exe program
Linux® or macOS®
When using Linux® or macOS®, the program can be started in a similar way by opening the STM32CubeIDE
folder where the product is installed.
STM32CubeIDE Launcher
When the product is started, it displays the STM32CubeIDE Launcher dialog with workspace selection. The first
time the product is started, it presents a default location and workspace name. The dialog enables the user to
select the name and location of the active workspace for holding all the projects currently accessible by the user.
Any newly created project is stored in this workspace. The workspace is created if it does not yet exist.
Note: If Windows® is used, avoid locating the workspace folder too many levels below the file system root to avoid
exceeding the Windows® path length character limitations. Build errors occur if the file paths become longer
than what Windows® can handle.
Click on the [Launch] button to launch STM32CubeIDE. The first time, it opens the Information Center, which is
described in Section 1.3 Information Center.
It is not required to read all material before using the product for the first time. Rather, it is recommended to
consider the Information Center as a collection of reference information to return to, whenever required.
When using an old workspace, the Information Center may not display valid information, showing “This page can’t
be displayed” or opening old manuals when accessing documents. In such case, reload the page by clicking on
the [Home] button at the top right corner of the Information Center window.
Scroll through the Technical Documentation page and click on a document in the list to open it. The documents
are listed in groups:
• IDE documentation
• STM32Cube ecosystem documentation
• Build tools
• Debugger documentation
• Toolchain manuals (GNU Tools for STM32)
• Toolchain manuals (GNU Arm Embedded)
Note: There are two toolchain manual groups because STM32CubeIDE is distributed with both a GNU Arm Embedded
toolchain and a GNU Tools for STM32 toolchain with patched enhancements.
To navigate back to the Home page, press STM32CubeIDE Home at the top left side of the Information Center.
1.4.1 Perspectives
The perspectives can be customized according to the user's need; Views can be moved, resized and new views
can be opened. It is possible to reset the perspective at any time if, for instance, too many views are opened or if
the views are reordered. The perspective is reset by right-clicking the perspective icon in the toolbar and selecting
[Reset] from the list. This resets the views; Added views in the perspective are closed and the default views are
moved to their original location.
As seen in Figure 8, it is also possible to customize a perspective and save the perspective with a new name.
Switching from one perspective to another is a quick way to hide some views and display others. To switch
perspective, select the [Open Perspective] toolbar buttons at the right of the toolbar.
The Remote Systems view contains buttons to open a new connection via FTP, Linux®, Local, SSH, Telnet and
others.
1.4.2 Editors
The editor area in a perspective is used by editors. Any number of editors can be opened simultaneously but only
one can be active at a time. Different editors can be associated with different file extensions. Example of editors
are; c-editor, linker script editor, ioc-file editor for STM32CubeMX device configuration.
To open a file in the editor, double-click on the file in the Project Explorer view or open the file via the [File] menu.
When a file is modified in the editor,it is displayed with an asterisk (*) indicating that the file has unsaved changes.
1.4.3 Views
Only the most common views associated with the perspective are displayed by default. There are many more
views in the product supporting different features. Some of these views only provide valid data when a debug
session is ongoing, while others always display data.
Views can be opened from the [Window]>[Show View] menu by selecting one of the views in the list.
The above list of views in Figure 15 is still not complete. It contains only the most common views for the work task
related to the perspective currently selected. To access even more views, select [Other…] from the list. This
opens the Show View dialog box. Double-click on any view to open it and access its additional features.
The views can be resized and their positions can be changed: Simply drag the view to a new place in
STM32CubeIDE. The view can also be dragged outside the STM32CubeIDE window on the screen. Such
detached views are shown in separate windows. Detached views works like the other views but are always shown
in front of the workbench. Detached views can be attached again by dragging the tab in the detached view into
the STM32CubeIDE window.
To restore the perspective to original state, right-click the perspective icon in the toolbar and select [Reset] from
the list. Another way to reset the perspective is to use the menu [Window]>[Perspective]>[Reset Perspective].
[Restore Defaults] resets all changes. The preference settings are stored in a metadata folder in the workspace
of the application. Section 1.7 Managing existing workspaces in this user manual provides information on how to
backup preferences and copy preferences across workspaces.
It is advised to walk through the preferences pages and get an understanding of the possible configuration
options. The following sections present some of them.
The menu selection [C/C++]>[Code Style]>[Formatter] provides a Preferences pane containing settings to set an
active profile.
At this point, if [Edit…] is pressed, a new dialog is opened, where the selected profile can be updated according
to specific coding rules. This is displayed in Figure 21.
Note: If there is a problem to save the proxy settings, the reason can be a corrupt secure_storage file. Proceed as
follows to solve the problem:
1. Rename file C:\Users\user_name\.eclipse\org.eclipse.equinox.security\secure_stora
ge to a new name
2. Restart STM32CubeIDE
3. Update the proxy network settings, with user and password information, and save them to create a new se
cure_storage file
It is also possible to select and remove recent workspaces from the list of recent workspaces. However, removing
a workspace from that list does not remove the files. Neither does it remove the files from the file system.
If this message is displayed, choose a different workspace, or return to the already running STM32CubeIDE.
Pressing CTRL+Shift+L in this sheet opens the Keys pane in the Preferences dialog.
The Keys pane offers the possibility to examine the shortcuts in detail and change the scheme (Default, Emacs,
or Microsoft® Visual Studio), reconfigure shortcut keys, and others.
Table 1 presents some of the keys to mention with their default bindings.
Add some text and see that this text is entered in all marked rows. As an example, the text “My_” is added and
displayed in Figure 31.
Copy the selected block by using Ctrl+C. This copied text can then be inserted elsewhere. To do so, type Alt
+Shift+A to toggle the selection modeback to the normal mode, move the cursor to another line, and type Ctrl+V
to paste the copied columns to the new lines.
Use the navigation buttons to navigate between differences, or simply navigate in the view using the scroll bar to
see the file differences.
In the case presented in Figure 38, there are three revisions of main.c. Double-click on a file in the History view
to open it in the editor.
Right-click on a file in the history and select [Compare Current with Local] to compare it with the current version
of the file.
This opens the File Differences editor and displays the file changes.
As mentioned in Section 1.6 Workspaces and projects, a workspace is a directory containing projects. The first
time a workspace is created, it is empty without any projects. The projects need to be created or imported in the
workspace. This section contains information on how to create projects in the workspace and build projects. It
also covers how to import and export projects.
However, the Eclipse® C/C++ Development Toolkit (CDT), which STM32CubeIDE is based on, contains also
basic project wizards, which can be used to create C managed build, C++ managed build, and makefile projects.
The STM32 projects can be:
• C or C++
• Generated executable or library file
• Based on STM32Cube (using STM32 firmware library package) or empty projects
STM32 projects also support an advanced umbrella project structure, where one project contains many projects,
for instance one project per core for multi-core devices.
The MCU/MPU selector and Board Selector tabs can be selected at the top of the window. Use the first tab to
create project for a specific device and the second if a project for a specific board is needed.
This section presents the creation of a project for the NUCLEO-F401RE board using the Board Selector.
Among the different filters available for use on the left of the window, type “401” in the Part Number Search field to
filter the boards with names containing this string. In Figure 42, two boards are listed, a Nucleo board board and a
Discovery board. The NUCLEO-F401RE board is selected.
Five tabs, Features, Large Pictures, Docs & Resources, Datasheet, and Buy, offer the possibility to display
detailed information about the selected board or device. For instance, documentation available for the board is
displayed and can be opened when Docs & Resources is selected. When Datasheet is selected, the board
datasheet is downloaded from STMicroelectronics web site.
Pressing [Next] when the NUCLEO-F401RE board is selected opens the Project setup page.
Enter a project name and select the desired setting for the project in the dialog boxes. The project named
“NUCLEO-F401RE” is filled in as an example in Figure 43.
According to the settings in Figure 43, the project is meant to be stored in the default location with the following
options set:
• C project
• Executable binary type
• STM32CubeIDE targeted project type
Press [Next] to open the Firmware Library Package Setup page.
In this page, it is possible to select the STM32Cube firmware package to use when creating the project. In this
case, the default settings are used. Press [Finish] to create the project.
As a result, the following dialog is displayed.
Press [Yes] since it is a good practice to get the software needed to initialize the peripherals.
This opens the new dialog shown in Figure 46.
Opening the STM32CubeMX perspective is a good decision if there are any needs to configure the device.
Enable [Remember my decision] if the question msut not be asked the next time a new project is created. Press
[Yes] to continue.
At this point, the project creation starts. The time it takes depends on the amount of files that need to be
downloaded to create the project.
When the project is created, the STM32CubeMX perspective is opened with a window for configuring the
peripherals, clock, middleware, and power consumption.
The new project is listed in the Project Explorer view with some of the folders and files it contains.
The NUCLEO-F401RE.ioc file contains the configuration settings and is opened in the STM32CubeMX editor.
This editor contains tabs for Pinout & configuration, Clock configuration, Project manager and Tools. When
changes are made in the STM32CubeMX editor, the .ioc file in the tab is marked as changed. If the file is saved,
a dialog opens asking “Do you want to generate Code?”, making it easy to generate new code in the project that
supports the new device configuration. For more information on how to use the STM32CubeMX editor, refer to
[ST-12].
In Figure 49, the Targeted Project Type is selected to be empty. If project type [STM32Cube] is selected instead,
the generated project contains STM32 drivers also. Press [Finish] to create the project.
Once the project is created, the Project Explorer contains the library project and the previously created NUCLEO-
F401RE board project.
As shown in the Project Explorer view in Figure 50, the myLib project only contains an Inc and Src folder. Folder
Inc is empty by default. It is intended that header files are added to this folder. The Src folder contains three C
files. The <myLib.c> file is intended to be updated with the library functions that must be included in the library.
The name of the library file is the same as the project name. The two other C files are used by Newlib if needed
and can be updated if required.
The name of the function in file myLib.c can be renamed. More functions can be added into the myLib.c file.
Additional C files can also be added if a bigger library is created. It is good practice to create header files
containing prototypes of the library functions that are callable from the applications.
Note: The library project folder does not contain any linker script. When building the library project, gcc is used as
compiler for the C files and ar is used to create an archive file, which can be linked into and used by other
executable projects. It is not important to select the correct device for memory settings. The device name is used
to set the Cortex® core to the one intended to be used with the library. This makes the compiler generate correct
instructions.
It is possible to create new build configurations for a project at any time. Such new build configuration can be
based on an earlier available build configuration.
When building the project, the active build configuration is used and during build the files generated are written
into a folder with the same name as the active build configuration.
Note: The build configuration only handles the build settings. How to configure debug settings is described later in this
manual.
Figure 51. Set the active build configuration using the toolbar
Another way to change the active build configuration is to right-click on the project name in the Project Explorer
view, select [Build Configurations]>[Set Active], and select the preferred build configuration.
It is also possible to select the active build configurations using the menu [Project]>[Build Configurations]>[Set
Active] and select the chosen build configuration.
As shown in Figure 54, some buttons in the dialog are used to manage the configurations:
• [Set Active] is used to change and select another configuration to be active
• [New…] is used to create a new build configuration
• [Delete] is used to delete an existing build configuration
• [Rename…] is used to rename the build configuration
To create a new build configuration, press the [New…] button. This opens the Create New Configuration dialog. In
this dialog, a name and description is entered. The name must be a valid directory name since it is used as the
directory name when building the project with the new configuration.
As seen in Figure 55, the new build configuration is based on an existing build configuration. In the case
illustrated, the new configuration is based on the existing Debug configuration. Press [OK] when finished with the
settings.
The Manage Configurations dialog opens and the new debug configuration is displayed.
Change the active configuration to another configuration if needed and press [OK] to save and close the
configurations dialog when finished managing configurations.
Update the name, description, or both and press [OK] to rename the Debug2 configuration. In this case, press
[Cancel] and keep the name.
Select [C/C++ Build]>[Settings] in the Properties left pane. The right part is then filled with tabs Toolchain
Version, Tool Settings, Build Steps, Build Artifact, Binary Parsers, and Error Parsers. The first three tabs are the
most useful ones.
Note: Resize the dialog window or use the top-right arrow buttons if all tabs are not visible.
The Settings pane contains a [Configuration] selection to decide if new selections are used in the active
configuration only, in another configuration, in all configurations or in multiple configurations. Press [Manage
Configurations] to open the Manage Configurations dialog.
The Toolchain Version tab is used to change from the default “GNU Tools for STM32” to the “GNU ARM
Embedded” toolchain or when wanting to use a specific older toolchain version. It is recommended to use the
latest GNU Tools for STM32 included in STM32CubeIDE.
STM32CubeIDE is distributed with both the standard GNU ARM Embedded toolchain and an STM32 version with
patched enhancements. Information about patches made in GNU Tools for STM32 can be read in [EXT-12]. The
document can be opened from the Technical Documentation page in the Information Center.
Select [Fixed] to enable the selection of [Type] and [Version] for the toolchain.
The Tool Settings tab is further split into MCU Settings, MCU Post build outputs, MCU GCC Assembler, MCU
GCC Compiler and MCU GCC Linker.
MCU Settings displays the selected MCU and board for the project and proposes to select how to handle floating
point, instruction set and runtime library.
MCU Post build outputs proposes to convert the elf file to another file format, show build size information, and
generate list file. The output file can be converted to:
• Binary file
• Intel Hex file
• Motorola S-record file
• Motorola S-record symbols file
• Verilog file
The MCU GCC Assembler settings contains selections for the assembler. The main node presents all the
assembler command-line options that are currently enabled in the sub-node settings. The sub-nodes are used to
view the current settings or change any settings for the assembler.
The MCU GCC Compiler settings contains selections for the compiler. The main node presents all the compiler
command-line options that are currently enabled in the sub-node settings. The sub-nodes are used to view the
current settings or change any settings for the compiler.
The MCU GCC Linker settings contains selections for the linker. The main node presents all the linker command-
line options that are currently enabled in the sub-node settings. The sub-nodes are used to view the current
settings or change any settings for the linker.
The Build Steps settings contains fields used to provide pre-build and post-build steps, which run before and after
building the project. Edit the fields to run any pre-build or post-build step.
To start a build, select the corresponding project in the Project Explorer view and click on the [Build]
toolbar button.
The build can also be started from menu [Project]>[Build Project]. The [Project] menu contains also some other
usable build commands such as [Build All], [Build Project] or [Clean].
Another way to start a build is to right-click on the project in the Project Explorer view. This opens the context
menu with the [Build] command and some other build options.
During the build, the Console view lists the build process. At the end, when the elf file is created normally, it lists
size information.
The toolbar contains the [Build all] button, which is used to build the active build configuration for all open
projects in workspace.
It is also possible to use the menu [Project]>[Build All] to start a build of all projects.
2. Setup the path environment to include the path to the STM32CubeIDE installation folder, C:\ST\STM32Cub
eIDE_1.0.2\STM32CubeIDE with the command PATH=C:\ST
\STM32CubeIDE_1.0.2\STM32CubeIDE;%PATH%
The headless-build command file takes some parameters, such as –help to get some help. Figure 73
shows the result of command headless-build.bat –help in the command prompt.
When newlib-nano is used while floating-point numbers must be handled by scanf/printf, additional options
are required. The reason is that newlib-nano and newlib handle floating-point numbers differently. In
newlib-nano, formatted floating-point number inputs and outputs are implemented as weak symbols. Therefore,
the symbols must be pulled by specifying explicitly if %f is used with scanf/printf using the –u option:
• -u _scanf_float
• -u _printf_float
For example, to enable output float with printf, the command line is as follows:
$ arm-none-eabi-gcc --specs=nano.specs -u _printf_float $(OTHER_LINK_OPTIONS)
The options can be enabled using the [Use float …] checkboxes in [MCU Settings] in the Tool Settings tab.
/**
*****************************************************************************
** File : sysconf.c
*****************************************************************************
**/
/* Includes */
#include <errno.h>
#include <unistd.h>
/* Variables */
extern int errno;
Note: : If the “GNU ARM Embedded” toolchain is used, it does not call any sysconf() function implemented in the
application but always uses the default sysconf() function in newlib. Also, no call to sysconf() is made if
the “GNU Tools for STM32” toolchain is used with the reduced C newlib-nano library.
In this case, a new elf file is created but, if the warning is not detected, it will not work to debug the project
because the program does not contain the Reset_Handler function. It is possible to configure the linker to treat
warnings as errors by adding the --fatal-warnings option.
When the --fatal-warnings option is used, the linker does not generate the elf file but displays an error in the
console log:
c:\st\stm32cubeide_1.1.0.19w37\stm32cubeide\plugins
\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-
update.win32_1.0.0.201904181610\tools\arm-none-eabi\bin\ld.exe: warning: cannot
find entry symbol Reset_Handler; defaulting to 0000000008000000
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:40: NUCLEO-F401RE.elf] Error 1
"make -j4 all" terminated with exit code 2. Build might be incomplete.
11:26:30 Build Failed. 1 errors, 6 warnings. (took 7s.193ms)
Example:
/* Entry Point */
ENTRY(Reset_Handler)
The ENTRY information is used by GDB so that the program counter (PC) is set to the value of the ENTRY address
when a program is loaded. In the example, the program starts to execute from Reset_Handler when a step or
continue command is given to GDB after a load.
Note: The start of the program can be overridden if the GDB script contains a monitor reset command after the load
command. Then the code starts to run from reset.
Example:
Example:
The values defined here are normally used later in the linker script to make it possible for the linker to test if the
heap and stack fit in the memory. The linker can then issue an error if there is not enough memory available.
Example:
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
Example:
/* Sections */
SECTIONS
{
/* The startup code into "FLASH" Rom type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data into "FLASH" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
Example:
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
Example:
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
Example:
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left
*/
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
Example:
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
IP_CODE (rx) : ORIGIN = 0x8040000, LENGTH = 256K
}
Place the following code a bit further down in the script, between the .data { ... } and the .bss { ... }
section in the linker script file:
Example:
.ip_code :
{
*(.IP_Code*);
} > IP_CODE
This tells the linker to place all sections named .IP_Code* into the IP_CODE memory region, which is specified
to start at target memory address 0x804 0000.
In the C code, tell the compiler which functions must go to this section by adding
__attribute__((section(".IP_Code"))) before the function declaration.
Example:
The myIP_read() function is now placed in the IP_CODE memory region by the linker.
Define a new memory region in the MEMORY {} region in the linker script:
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
/* Memories definition */
MEMORY
{
RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 16K
RAM_CODE (xrw) : ORIGIN = 0x20004000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20008000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
Define an output section for the code in the linker script. This must be placed with a Load Memory Address (LMA)
belonging to the Flash memory, and a Virtual Memory Address (VMA) in RAM:
/* load code used by the startup code to initialize the ram code */
_siram_code = LOADADDR(.RAM_CODE);
.RAM_CODE :
{
. = ALIGN(4);
_sram_code = .; /* create a global symbol at ram_code start */
*(.RAM_Code) /* .RAM_Code sections */
*(.RAM_Code*) /* .RAM_Code* sections */
. = ALIGN(4);
_eram_code = .; /* define a global symbol at ram_code end */
} >RAM_CODE AT> FLASH
The RAM code area must be initialized and code copied from the Flash memory to the RAM code area. The
startup code can access the location information symbols _siram_code, _sram_code and _eram_code.
Add load address symbols for RAM_CODE into the startup file:
Add a piece of code into the startup code to copy the RAM code from the Flash memory (LMA) to the RAM
(VMA):
Reset_Handler:
ldr sp, =_estack /* set stack pointer */
RamCodeInit:
ldr r3, =_siram_code
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopRamCodeInit:
ldr r0, =_sram_code
ldr r3, =_eram_code
adds r2, r0, r1
cmp r2, r3
bcc RamCodeInit
CopyDataInit:
In the C code, instruct the compiler about which functions must go to this section by adding
__attribute__((section(".RAM_Code"))) before the functions declarations:
The first step is to create a new memory region in the linker script:
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
Place the following a bit further down in the script, between the .data { ... } and the .bss
{ ... } section
.flash_v :
{
*(.flash_v*);
} > FLASH_V
This instructs the linker to place all sections named flash_v* into the flash_v output section in the FLASH_V
memory region, which is specified to start at target memory address 0x807 F800.
A section can be called almost anything except some predefined names such as “data”.
Now, the variables that must be located into the FLASH_V memory must be defined with attributes in the C files:
When debugging this example and examining the memory, it can be observed that:
• Address 0x807 f800 contains VERSION_NUMBER
• Address 0x807 f804 contains CRC_NUMBER
• Address 0x807 f808 contains BUILD_ID
If the inserted data order in the Flash memory is important, map the order of the variables in the linker script. This
makes it possible to define the variables in any file. The linker outputs the variables in the defined order
independently on how the files are linked. As a result, if the CRC_NUMBER is calculated in some way after the
linker has built the file, the CRC_NUMBER can be inserted into the Flash memory file by another tool:
Decide the order in the linker script by adding the specially named sections in order
BUILD_ID, VERSION_NUMBER, CRC_NUMBER, and others(*).
.flash_v :
{
*(.flash_v.BUILD_ID*);
*(.flash_v.VERSION*);
*(.flash_v.CRC*);
*(.flash_v*);
} > FLASH_V
When debugging this example and examining the memory, it can be observed that:
• Address 0x807 f800 contains BUILD_ID
• Address 0x807 f804 contains VERSION_NUMBER
• Address 0x807 f808 contains CRC_NUMBER
Example:
File: readme.txt
Revision: Version 2
Product news: This release ...
One way to include this in the project is to make a reference in a C file to include it using the incbin directive
and the allocatable (“a”) option on the section:
asm(".section .binary_data,\"a\";"
".incbin \"../readme.txt\";"
);
The new section binary_data is then added into the linker script with instructions that the section must be put in
the Flash memory. The KEEP() keyword can be used to surround an input section so that the linker garbage
collector does not eliminate the section even if not called:
.binary_data :
{
_binary_data_start = .;
KEEP(*(.binary_data));
_binary_data_end = .;
} > FLASH
The binary data, in this case the readme file, can be observed in the Memory view when the project is debugged.
Example:
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K-4K
FLASH_D (rx) : ORIGIN = 0x807F000, LENGTH = 2K
FLASH_V (rx) : ORIGIN = 0x807F800, LENGTH = 2K
}
Add a section for FLASH_D using the NOLOAD directive. This can be done using the following code a bit further
down in the linker script:
.flash_d (NOLOAD) :
{
*(.flash_d*);
} > FLASH_D
Finally, data can be used somewhere in the program by adding a section attribute when declaring the variables
that must be located in the FLASH_D memory.
The source folders for the header files must also be added to the [Include paths] field:
1. Select [Project]>[Properties]>[Tool Settings]>[C Compiler]>[Directories]
2. press the [Add…] button and add the paths to the source folders for the header files in the library
Note: Libraries added by include paths are considered as static libraries because they are provided by external
parties. The header files are not rescanned as the content must not have changed for external header files. If
external libraries must be treated as normal source folders, the folders must also be added as source folders to
the project.
Refer to Section 2.5.9 Referring to projects for more information if a project is referring to another project, a
library or a normal project.
Note: When multiple projects are used as references, use the [Move Up] and [Move Down] buttons to setup the
priorities.
There are many advantages to set project references correctly:
• The projects involved are not rebuilt more than necessary.
• The indexer is able to find functions from the library and open them. To use this possibility, press the Ctrl key
and, in the editor, click the library function where it is used to open the library source file in the editor.
• It is possible to create the call hierarchy for the functions in the library. To find the call hierarchy, mark the
function name and press Ctrl+Alt+H to display the call hierarchy in the Call Hierarchyview.
If a library project is added as a reference, all the correct settings in the Paths and Symbols property page for the
library is set. The tool settings that depend on this property page are adjusted also.
This is the recommended method of adding libraries developed locally. For more information about adding
libraries, refer to Section 2.5.8 Include libraries.
Another way to have projects referring to each other is as follows:
1. Select [Project]>[Properties]
2. Select [Project References]
3. Select and mark the project for reference
With this method, however, it is not possible to refer to different build configurations and libraries are not set up
automatically.
• The UART output is maybe the most commonly used method, where the output from the embedded system
is sent for instance to a terminal using RS-232. It requires some CPU overhead and medium bandwidth.
• The Instrumentation Trace Macrocell (ITM) output is efficient but requires that the Arm® CoreSight™
debugger technology with Serial Wire Viewer (SWV) is supported by the device. This is normally the case for
Cortex®‑M3, Cortex®‑M4, and Cortex®‑M7 based devices. However, the SWV signals must be available and
connected to the board also. It requires low CPU overhead but limited bandwidth. ITM output is explained in
Section 4 Debug with Serial Wire Viewer tracing (SWV).
• The RTT solution is described by SEGGER on their website. RTT is a fast solution but requires SEGGER J-
LINK debug probe.
To enable I/O redirection with UART or ITM output, the file syscalls.c must be included and built into the
project. When printf() is used, it calls the _write() function, which is implemented in syscalls.c.
The syscalls.c file is normally created and included in the project when creating a new STM32CubeIDE
project. The _write() function in this file must be modified to enable printf() redirection by modifying the call
to __io_putchar(). The way to modify _write() depends on the hardware and library implementation.
The example below shows how to update syscalls.c so that printf ouput is redirected to ITM with an
STM32F4 Series device. This is done by adding some header files to access ITM_SendChar() and make a call
to ITM_SendChar().
#include "stm32f4xx.h"
#include "core_cm4.h"
It can be noticed that the _write function in syscalls.c contains a weak attribute. This means that the
_write function can be implemented in any C file used by the project.
For instance, the new _write() function can be added directly into main.c. Omit the weak attribute in that
case, as shown in the example below.
Reset_Handler:
ldr sp, =_estack /* set stack pointer */
/* The program code and other data into "ROM" Rom type memory */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
GOT_START = .;
*(.got*)
GOT_END = .;
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >ROM
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
Figure 88 illustrates an example where the download offset is 0x1000 and the symbol address is 0x800 1000. It
is possible to set the symbol address to 0x800 1000 in this case because the .isr_vector is added into
the .text section as described in Section 2.7.6 Interrupt vector table and symbols.
If instead the .isr_vector is located in another section outside .text, the start address of the .text section
must be used with the offset added. For instance, if the map file states that .text starts at
0x0000 0000 0800 0194, the symbol address in this case must be set to 0x800 1194.
Figure 88 shows that the breakpoint is set at main and that the program counter ($pc) is set to the
Reset_Handler symbol into [Run Commands]. This symbol contains the correct address to the
Reset_Handler because gdb uses the base symbol address 0x800 1000. If $pc is not setup during this
debug configuration, the [Resume] checkbox must be disabled to make the program stop after load. In this case,
the program counter must be set manually in the Registers view before starting the program.
Right-click the project in the Project Explorer view and select [Export…].
The Export dialog opens. Select [General]>[Archive File] and press [Next >].
The Export dialog is updated. Select the project to be exported. It is possible to exclude some project files from
the export. In the example in Figure 91, all project and library files are included. A file name must be entered into
the [To archive file] field, possibly browsing to a folder location for the file with the [Browse...] button. In the
example, the default options values are kept unchanged. Press [Finish] to export the project and create the zip
file.
Select [Import ac6 System Workbench for STM32 project] or [Import Atollic TrueSTUDIO project] depending
on the original tool used to create the project and press [Next >].
In this example, the ac6 project is copied into the STM32CubeIDE workspace, hence the [Directory…] button is
used and project STM32F401_Ac6 is selected. The import wizard detects that this is a System Workbench
project.
If the association is selected, double-clicking on a .project file in the personal computer file browser triggers
the project import by STM32CubeIDE into the current workspace. The project converter investigates the project,
which is imported directly if made for STM32CubeIDE. If the project comes from another tool, the project
converter tries to identify if it is a known project format and, in such case, converts the project to an
STM32CubeIDE project as described in Section 2.9.2 Importing System Workbench and TrueSTUDIO projects.
3 Debugging
3.1 Introduction to debugging
STM32CubeIDE includes a powerful graphical debugger based on the GDB command-line debugger. It also
bundles GDB servers for the ST-LINK and SEGGER J-Link JTAG probes.
The GDB server is a program that connects GDB on the PC to a target system. The STM32CubeIDE debug
session can autostart a local GDB server or connect to a remote GDB server.
The remote GDB server can be running on the same PC, or on a PC that is accessible via the network and
specified with Host name or IP address and a Port number. When connecting to a remote GDB server, this GDB
server must be started first before a debug session is started in STM32CubeIDE.
When autostart local debugging is selected, STM32CubeIDE automatically starts and stops the GDB server as
required during debugging, thus integrating the GDB server seamlessly.
Note: It is recommended to use compiler optimization level –O0 when building a project that must be debugged.
Debugging with optimization level –Og may work but higher optimization level is hard to debug because of
compiler code optimization.
Another way to create a new debug configuration is to select the project name in the Project Explorer view and
use the menu [Run]>[Debug As]>[STM32 Cortex-M C/C++ Application].
A third way to create a new debug configuration is to select project name in the Project Explorer view and press
[F11].
All three different ways open the Debug Configuration dialog.
Note: It is possible in the Main tab to define if a build must be made before the debug session is started.
The [Port number] edit field contains the default value used by the GDB server selected in field [Debug probe].
Field [Host name or IP address] must be set when [Connect to remote GDB server] is selected.
Field [Debug probe] selects the probe and GDB server to be used for debugging. When using an ST-LINK debug
probe, ST-LINK GDB server or OpenOCD can be used. When using a SEGGER J-LINK probe, use the
SEGGER J-LINK GDB server.
The [GDB Server Command Line options] selections are updated as a function of the [Debug probe] selected.
Detailed information about these settings are available in Section 3.4 Debug using different GDB servers and
sub-sections.
The [Initialization Commands] edit field can be updated with for instance GDB server monitor commands if there
is any special need to send some commands to the GDB server before load commands are sent. For instance,
when using ST-LINK GDB server a monitor flash mass_erase command can be entered here if a Flash
memory erase is needed before load.
The [Load Image and Symbols] list box must contain the file(s) to debug. This list is associated with the
following command buttons:
• [Add…]: Add new lines for files for download and/or load symbols
• [Edit…]: Edit the selected line
• [Remove]: Remove the selected line from the list
• [Move up]: Move the selected line upwards
• [Move down]: Move selected line downwards
The [Runtime Options] section contains checkboxes to set the start address and breakpoint, and enable
exception handling and resume.
The start address can be selected as:
• [Default start address]: $pc is set to the start address found in the last loaded .elf file
• [Set program counter (hex)]: $pc is set to the hex value specified in the edit field
• [Specify vector table (hex)]: $pc is updated with the value found in memory using specified address +
offset of 4. This is similar to how $pc is set by a reset using vector table in a Cortex®-M device
When the [Resume] selection is enabled, a continue command is issued to GDB after load to start the program.
Usually, in this case, the program breaks at main if a breakpoint at main is set. Otherwise, when the [Resume]
selection is disabled, the program stays at the ENTRY location specified in the linker script, normally the
Reset_Handler function. A step may be needed in this case to display the Reset_Handler function in the
editor.
When a line in the listbox is selected and [Edit…] is pressed, the following dialog appears for selecting if the file
must be downloaded and if symbols must be loaded.
The [Name] field on top of the right pane can be edited using a name for the debug configuration which reflects
the configuration. This name then appears in the navigation window under the [STM32 MCU Debugging] node to
the left when pressing [Apply].
The toolbar left of the navigation window contains icons to manage configurations, for instance to duplicate or
delete a selected configuration.
These icons are used for the following purpose, from left to right:
• Create new launch configuration
• New launch of configuration prototype
• Export launch configuration
• Duplicate currently selected launch configuration
• Delete selected launch configuration(s)
• Collapse all expanded launch configurations
• Filter launch configurations
Different command-line options are used when starting these GDB servers. Therefore the Debugger tab in the
Debug Configurations dialog displays different settings depending on the GDB server selected. This section
describes the individual settings for each server.
Select [SWD] or [JTAG] in [Interface] to define how the ST-LINK probe must connect with the microcontroller. The
SWD interface is usually the preferred choice. It must be selected if SWV is to be used.
When [ST-LINK S/N] is enabled, the serial number of the ST-LINK probe to be used must be entered in the edit/
list field. The [Scan] button can be used to scan and list all detected ST-LINK devices connected to the PC. After
a scan, the S/N of these ST-LINK devices are listed in the list box from which the desired ST-LINK can be
selected. When [Use specific ST-LINK S/N] is enabled, the ST-LINK GDB server is started and connects only to
the ST-LINK with the selected S/N.
The [Frequency (kHz)] selection defines the communication speed between the ST-LINK and STM32 device.
When [Auto] is selected, the maximum speed provided by ST-LINK is used. Reduce the frequency in case of
hardware limitations.
The [Access port] selection is used only when debugging a multi-core STM32 device. In such case, the ST-LINK
is connected to the device and the ST-LINK GDB server must be informed of the core to debug.
The [Reset behaviour] contains selections for [Type] and [Halt all cores].
The [Type]can be set as follows:
• [Connect under reset] (default)
• [Software system reset]
• [None] (for attach to a running target where the program is downloaded into the device already. There must
not be any file program command in the Startup tab.)
Note: The selected reset behaviour is overridden if the debug configuration includes Flash programming, in which
case the ST-LINK GDB server uses the STM32CubeProgrammer (STM32CubeProg) command-line program
STM32_Programmer_CLI to program the Flash memory. This program is always started by the ST-LINK GDB
server with mode=UR reset=hwRst so that a device reset is done when loading a new program, disregarding
the selection of the [None] option. This ensures that device programming is made correctly.
[Halt all cores] can be used only when debugging multi-core devices.
The [Serial Wire Viewer (SWV)] selections can only be used when the [SWD] interface is selected. When [SWV]
is enabled, it is required to configure the [Clock Settings]. The [Core Clock] must be set to the speed of the
device and [SWO clock] to the desired speed of the SWO clock. The SWV [Port number] must be set to the port
to be used for the communication of SWV data. The SWV port cannot be set equal to the GDB connection [Port
number].
Enabling [Wait for sync packet] ensures that a larger part of the received SWV data packages are correct
(complete), but may also lead to an increased number of packages being lost. This is especially true if the data
load (number of packages) is high.
[Device settings] contains selections for [Debug in low power modes] and [Suspend watchdog counters
while halted]. These can be defined as:
• [No configuration]
• [Enable]
• [Disable]
The [Misc] selections contains:
• [Verify flash download]
• [Enable live expressions] (To be able to use the Live Expressions view during debugging, the live
expression mechanism must be enabled during startup. It is enabled by default.)
• [Log to file] (Enable in case of debugging problems. It starts the ST-LINK GDB server with a higher log level
and saves the log into a file.)
• [External Loader] (Enable if loading must be made to non-internal STM32 Flash memory). A [Scan] button
is available to access STM32CubeProgrammer external Flash loader files.
When [External Loader] is enabled, there is also an [Initialize] selection. When it is enabled, the Init()
funtion in STM32CubeProgrammer is called after reset. It can be used to configure the device for external
memory access. Usually, initialization must be done by the debugged application.
• [Shared ST-LINK] (Shared ST-LINK must be enabled if other programs must be able to connect to the same
ST-LINK during a debug session.). Refer to Section 3.6.2 Shared ST-LINK for details.
A detailed description of the ST-LINK GDB server is available in the GDB server manual ([ST-07]), which is
available from the Information Center.
Note: STM32_Programmer_CLI is used by the ST-LINK GDB server to program the STM32 or external Flash
memory. In this case, such external Flash memory programming is automatically done using the external loader.
The [OpenOCD Command] edit field contains the openocd.exe file to be used when debugging. The [Browse]
button can be used to select another version of OpenOCD.
The [OpenOCD Options] edit field can be used to add additional command-line parameters to be used when
starting OpenOCD.
The [Configuration Script] selections can be [Automated Generation] or [User Defined]. When [Automated
Generation] is selected, an openocd.cfg file is created automatically based on the selections made in the
Debugger tab. When [User Defined] is selected, the file must be specified in the [Script File] edit field.
The [Interface]selection [Swd] or [Jtag] selects how the ST-LINK probe must connect with the microcontroller.
[Swd] is usually the preferred choice.
The Frequency selection configures the communication speed between the ST-LINK and STM32 device.
The [Reset Mode] selection contains:
• [Connect under reset]
• [Hardware reset]
• [Software system reset]
• [Core reset]
• [None]
[Enable debug in low power modes] enables debug also with the STM32 device in low-power mode.
[Stop watchdog counters when halt] stops the watchdog when the debug session halts the STM32 device.
Otherwise, a watchdog interrupt may be triggered.
[Shared ST-LINK] must be enabled if other programs have to connect to the same ST-LINK during a debug
session. Refer to Section 3.6.2 Shared ST-LINK for details.
The [Interface] selection [SWD] or [JTAG] selects how the SEGGER J-Link probe must connect with the
microcontroller. The [SWD] interface is usually the preferred choice; it is required if SWV is used.
The [Initial Speed] selection configures the communication speed used between SEGGER J-Link and the STM32
device.
When [Use specific J-Link S/N] is enabled, enter the S/N of the J-Link to be used when debugging in the edit/list
field. When [Use specific J-Link S/N] is enabled, the SEGGER J-Link GDB server is started and connects only
to the J-Link with the selected S/N.
The Device edit field is used if it contains an entry. This field can be used if there is a problem to start the
SEGGER J-Link GDB server with the default device name used in STM32CubeIDE. In such case, enter the
device name used by the SEGGER GDB server in the edit field.
The [Reset strategy] selection contains:
• [Type 0: Normal] - Default.
• [None] - Intended to be used for attaching to the running target. In this case, the program must already be
downloaded into the device. There must not be any file program command in the Startup tab.
The [JTAG Scan Chain] selections can be used only when the [JTAG] interface is selected.
The [Serial Wire Viewer (SWV)] selections can be used only when the [SWD] interface is selected. When [SWV]
is enabled, it is required to configure the [Core Clock]. The [Core Clock] must be set to the speed of the device
and [SWO clock] to either [Auto] or the desired SWO clock speed. Usually, [Auto] is the best choice. The
SWV [Port number] must be set to the port to be used for the communication of SWV data. The SWV port cannot
be set equal to the GDB connection [Port number].
The [Misc] selections contains:
• [Use J-Link script file]
• [Enable live expressions]
To be able to use the Live Expressions view during debug, the live expression mechanism must be enabled
during startup.
• [Verify flash download]
• [Select RTOS variant] list box can be used if [Thread-aware RTOS support] is used with [FreeRTOS] and
[embOS].
When [Thread-aware RTOS support] is used, update the Startup tab: disable [Resume] and [in Run
Commands], add thread 2 and continue. This forces a thread context switch before the continue
command is sent.
Note: A detailed description of SEGGER J-Link GDB server is available in the SEGGER J-Link manual, which can be
accessed from the “Information Center”.
Select in the left pane the debug configuration to use. Press the [Debug] button to start a debug session if all
debug configurations have been made. The project is built if file updates are made, but the building depends on
the debug configuration.
STM32CubeIDE launches the debugger and the following dialog is opened.
It is recommended to enable [Remember my decision] and press [Switch]. It opens the Debug perspective,
which provides a number of views and windows suitable for debugging.
The most important views opened by default in the Debug perspective are:
• The Debug view, which displays the program under debug. It also lists threads and offers the possibility to
navigate in the thread by selecting a line in threads.
• The Editor view, which displays the program file. It is possible to set break points and follow program
execution in the file. It is also possible to hoover the cursor over a variable to display its current value. The
features available during file edition are available also during debug, such as opening the declaration of a
function and others.
• The Variables view, which displays local variables automatically with their current value when the program is
not running.
• The Breakpoints view, which displays current breakpoints. It is possible to disable and enable breakpoints in
the list. The Breakpoints view also contains a toolbar, which, for instance, enables to remove breakpoints,
and skip breakpoints with one click on the [Skip All Breakpoints] icon.
• The Expressions view, which is used to add and view expressions. An expression may be a single global
variable, structure, or an expression calculating some variables. The values are only updated when the
program is stopped. It is possible to select a global variable in the Editor and drag it over to the Expressions
view instead of entering the variable name.
• The Registers view, which displays the debugged device current values. The values are only updated when
the program is stopped.
• The Live Expressions view, which displays expression values sampled and updated regularly during
program execution. The view allows the creation of mathematical expressions that are evaluated
automatically, such as (Index*4+Offset). The Live Expressions view update requires that live
expressions are enabled in the debug configuration. Refer to Section 3.6.1 Live Expressions view for
details.
The live expressions mechanism is not supported by OpenOCD.
• The SFRs view, which displays the Special Function Registers in the debugged device. Refer to
Section 5 Special Function Registers (SFRs) for details.
• The Console view, which displays different console outputs. By default, the console output from the GDB
server log is displayed. It is possible to change the console log by pressing the [Display Selected Console]
icon to the right of the Console view.
Other views are also useful during debug, among which:
• The Debugger Console view, which can be used if there is a need to manually enter GDB commands. The
easiest way to open the Debugger Console view is to use the [Quick Access] field and enter Debugger in
this field. It lists choices containing the Debugger Console view. Select it to open the view. GDB can be
entered in the Debugger Console view.
For instance, to display 16 words of memory from address 0x800 0000, enter the GDB command x /16
0x8000000.
x /16 0x8000000
0x8000000: 0x20018000 0x080008b1 0x080007e9 0x080007f7
0x8000010: 0x080007fd 0x08000803 0x08000809 0x00000000
0x8000020: 0x00000000 0x00000000 0x00000000 0x0800080f
0x8000030: 0x0800081d 0x00000000 0x0800082b 0x08000839
• The Memory and Memory Browser views, which can be used to display and update memory data.
• The Disassembly view, which is used to view and step in the assembly code.
• The SWV views. Refer to Section 4 Debug with Serial Wire Viewer tracing (SWV) for details.
• The Fault Analyzer view. Refer to Section 6 Fault Analyzer for details.
Alternatively, the Debug perspective toolbar has the following main debug control icons.
These icons are used for the following purpose, from left to right:
• Reset the device and restart the debug session
• Skip all breakpoints (Ctrl+Alt+B)
• Terminate and relaunch
• Resume (F8)
• Suspend
• Terminate (Ctrl+F2)
• Disconnect
• Step into (F5)
• Step over (F6)
• Step return (F7)
• Instruction stepping mode (assembler stepping)
Press [Terminate and relaunch] to terminate the current debug session, build a new program if the source code
is modified, and relaunch the debug session.
When pressing [Instruction stepping mode], the Disassembly view is opened and further stepping uses
assembler instruction stepping level. Press [Instruction stepping mode] again to toggle back to C/C++ level
stepping.
Select the [Toggle Breakpoint] menu command to set or remove a breakpoint at the corresponding source code
line.
Select [Breakpoint Properties...]. The following window opens. In the example illustrated below, i>20 is entered
as a condition.
With the condition above set, the program breaks each time the line is executed, then GDB tests the condition
and restarts execution if the variable i is not greater than 20. It takes some time for GDB to evaluate the
condition.
The conditions are written in C-style. It is therefore possible to write expressions such as i%2==0” to set more
complex conditions.
The debugger is now connected to the embedded target, which is automatically halted. At this point, different
status registers and variables can be investigated in the application. If the CPU has crashed, the Fault Analyzer
can be used to get a better understanding of the root causes.
3.5.7.1 Restart
During debugging, it is sometimes needed to restart the program to examine more carefully problems observed
during debug. In such case, restart the program using the [Reset the chip and restart debug session] toolbar
button or [Run]>[Restart] menu command. This resets the device, and starts the program if [Resume] is enabled
in the debug configuration.
Note: To make restart work, the interrupt vector must be configured and used with the hardware reset. This is usually
the case for STM32 programs located in the Flash memory. However, if the program is located elsewhere such
as in RAM, some manual handling may be needed to make the program start from the expected
Reset_Handler.
Figure 122 shows a setting where a new restart configuration is created, which contains an additional command
to set pc to 0x8000ca0.
When several reset configurations are defined, they appear in the toolbar dropdown menu in order of use. Select
the desired one to perform a reset.
3.5.7.3 Terminate
The most common way to stop a debug session is by clicking the [Terminate] toolbar button. It is also possible to
stop the debug session with the [Run]>[Terminate] menu. When the debug session is stopped, STM32CubeIDE
switches automatically to the C/C++ perspective.
The view can parse complicated data types and display complex data types like C-language structures. Only one
format of numbers is used at the same time. To change this format, use the dropdown menu.
Note: The Live Expressions view does not work with OpenOCD GDB server.
Note: To be able to use the Live Expressions view during debug, the live expression mechanism must be enabled
during startup. It is the case by default when ST-LINK GDB server or SEGGER J-Link is selected in the debug
configuration.
It is possible to run one instance of STM32CubeIDE containing one project for HW_A and one project for HW_B.
The default port to be used is:
• 61234 for ST-LINK GDB server
• 3333 for OpenOCD
• 2331 SEGGER J-Link
This is presented in the Debugger tab in the Debug Configurations dialog. The port number must be changed for
one of the projects to use another port, such as port 61244.
The debug configuration can use GDB connection selection [Autostart local GDB server]. Note that when
debugging multiple boards, two or more debug probes are connected to the PC; the correct serial number must
be selected for each debug configuration.
When the debug configurations has been configured for both projects so that each board is associated to a
specific probe, it is time to test and debug each board individually first. When it is confirmed that this is working,
the debug of both targets at the same time can be started as follow:
1. Start to debug HW_A.
2. The perspective switches automatically to the Debug perspective in STM32CubeIDE when a debug session
for HW_A is started.
3. Switch to the C/C++ perspective.
4. Select the project for HW_B and start debugging it. The Debug perspective opens again.
5. There are two application stacks/nodes in the Debug view, one for each project. When changing the
selected node in the Debug view, the related editor, variable view and others are updated to present
information associated to the selected project.
It is also possible to start the GDB servers manually: select [Connect to remote GDB server] in the debug
configuration. In such case, make sure that the GDB servers are started with parameters defining the individual
ports and serial numbers to be used, and that the corresponding port numbers are used in the Debug
Configurations dialog for each project.
Below is an example using SEGGER J-Link GDB server connecting to SEGGER J-Link, with port=2341 and S/
N=123456789:
Information on command-line parameters to be used when starting the GDB servers manually are provided in the
GDB server manuals available from the Information Center.
Another way to create a run configuration is to select the project name in the Project Explorer view and use the
menu [Run]>[Run As]>[STM32 Cortex-M C/C++ Application].
Use for instance menu [Run]>[Debug Configurations…] and select the STM32 Cortex®-M debug configuration
to update.
Note: The [Configure Trace] toolbar button is available in all SWV views.
Three examples are provided below for illustrating SWV trace configuration:
• Example 1: To trace the value of a global variable, enable [Comparator] and enter the name of the variable
or the memory address to be traced.
The value of the traced variable is displayed both in the Data Trace and Data Trace Timeline Graph views.
• Example 2: To profile program execution, enable [PC sampling]. In the beginning, a high value for the
[Cycles/sample] is recommended.
The result from the PC sampling is then displayed in the SWV Statistical Profilingview.
• Example 3: To trace the exceptions occurring during program execution, enable [Trace Event EXETRC:
Trace Exceptions].
Information about the exceptions is then displayed in the SWV Exception Trace Log and SWV Exception
Timeline Graph views.
Note: The tracing cannot be configured while the target is running. Pause the debugging before attempting to send a
new configuration to the board. Each new or updated configuration must be sent to the board to take effect. The
configuration is sent to the board when the [Start/Stop Trace] button is pressed.
Note: More than one SWV view may be open at the same time for the simultaneous tracking of various events.
The SWV views toolbars contain these usual control icons.
These icons are used for the following purpose, from left to right:
• Configure trace
• Start/Stop trace
• Remove all collected SWV data
• Scroll lock
• Minimize
• Maximize
The SWV graph views toolbars contain these extra control icons.
These icons are used for the following purpose, from left to right:
• Save graph as image
• Switch between seconds and cycle scale
• Adjust the Y-axis to best fit
• Zoom in
• Zoom out
The column information in the SWV Trace Log view is described in Table 2.
Name Description
Index The package ID. Shared with the other SWV packages.
Type The type of package (example PC sample, data PC value (comp 1), exceptions, overflow).
Data The package data information.
Cycles The timestamp of the package in cycles.
Time(s) The timestamp of the package in seconds.
Extra info Optional extra package information.
Data tab
The first tab is similar to the SWV Trace Log view, but is restricted to exception events. It also provides additional
information about the type of event. The data can be copied and pasted into other applications. Each row is linked
to the code for the corresponding exception handler. Double-click on the event to open the corresponding
interrupt hander source code in the Editor view.
Note: Enable [Trace Event EXETRC: Trace Exceptions] in the Serial Wire Viewer settings dialog to trace exceptions
during program execution. Enable [Timestamps] to log cycle and time for each interrupt package.
The column information in the SWV Exception Trace Log – Data tab is described in Table 3.
Name Description
Index The exception package ID. Shared with the other SWV packages.
Type Each exception generates three packages: Exception entry, Exception exit and then an Exception return package.
Name The name of the exception. Also the exception or interrupt number.
Peripheral The peripheral for the exception.
The name of the interrupt handler function for this interrupt. Updated when debug is paused. Is cached during the
Function
whole debug session. By double clicking the function, the editor will open that function in the source code.
Cycles The timestamp for the exception in cycles.
Time(s) The timestamp for the exception in seconds.
Extra info Optional extra information about that package.
Statistics tab
The second tab displays statistical information about exception events. This information may be of great value
when optimizing the code. Hypertext links to exception handler source code in the editor is included.
The column information in the SWV Exception Trace Log – Statistics tab is described in Table 4.
Name Description
Exception The name of the exception provided by the manufacturer. Also the exception or interrupt number.
The name of the interrupt handler for this interrupt. Updated when debug is paused. Is cached during the
Handler whole debug session.
By double clicking the handler, the editor will open that function in the source code.
% of This exception type’s share, in percentage, of all exceptions.
Number of The total number of entry packets received by SWV of this exception type.
% of exception time How big part of the execution time for all exceptions that this exception type have.
How big part of the total execution time for this debug session that this exception type have. All the
% of debug time
timers are restarted when the Empty SWV-Data button is pressed.
Total runtime The total execution time in cycles for this exception type.
Avg runtime The average execution time in cycles for this exception type.
Fastest The execution time in cycles for the fastest exception of this exception type.
Slowest The execution time in cycles for the slowest exception of this exception type.
First The first encounter of an entry event for this exception type in cycles.
First(s) The first encounter of an entry event for this exception type in seconds.
Latest The latest encounter of an entry event for this exception type in cycles.
Latest(s) The latest encounter of an entry event for this exception type in seconds.
Note: Each interrupt is displayed with 3 packages (Exception entry, Exception exit and Exception return).
When running the program in debugger with SWV trace enabled the SWV Data Trace view displays this
information when [Comparator 0] with pos1 data is selected in the [Watch] list.
Name Description
The SWV Data Trace Timeline Graph has the following features:
• The graph can be saved as a JPEG image file by clicking on the camera toolbar button.
• The graph shows the time in seconds by default but can be changed to cycles by clicking on the clock
toolbar button.
• Y-axis can be adjusted to best fit by clicking on the y-axis toolbar button.
• Zoom in and out by clicking on the [+] and [–] toolbar buttons.
• The zoom range is limited while debug is running. Zoom details are available when debug is paused.
The packages from the ITM ports are displayed in the SWV ITM Data Console view. The CMSIS function
ITM_SendChar() can be used by the application to send characters to the port 0, and the printf() function
can be redirected to use the ITM_SendChar() function.
The following describes how to setup printf redirection over ITM:
1. Configure first file syscalls.c. Usually, the syscalls.c file is located in the same source folder as main
.c.
If no syscalls.c file is available in the project, it can be copied from another STM32CubeIDE project. One
way to get the file is to create a new STM32 empty project for the device. In the Src folder, this project
contains a syscall.c file. Copy this file to a source folder in the project where it is needed.
2. Inside the syscalls.c file, replace the _write() function with code calling ITM_SendChar() instead of
__io_putchar()
3. Locate the core_cmX.h file, which contains the function ITM_SendChar(). The core_cmX.h file is
included by the Device Peripheral Access Layer header file (for instance stm32f4xx.h, which in turn must
be included in the syscalls.c file).
#include "stm32f4xx.h"
Use the Include Browser view to find the Device Peripheral Access Layer header file. Drop the core file in
the Include Browser view, and check which files are including the core_cmX.h file.
4. Test by adding include stdio.h and call to printf() into the application. Make sure that printf() is not
called too often.
#include <stdio.h>
5. Start a debug session and enable [ITM port 0] in the SWV ITM Data Console view.
6. Open the SWV ITM Data Console view and start tracing using the red [Start/Stop Trace] button on the
toolbar in this view.
7. Start the program. Print commands are logged to the Port 0 tab in the view.
8. It is possible to open new port x tabs (x from 1 to 31) by pressing the green [+] button on the toolbar. This
opens the Add Port dialog. In the dialog select the [ITM Port number] to be opened to display it as a tab in
the SWV ITM Data Consoleview.
Note: Study the ITM_SendChar() function to learn how to write a function that transmits characters to another ITM
port channel.
1. Configure SWV to send Program Counter samples, as shown in Figure 150. Enable [PC Sampling] and
[Timestamps].
With the given [Core Clock] cycle intervals, SWV reports the Program Counter values to STM32CubeIDE.
Set the [PC Sampling] to a high [Cycle/sample] value to avoid interface overflow.
2. Open the SWV Statistical Profiling view by selecting [Window]>[Show View]>[SWV Statistical Profiling].
The view is empty since no data is collected yet.
3. Press the red [Start/Stop Trace] button to send the configuration to the board.
4. Resume program debugging. STM32CubeIDE starts collecting statistics about function usage via SWV
when the code is executing in the target system.
5. Suspend (Pause) the debugging. The view displays the collected data. The longer the debugging session,
the more statistics are collected.
Note: A double-click on a function line in the SWV Statistical Profiling view opens the file containing the function in the
editor.
The column information in the SWV Statistical Profiling is described in Table 6.
Name Description
The name of the function which is calculated by comparing address information in SWV packages with the
Function
program elf file symbol information.
Select the [Windows]>[Preferences] menu. In the Preferences dialog, select [STM32Cube]>[Serial Wire
Viewer]. Update [Trace buffer size] if needed.
The buffer is stored in the heap. The allocated heap is displayed by first selecting the [Windows]>[Preferences]
menu. In the Preferences dialog, select [General]. Enable [Show heap status] to display the current heap and
allocated memory in the bottom right corner of STM32CubeIDE. There is an upper limit to the amount of memory
STM32CubeIDE can allocate. This limit can be increased to store more information during a debug session.
To update the memory limit, proceed as follows:
1. Navigate to the STM32CubeIDE installation directory. Open the folder in which the IDE is stored.
2. Edit the stm32cubeide.ini file and change the –Xmx1024m parameter to the desired size in megabytes.
3. Save the file and restart STM32CubeIDE.
• The target [Core Clock] is incorrectly set. It is very important to select the right [Core Clock].
If the frequency of the target [Core Clock] is unknown, it can sometimes be found by setting a breakpoint in
a program loop and open the Expressions view, when the breakpoint is hit.
Click on [Add new expression], type SystemCoreClock and press [Enter]. This is a global variable that,
according to the CMSIS standard, must be set by the software to the correct speed of the [Core Clock].
In CMSIS standard libraries, a function called SystemCoreClockUpdate() can be included in main() to
set the SystemCoreClock variable. Use the Variable view to track it.
Note: If the software dynamically changes the CPU clock speed during runtime, this might cause SWV to stop as the
clocking suddenly becomes wrong during execution.
To make sure that all data is received, apply the following steps:
1. Open the SWV configuration. Disable all tracing except [PC Sampling] and [Timestamps]. Set the
[Resolution] to the highest possible value.
2. Save, and open the SWV Trace Log view.
3. Start tracing.
4. Make sure that incoming packages can all be seen in the SWV Trace Log view.
Figure 153. Open the SFRs view using the [Quick Access] field
The top of the SFRs view contains a search field to filter visible nodes, such as peripherals, registers, bit fields.
Upon text entry in the search field, only the nodes containing this text are displayed.
The information at the bottom of the SFRs view displays detailed information about the selected line. For registers
and bit fields, this includes [Access permission]and [Read action] information.
The [Access permission] contains the following details:
• [RO](read-only)
• [WO](write-only)
• [RW](read-write)
• [W1](writeOnce)
• [RW1](read-writeOnce)
The Read action contains information only if there is a read action when reading the register or bit field:
• [clear]
• [set]
• [modify]
• [modifyExternal]
The toolbar buttons are located at the top-right corner of the SFRsview.
The [RD] button in the toolbar is used to force a read of the selected register. It causes a read of the register even
if the register, or some of the bit fields in the register, contains a ReadAction attribute set in the SVD file.
When the register is read by pressing the [RD] button, all the other registers visible in the view are read again also
to reflect all register updates.
The program must be stopped to read registers.
The base format buttons ([X16], [X10], [X2]) are used to change the registers display base.
The [Configure SVD settings] button opens the CMSIS-SVD Settings Properties Panelfor the current project.
The [Pin] button ("don’t follow" selection) can be used to keep focus on the current displayed SVD file even if the
Project Explorer view is switched to another project.
All SVD files must comply with the syntax outlined in the CMSIS-SVD specification available on Arm® website. If
these requirements are not met, the SFRs view is likely not to show any register information.
The [Device file] field is used for the System View Description (SVD) file. This file must describe the whole
device. Other views may fetch information from the SVD file pointed out by this field, therefore it is recommended
to use this field only for SVD files containing full STM32 device description. Updated SVD files can be obtained
from STMicroelectronics (refer to the HW Model, CAD Libraries and SVD columns in the device description
section on the STMicroelectronics website at www.st.com.
The [Custom file] field can be used to define special function registers related to custom hardware, in order to
simplify the viewing of different register states. Another possible use case is to create an SFR favourites’ file,
containing a subset of the content in the [Device file]. This subset may be for instance composed of frequently
checked registers. If a [Custom file] is pointed out, a new top-node in the SFRs view is created, which contains
the [Custom file] related register information.
Both fields may be changed by the user and both fields may be used at the same time.
Note: • It is possible to write new values in the value columns of registers and bit fields when these have write
access permission.
• It is possible to use the SFRs view while the target is running when using the ST-LINK GDB server.
However the [Live expression] option in the debug configuration must be enabled in this case.
• It is not possible to use SFRs view while the target is running when using OpenOCD or SEGGER J-Link.
• The SFRs view can also be useful in the C/C++ Editing perspective, however then only the names and
addresses of the registers are displayed.
6 Fault Analyzer
6.1 Introduction to the Fault Analyzer
The STM32CubeIDE Fault Analyzer feature interprets information extracted from the Cortex®-M nested vector
interrupt controller (NVIC) in order to identify the reasons that caused a fault. This information is visualized in the
Fault Analyzer view. It helps to identify and resolve hard-to-find system faults that occur when the CPU is driven
into a fault condition by the application software.
Among such conditions are:
• Accessing invalid memory locations
• Accessing memory locations on misaligned boundaries
• Executing undefined instruction
• Division by zero
Upon fault occurrence, the code line where the fault occurred is displayed in the debugger. The view displays the
reasons for the error condition. Faults are coarsely categorized into hard, bus, usage and memory faults.
• Hard and bus faults occur when an invalid access attempt is made across the bus, either of a peripheral
register or a memory location
• Usage faults are the result of illegal instructions or other program errors
• Memory faults include attempts of access to an illegal location or violations of rules maintained by the
memory protection unit (MPU)
To further assist fault analysis, an exception stack frame visualization option provides a snapshot of the MCU
register values at the time of the crash. Isolating the fault to an individual instruction allows to reconstruct the
MCU condition at the time the faulty instruction was executed.
In the Debugger perspective, the Fault Analyzer view is opened from the menu. Select the menu command
[Window]>[Show View]>[Fault Analyzer] or use the [Quick Access] field, search for “Fault Analyzer” and select
it from the views.
• The first toolbar button (left) opens the Editor on the fault location return address by using the information in
the PC and LR registers in the stack and the symbol information in the debugged elf file.
• The second toolbar button (middle) opens the Disassembly view on the fault location return address by
using the information in PC and LR registers in the stack and the symbol information in the debugged elf
file.
• The third toolbar button (right) selects if the PC or LR register is used when opening the Editor or
Disassembly view on error location.
Figure 160 and Figure 161 show the Editor and Disassembly views opened using the toolbar buttons to find the
fault location in the example.
Note: The Fault Analyzer can be used on all STM32 projects. It requires no special code and no special build
configuration. All data are collected for the Cortex®-M registers. The symbol information is read from the
debugged elf file.
7 Build Analyzer
7.1 Introduction to the Build Analyzer
The STM32CubeIDE Build Analyzer feature interprets program information from the elf file in detail and presents
the information in a view. If a map file, with similar name, is found in the same folder as the elf file the
information from the map file is also used and even more information can be presented.
The Build Analyzer view is useful to optimize or simplify a program. The view contains two tabs, the Memory
Regions and Memory Details tabs:
• The Memory Regions tab is populated with data if the elf file contains a corresponding map file. When the
map file is available, this tab can be seen as a brief summary of the memory regions with information about
the region name, start address and size. The size information also comprises the total size, free and used
part of the region, and usage percentage.
• The Memory Details tab contains detailed program information based on the elf file. The different section
names are presented with address and size information. Each section can be expanded and collapsed.
When a section is expanded, functions/data in this section is listed. Each presented function/data contains
address and size information.
Name Description
Start address The start address of the region, defined in the linker script.
End address End address of the region.
Size The total size of memory region.
Free The free size in the memory region.
Used The used size in the memory region.
The percentage of used size relative to the total memory region size. See Table 8 for the bar icon color
Usage %
information.
The Usage (%) column contains a bar icon corresponding to the percentage value. The bar has different colors
depending on the percentage of used memory.
Name Description
Name of memory region, section, function, and data. A green icon is used to mark functions while the
Name
blue icon is used for data variables.
Run Address (VMA) The Virtual Memory Address contains the address used when the program is running.
The Load Memory Address is the address used for load, for instance for the initialization values of
Load Address (LMA)
global variables.
Size Used size (total size for Memory Regions).
Note: The memory region name is only displayed if a corresponding map file is found.
This example shows how to write the Reset_Handler in an assembler startup file to include the constants
_sidata, _sdata, _edata, _sbss, and _ebss in the Reset_Handler size information in the elf file. If these
constants are defined out of the Reset_Handler section definition, their sizes are not included in the calculated
size of the Reset_Handler. To include them in the size of the Reset_Handler, these definitions must be
placed inside the Reset_Handler section as presented in the code example below.
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
ldr sp, =_estack /* set stack pointer */
CopyDataInit:
ldr r3, =_sidata
7.2.2.2 Sorting
The sort order of a Memory Details tab column can be changed by clicking on the column name.
The Ctrl+C copy of the lines selected in Figure 170 provides the Ctrl+V results below:
"sound4";"0x0807afc8";"0x0807afc8";"8500"
"sound3";"0x08079c40";"0x08079c40";"5000"
"sound2";"0x08074e20";"0x08074e20";"20000"
"sound1";"0x08070000";"0x08070000";"20000"
"image3";"0x08064c08";"0x08064c08";"35000"
"image2";"0x080561a8";"0x080561a8";"60000"
"image1";"0x08050000";"0x08050000";"25000"
"icons";"0x08040000";"0x08040000";"20000"
The Call Graph tab contains an expandable list with functions included in the program. Lines representing
functions calling other functions can be expanded to see the call hierarchy.
The Static Stack Analyzer view is populated when a built project is selected in the Project Explorer. The project
must be built with option [Generate per function stack usage information] enabled, otherwise the view cannot
present any stack information.
How to setup the compiler to generate stack usage information is explained in the next section.
Name Description
The List tab sort order can be changed by clicking on a column name.
Note: By double-clicking on a line that displays the file location and line number in the List tab, the function is opened
in the Editor view.
The column information in the Call Graph tab is described in Table 11.
Name Description
The Call Graph tab sort order can be changed by clicking on a column name.
By double-clicking on a line that displays the file location and line number in the tab, the function is opened in the
Editor view.
Note: The main function is usually called by the Reset_Handler and can in those cases be seen when expanding
the Reset_Handler node.
If unused functions are listed in the tab, check if linker option [dead code removal] is enabled to remove unused
code from the program. Read more on this in Section 2.5.2 Discard unused sections.
The small icon left of the function name in column Function column indicates the following:
• Green dot: the function uses STATIC stack allocation (fixed stack).
• Blue square: the function uses DYNAMIC stack allocation (run-time dependent).
• 010 icon: used if the stack information is not known. This can be the case for library functions or assembler
functions.
• Three arrows in a circle: used in the Call Graph tab when the function makes recursive calls.
Figure 178 displays the List tab where the [Filter] field is used to seek functions containing the “read” string in
their name.
Figure 179 shows a use example of the [Search...] field in the Call Graph tab for filtering functions with name
matching the “read” string.
The Ctrl+C copy of the lines selected in Figure 180 provides the Ctrl+V results below:
"SystemClock_Config";"88";"STATIC";"main.c:410";""
"main";"40";"STATIC";"main.c:183";""
"HAL_GPIO_Init";"40";"STATIC";"stm32f4xx_hal_gpio.c:171";""
Update details is displayed. Review and confirm the update. Press Next.
Review Licenses details are displayed. Review the licenses, select [I accept the terms of the license
agreements] and press [Finish] to install the update.
The progress bar displayed at the bottom of the STM32CubeIDE window shows the installation completion rate.
Restart STM32CubeIDE when the update is finished.
The Eclipse Marketplace dialog opens. Search for the plugin or use the tabs (Recent, Popular, Favorites) to find
the software wanted and install it.
The Install dialog opens. Enter the plugin update site URL. If the URL is not known, use [--All Available Sites--].
If no direct Internet connection is available, the plugin can be downloaded into an archive on a computer with an
Internet connection, and then manually transferred to the computer with an STM32CubeIDE installation. Add the
archived file by clicking on the [Add…] button and then select [Archive and select the downloaded file].
Select the appropriate plugins and install the software. Restart STM32CubeIDE when installation is finished.
Press the [Installation Details] button to open the STM32CubeIDE Installation Details dialog.
Select the plugin to uninstall in the Installed Software tab and press [Uninstall…]. Restart STM32CubeIDE when
the uninstallation is finished.
10 References
Revision history
Contents
1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
1.1 Product information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.4 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.5 Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.2 Editors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.3 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
3.1 Introduction to debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.2 Debug configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.2.1 Debug configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
List of tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
List of figures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
List of tables
Table 1. Key shortcut examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 2. SWV Trace Log columns details. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Table 3. SWV Exception Trace Log – Data columns details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Table 4. SWV Exception Trace Log – Statistics columns details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Table 5. SWV Data Trace columns details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Table 6. SWV Statistical Profiling columns details. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Table 7. Memory Regions tab information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Table 8. Memory Regions usage color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Table 9. Memory Details tab information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Table 10. Static Stack Analyzer List tab details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Table 11. Static Stack Analyzer Call Graph tab details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Table 12. STMicroelectronics reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Table 13. External reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Table 14. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
List of figures
Figure 1. STM32CubeIDE key features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Figure 2. STM32CubeIDE window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 3. STM32CubeIDE Launcher – Workspace selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 4. Help menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 5. Help - Information Center menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 6. Information Center – Home page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 7. Information Center – Technical documentation page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 8. Reset perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 9. Toolbar buttons for switching perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 10. C/C++ perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 11. Debug perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 12. Device Configuration Tool perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 13. Remote System Explorer perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 14. New connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 15. [Show View] menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 16. Show View dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 17. Quick access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 18. Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 19. Preferences - Text Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 20. Preferences - Formatter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 21. Preferences - Code style edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 22. Preferences - Network Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Figure 23. Preferences - Workspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Figure 24. Display of Java heap space status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Figure 25. Workspace unavailable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Figure 26. Shortcut keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Figure 27. Shortcut preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Figure 28. Editor with text zoomed in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Figure 29. Editor folding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Figure 30. Editor block selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Figure 31. Editor text block addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Figure 32. Editor column block selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Figure 33. Editor column block paste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Figure 34. Editor - Compare files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Figure 35. Editor - File differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Figure 36. Local history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Figure 37. Show local history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Figure 38. File history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Figure 39. Compare current history with local history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Figure 40. Compare local file differences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Figure 41. STM32 target selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Figure 42. STM32 board selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Figure 43. Project setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Figure 44. Firmware library package setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Figure 45. Initialization of all peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Figure 46. STM32CubeMX perspective opening. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Figure 47. Project creation started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Figure 48. STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Figure 49. STM32 static library project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Figure 50. STM32 library and board project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Figure 51. Set the active build configuration using the toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Figure 52. Set active build configuration using right-click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45