0% found this document useful (0 votes)
48 views28 pages

05 - SW4STM32 - Tips and Tricks

The document discusses configuring the SW4STM32 toolchain environment. It provides steps to: 1. Adjust settings like C dialect, parallel build options, and indexer configuration. 2. Learn how to run external applications, set autosave options, and use task tags. 3. Configure features like autocompletion, compiler optimization levels, and managing output file types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views28 pages

05 - SW4STM32 - Tips and Tricks

The document discusses configuring the SW4STM32 toolchain environment. It provides steps to: 1. Adjust settings like C dialect, parallel build options, and indexer configuration. 2. Learn how to run external applications, set autosave options, and use task tags. 3. Configure features like autocompletion, compiler optimization levels, and managing output file types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

STM32 Ecosystem workshop

T.O.M.A.S Team
2

• Now it is a right time for some activities again 


• Our goal is to adjust the configuration of SW4STM32 environment.
• You can follow next steps directly on your “L4_Blinky” project.
Our goals for this session 3

Get knowledge about some features of SW4STM32 toolchain:


Selection C dialect and parallel build options
Configuration of the indexer
How to run an external application
How to set autosave before build option
How to use “come back later” messages within the code
How to use and configure autocompleting option
Managing different output files (.hex, .bin files generation)
How to run debug session and handling most common issues related to this operation
Some tips in SW4STM32
Code generation strategies for SW4STM32
generation of project files under root or in dedicated folder 5

• There are two ways how to generate project files for SW4STM32 from STM32CubeMX application:
1. Generate the toolchain project files in STM32CubeMX user project root folder (Generate under root
checkbox should be selected) -> we will use this option during this session
2. Generate the toolchain project files in dedicated toolchain folder (Generate under root checkbox should
be not selected)

• STM32CubeMX project generation under the root folder allows to:


• Optional copy of the project into the Eclipse workspace when importing a project.
• Use of source control systems such as GIT or SVN from the Eclipse workspace.

• Warning: Choosing to copy the project into workspace will prevent any further synchronization
between changes done in Eclipse and changes done in STM32CubeMX as there will be 2 different
copies of the project.
Useful project settings in SW4STM32
configuring C dialect and parallel build 6
Project->Properties
C/C++ Build->Settings->Tools Settings tab  MCU GCC Compiler->Dialect
1. Configure C standard
to C99 to avoid
possible compilation
errors
1

C/C++ Build->Behavior tab

2. Check Enable parallel


build to make use of
your machine potential 2
and to shorten
compilation time
NOTE: These steps were already mentioned in a previous part, here duplicated to keep narration consistency.
Indexer in SW4STM32 7

• The indexer uses the parser to create a database of project files that provides the
basis for search, navigation features and parts of content assist (Ctrl+Space
feature).
• The indexer runs on a background and reacts to resource change like:
 Project creation/deletion
 Source files creation/deletion
 File imports
 Source file content changes
• It is possible to customize the behavior of the indexer (or turn it off) for each project
within the workspace separately.
Compiler optimization levels 8

• Optimization levels are accessible within project properties (right click the project name)
• Within project Properties select:
C/C++ Build -> Settings ->Tool Settings->MCU GCC Compiler->Optimization From
• From drop-down menu select required optimization level
• Click Apply->OK buttons when completed
Issue with missing _IRQn 9

• During code generation with “Generate


Under Root” option selected, all
header files for a complete family are
added to the project causing an error
with unresolved parameter (too many
sources with the same definition)  Project Properties->C/C++ General->Indexer
this is necessary to change indexer
settings.
check this option

uncheck this option


Run an external application 10

Example: How to erase Flash memory using command line STLink Utility application from SW4STM32
1

2
1. Select External Tools Configuration from Run
configuration option 3
2. Double click Program to create new configuration
3. Browse ST-LINK_CLI.exe within File System
4
4. Add –c SWD UR –ME arguments
• -c SWD  use SWD to connect to the target
• UR  connect under reset
• -ME  mass erase of the FLASH memory

5. Run the program


(ST-LINK_CLI.exe –c SWD UR –ME will be executed) 5
Useful configuration
11
auto save on build and launch
Editor settings are available in WindowsPreferences menu

General->Workspace

Run/Debug->Launching
Adding files to the project 12

1. Right-click the files folder within the project to select IMPORT


2. Select General->File System
3. Browse for files to be imported (sine.h in below example)
1 4. Select import options (click on Advanced button) and click Finish button
5. File will pop-up in selected folder
File copied into the folder

3
5
File linked to the folder
4
File will be imported
as link if selected (by
default not selected)
2
Importing projects into workspace
import from archive file
1. Select File->Import from SW4STM32 main menu

2. Select “Existing Projects…” from Import->General window


3 Select “Select archive file”
and browse proper .zip /.tar
file from Import Project
window

5 Projects will be added


4 into current workspace.
Select project from the
Projects lists and press Finish
Project refresh after configuration change 14

• After performing any change to


optimization/debug level, we strongly
recommend to refresh project
configuration (F5) and to build it again
Enable float support in printf 15

• By default “nano” version of


C/C++ Build -> Settings -> MCU GCC Linker -> Miscellaneous
the stdio (standard input-
output library) is selected.
Remove this option
• This helps to keep code size
low but does not allow use of
float numbers in printf.

