User Tools

Site Tools


Sidebar

Modtronix.com
Sitemap

tutorials:software:ide:system_workbench_for_stm32

System Workbench for STM32 IDE

=== Click to Enlarge ===

This Wiki page contains information how to use the System Workbench for STM32 IDE, also known as SW4STM32.

The System Workbench toolchain, called SW4STM32, is a free multi-OS software development environment based on Eclipse IDE for C/C++ developers (Eclipse CDT). It supports the full range of STM32 microcontrollers and associated boards. It is also used by Modtronix for our STM32 based boards. There is a lot of information available online if you get stuck.

SW4STM32 Features

  • GCC C/C++ compiler
  • GDB-based debugger
  • Eclipse IDE with team-work management
  • Compatible with Eclipse plug-ins
  • ST-LINK support
  • CMSIS-DAP Programmer/Debugger
  • No code size limit
  • Multiple OS support: Windows®, Linux and OS

Without using SW4STM32, it is very time consuming getting the GCC C/C++ compiler and debugger working. SW4STM32 makes STM32 development very easy by providing a single tool that can be used for entire software development cycle.

Installation

Installation is quite simple, and basically just involves downloading and installing the app from openstm32.org. After installation, it is often required to check for updates in Eclipse(SW4STM32) to update to the latest version.

At the time of writing this, SW4STM32 documentation was located here. If this link is not valid any more, just look for the “System Workbench for STM32” documentation section at from openstm32.org.

The “System Workbench for STM32” user forum also contains a lot of useful information, and is located here. You will find help on their site relating to installation, debugging, programming of STM32 target, importing mbed project, importing STM32Cube(STM32CubeMX) projects and more.

Workspace and Projects

Because SW4STM32 is an Eclipse based tool, projects are always part of a workspace. Many Modtronix example and source code downloads include a SW4STM32 workspace with projects. To see if a download has a SW4STM32 workspace, look for a “SW4STM32” folder in the root directory. This is the SW4STM32 workspace folder, and will contains one or more SW4STM32 projects. The SW4STM32 IDE can be used to compile, debug and program the target board using a ST-Link or CMSIS-DAP based programmer/debugger.

Importing and Building Projects

=== Click to Enlarge ===

STM32 based software meant for the SW4STM32 IDE is contained in a workspace, with one or more projects. This workspace and project(s) can be imported into SW4STM32:

  • Unzip downloaded source code/project to your computer. Ensure path does not have spaces!
  • Start SW4STM32. During startup it will ask for a workspace. Select the “SW4STM32” folder in the root of the unzipped source code.
  • Once SW4STM32 has started, click on <File> <Import> menu. In <General>, select “Existing Project into Workspace”. Browse to “SW4STM32” folder, and import project. Ensure the following options are disabled
    • “Search for nested projects”
    • “Copy projects into workspace”
    • “Hide projects that already exist in the workspace”
  • Once import is done, build project via <Project> <Build Project> command (ctrl-B).

Running and Debugging

To program(run) and debug a target board, it must be connected to the PC using a supported programmer/debugger. This tutorial supports:

  • ST-Link Programmer and Debgger: By default, SW4STM32 supports ST-Link. A stand-alone ST-Link programmer/debugger, or boards with an integrated ST-Link programmer/debugger can be used(like the Nucleo range of boards from ST Microelectronics).
  • CMSIS-DAP Programmer and Debugger: Most mbed boards however have a CMSIS-DAP programming/debugging interface, which is also supported.

All new Modtronix STM32 based projects will use CMSIS-DAP programming/debugging by default. The reason is that our boards are designed for the mbed environment, and this is the default programmer/debugger used by mbed.

CMSIS-DAP Programmer and Debugger

To use CMSIS-DAP programming/debugging:

  • The target board must have a built in CMSIS-DAP interface
  • A CMSIS-DAP programmer/debugger must be used. Like the DIPDAP for example.

To configure an imported project to use this programmer/debugger is quite simple. Follow these steps:

  • Ensure you have already imported and built the project. See Importing and Building Projects section above.
  • Check the “SW4STM32 project folder” contains a “boardname_cmsis-dap.cfg” file. For Modtronix projects, the default project folder is “SW4STM32/Default”, which is located in the root of the downloaded source code/project.
  • Ensure you target board with a CMSIS-DAP interface is powered and connected via USB to you PC.
  • Select <Run><Debug>(F11) from the menu.

After completing this one time setup, the board can be programmed via the <Run><Run>(Ctrl-F11) command, and debugged via the <Run><Debug>(F11) command.

Project must contain “boardname_cmsis-dap.cfg” file! Click to Enlarge

Programming NZ32-Sx board For this to work, the target must be connected to a ST-Link/V2-1 programmer(SWD mode), like the Modtronix PGM-NUCLEO. The picture on the right shows the PGM-NUCLEO connected to the NZ32-SC151 target board.

To debug and program the target board, we first have to create a new Debug Configuration. This only has to be done once. Once done, the board can be debugged via <Run><Debug>(F11) menu, and programmed via the <Run><Run>(Ctrl-F11) menu. To create a new Debug Configuration do the following:.

  • Click on <Run> <Debug Configuration> menu.
  • Double click on “AC6 STM32 Debugging”.
  • A “New Configuration” will be created, select it.
  • In dialog box(for new configuration) select current project (Browse button). This should add the created *.elf file. If not, do it manually.
  • Click on the “Debugger” tab.
  • At the bottom of the “Debugger” tab, select “Manual Script”, and enter:
    • Debug Device = ST-LinkV2-1
    • Debug Interface = SWD
  • Now click on the “Debug” button at bottom of dialog.
  • The programmer should now download the firmware to the target, and switch to the Debug perspective.
  • In the Debug perspective, you can run, single step and debug the target board.
  • To exist debugging, click on <Run> <Terminate> menu.
  • To return to standard C/C++ perspective(view), click on <Window> <Open Perspective> <C/C++> menu
=== Click to Enlarge ===

ST-Link/V2 USB Drivers

The recommended programmer for Modtronix NZ32 STM32 based boards is the PGM-NUCLEO programmer. It requires the ST-Link/V2(ST-Link/V2-1) USB Drivers. Just search the net for “st link usb drivers”. At the time of writing this, they were available here.

To check if drivers are installed, plug programmer into USB port on PC and go to “Device Manager” on Windows. The following should be listed:

  • “STMicroelectronics STLink Virtual COM Port …” under “Ports (COM & LPT)” section
  • “STMicroelectronics STLink dongle” under “Universal Serial Bus devices section

Note that the USB Driver application supplied by ST will NOT install the drivers on your computer! By default, it will create a “STMicroelectronics” folder in “Program Files (x86)” directory. This folder will contain the USB drivers for 32-bit and 64-bit operating system. You will have to install the correct driver on your system (located in ”..\Program Files (x86)\STMicroelectronics“ folder) to complete the installation.

Seeing that the PGM-NUCLEO programmer is actually the programming part of a NUCLEO-F411RE board, the Nucleo documentation is also relevant. Useful information can be found here, and on the NUCLEO-F411RE page on mbed.org (“Nucleo ST-LINK/V2 driver installation and firmware upgrade” section at bottom of page).

Importing Code

Importing library

To import a new library or source code is very simple:

  • Create a new folder in the root project directory. This will be the same directory as contains the “SW4STM32” folder.
  • Place all library files in this new folder, normally this will be *.h, *.c and *.cpp files. Ensure this folder does NOT contain any “non source code” files and folders, like ”.hg“ or ”.git“ repository folders for example. It should only contains files and folders with source code.
  • Drag-and-drop(or copy-paste) this new folder into SW4STM32 project shown in “Project Explorer”. Ensure to drop(copy) to root of project.
  • A dialog box will open. Select “Link to files and folders”. Also click the “Create link locations relative to WORKSPACE_LOC” check box.
  • A new folder will now appear in the “Project Explorer” with the new source files.
  • Additionally we have to add this new folder to the include paths of compiler:
    • This is done in the project properties » “C/C++ General” » “Paths and Symbols”
    • Go to the “Includes” tab, where you can add the new directories to the Include path
    • You can either type the paths, or use the “Workspace…” button to browse your project.
    • For each directory added check both “Add to all configurations” and “Add to all languages”

Adding mbed library to project