• In order to change it, we have


to disable “nano” library option
within project settings.
“Come Back Later” – Tasks 16

• Task configuration is done in Task Tags field within WindowPreferencesC/C++


• This is possible to add new and modify existing keywords that will be recognized after saving
source file as Tasks marking (even being inside comment field - example (1) below).
• Double-clicking the particular task moves to the place of the code where the task is placed (2)

1
2
Auto completion of the generic C code 17

• Basic configuration is done within:


• WindowPreferencesC/C++EditorContent Assist
• Templates configuration is done within
• WindowPreferencesC/C++EditorTemplates
• Insert by Ctrl+Space during typing, i.e.
for <Ctrl+Space>
then select required template to be used

for (int var = 0; var < max; ++var) {

}
Managing output files
18
useful modifications in post-build steps
• Open properties window for the project (ProjectProperties)
• Select C/C++BuildSettingsBuild Steps
• Modify Command field using below information
(this is possible to add new commands after a && string)

• To generate a binary (.bin) output file use:

arm-none-eabi-objcopy –O binary “out_file.elf” “out_file.bin”

• To generate an INTEL hex (.hex) output file use:

arm-none-eabi-objcopy –O ihex “out_file.elf” “out_file.hex”

• To print information about code size after compilation use:

arm-none-eabi-size “out_file”
Restoring default configuration
19
resetting the perspective
• Perspective is a configuration of the windows and toolbars within current SW4STM32 workspace.
• There are different perspectives for editing, debugging, file sharing etc.
• Perspectives can by modified by the user (WindowPerspective)
• There is a function available to reset the perspective to its default view.
• This option is available in WindowPerspectiveReset Perspective
Example:

After (project explorer and output


Before (no project explorer nor console windows are restored)
output console windows) Select WindowPerspectiveReset Perspective
Issues with entering debug session 21

There are few typical root causes of the issues when entering debug mode:
• Wrong version of the HW debugger selected: i.e. STLinkV2-1 instead of STLinkV2 or vice versa
• Already running debug session(s)
• STLink owned by other debug/programming application (i.e. STMStudio, STLink Utility)
• A “ghost” GDB process existing in PC memory and locking an access to the debug port
• Wrong connection type selected. Debugged MCU requires connect under reset option – it can be
corrected within .cfg configuration file or by erasing the memory by STLink Utility application

Some PC oriented issues can be verified by connection trial using STLink Utility. Those are typically:
• Bad quality USB cable (especially when we use board with high current consumption)
• An issue with USB port (some USB3.0 ports show problems with correct operation with STLink)

In most of the cases root cause can be tracked by turn-on more verbose debug session
(please refer to the next slide)
Issues with entering debug session
22
more verbose debug session

• An useful option is increasing debug


level to 3 in OpenOCD configuration

• It generates much more messages


concerning OpenOCD operations
helping us to detect a root cause of
the issue with debug session

• To do it, please add –d3 option in


OpenOCD Command within current
debug configuration
Issues with entering debug session
23
detecting still running debug sessions
To detect still running debug sessions,
please switch to debug perspective
1. If the button is not
3
available, please click button
(or go to Window->Perspective- 1
>Open Perspective) and select
2
“Debug” line form the list
2. Please have a look whether there
are running debug sessions in the
Debug window 4
3. To close them, they should be first
terminated (STOP button) and then
removed (XX button)
4. After removing all missed debug
sessions, try to run debug session
once again.
Issues with entering debug session
detecting “ghost” GDB processes in the system 24

• Display list of active tasks in the PC (Windows OS) by pressing


Ctr+Alt+Del and select “Start Task Manager”
• Select “Processes” tab from Windows Task Manager
• Highlight “ghost” arm-none-eabi-gdb.exe process
• Press End Process button
Issues with entering into debug session
25
detecting issue with busy STLink
• Configure more verbose debug session (-d3 option)
• Run debug session and observe the messages displayed under Console tab
• Identify lines with Error attribute (first column in an example below)
Managing multiproject workspace
26
closing and opening projects
• In the workspaces which contains more projects there is a risk of work on the sources from inactive
project
• For this reason a good practice is to close inactive projects (it is not related to any project/file
erasing).
• To close the project, please click right mouse button on project name and select “Close Project”
• To close all opened, but not active project, please click right mouse button on the active project
name and select “Close Unrelated Projects”
• To reopen closed project, please double click left mouse button on its name or click right mouse
button on project name and select “Open Project”

Opened active project

Opened inactive project

Closed projects
Managing debug session
27
multiproject workspace

• In the workspaces which contains more


projects there is a risk that we are
running not correct debug session (by
simple click on “bug” icon)
• To display available debug sessions
within the workspace please use Run-
>Debug Configurations on click on
small “down” arrow near the “bug” button
• To select a correct debug session,
please click on its name
• To delete any debug configuration press
red ‘X” button
Our goals for this session 28

Get knowledge about some features of SW4STM32 toolchain:


Selection C dialect and parallel build options
Configuration of the indexer
How to run an external application
How to set autosave before build option
How to use “come back later” messages within the code
How to use and configure autocompleting option
Managing different output files (.hex, .bin files generation)
How to run debug session and handling most common issues related to this operation
Enjoy!

/STM32 @ST_World st.com/e2e

www.st.com/mcu

You might also like