There are many free libraries provided on mbed. For example, Modtronix provides many free libraries on our mbed project page. For this example we will import the modtronix_LCD2S library into our project:

  • Go to library page, located here for this example.
  • Click on “Download Repository zip” link. This will download zipped repository
  • Create a new folder in the root project directory called “modtronix_LCD2S”. The root project directory is the same directory as contains the “SW4STM32” folder.
  • Copy the contents of the downloaded file to this new folder.
  • Ensure this folder does NOT contain any “non source code” files and folders, like ”.hg“ or ”.git“ repository folders for example. It should only contains files and folders with source code.
  • Drag-and-drop(or copy-paste) this new folder into SW4STM32 project shown in “Project Explorer”. Ensure to drop(copy) to root of project.
  • A dialog box will open. Select “Link to files and folders”. Also click the “Create link locations relative to WORKSPACE_LOC” check box.
  • A new folder will now appear in the “Project Explorer” with the new source files.
  • Additionally we have to add this new folder to the include paths of compiler:
    • This is done in the project properties » “C/C++ General” » “Paths and Symbols”
    • Go to the “Includes” tab, where you can add the new directories to the Include path
    • For this example, enter “${WorkspaceDirPath}/../modtronix_LCD2S” into “Directory” box
    • For each directory added check both “Add to all configurations” and “Add to all languages”

Importing mbed projects

mbed projects can be imported and compiled using SW4STM32. See this page on openstm32.org for detailed description. If link is broken, search internet for “Importing mbed project System Workbench for STM32”

Importing STMCubeMX projects

STMCubeMX projects can be imported and compiled using SW4STM32. See this page on openstm32.org for detailed description. If link is broken, search internet for “Importing STM32CubeMX project System Workbench for STM32”

Additional Configuration

Once the project is all configured and building, there are many additional settings that can be fine tuned and personalized. When searching online, include “Eclipse CDT” with your search text. This IDE is based on Eclipse CDT.

Enabling Optimization

=== Click to Enlarge ===

After importing a workspace/project, optimization seems to be disabled by default. The code size of the built project can be significantly reduced by enabling Optimization. To enable compiler optimization, do the following (click image on right to enlarge):

  • Open project properties dialog by selecting <Project> <Properties> from menu
  • Select “C/C++ Build” » “Settings” from menu tree on the left
  • Select the “Tool Settings” tab
  • In this tab, select “Optimize for size (-Os)” for both the “MCU GCC Compiler” AND “MCU G++ Compiler”
  • See image on right for details, click to enlarge!

Use Newlib (MicroLib)

=== Click to Enlarge ===

Newlib is a highly optimized version of the standard C library. It also seems to be called MicroLib or nano library. It has been designed for use with embedded applications where memory resources are limited. To minimize code size, it has less functionality than the default standard C library. For details, click here. For details about the Keil version of MicroLib, see this page. To use Newlib in stead of the standard C library, do the following (click image on right to enlarge):

  • Open project properties dialog by selecting <Project> <Properties> from menu
  • Select “C/C++ General” » “Settings” from menu tree on the left
  • Select the “Tool Settings” tab
  • In this tab, select “MCU G++ Linker” » “Miscellaneous” from menu tree
  • Add ”-specs=nano.specs“ to Linker flags box (without double quotes)
  • See image on right for details, click to enlarge!

Parallel Build

=== Click to Enlarge ===

The time taken to build a project can be greatly reduced by enabling parallel build. To enable it, do the following (click image on right to enlarge):

  • Open project properties dialog by selecting <Project> <Properties> from menu
  • Select “C/C++ Build” from menu tree on the left
  • Select the “Behavior” tab, and check the “Enable Parallel Build” option
  • See image on right for details, click to enlarge!

Troubleshooting

Q. When building the project, I get the error message //"fatal error: filename.h: No such file or directory//"
Q. printf does not work with float data types

Question:  When building the project, I get the error message “fatal error: filename.h: No such file or directory
Answer: First check if the given file actually exists. Next, ensure the file path where this file is located is included in the “Paths and Symbols” properties:

  • This is done in the project properties » “C/C++ General” » “Paths and Symbols”
  • Go to the “Includes” tab, where the path should be listed for ALL languages.
  • For the picture below, it should be listed for “Assembly”, “GNU C”, “GNU C++” languages.
  • Some time languages are listed multiple times. When adding a new include path, ensure to have “Add to all configurations” checked as described in section above.
=== Click to Enlarge ===

Question:  printf does not work with float data types.
Answer: For float to work with printf, the ”-u _printf_float“ flag must be added to the linker. This will however increase the code size quite a bit, about 4kByte for our test. If possible, alternative methods should be used. To enable float for printf, do the following:

  • Open project properties dialog by selecting <Project> <Properties> from menu
  • Select “C/C++ General” » “Settings” from menu tree on the left
  • Select the “Tool Settings” tab
  • In this tab, select “MCU G++ Linker” » “Miscellaneous” from menu tree
  • Add ” -u _printf_float“ to Linker flags box (without double quotes)
tutorials/software/ide/system_workbench_for_stm32.txt · Last modified: 2017/02/22 03:29 by modtronix