User Tools

Site Tools


Sidebar

Modtronix.com
Sitemap

tutorials:nz32:ide:sw4stm32-with-nz32-boards

Using SW4STM32 with NZ32 Boards

This Wiki page contains information how to use the System Workbench for STM32 IDE(also known as SW4STM32) with Modtronix boards with a STM32 processors(NZ32-SC151 for example). This tutorial was created for V1.0.3 of SW4STM32.

Many Modtronix example and source code downloads include a SW4STM32 workspace with projects. SW4STM32 is an Eclipse based tool, meaning projects are always part of a workspace. 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 by following these simplified steps (see below for details):

Installing Software and Drivers

Importing and Build project

After all software has been installed, the workspace/project can be imported into SW4STM32:

  • Unzip downloaded source code/project to your computer. Ensure path does not have spaces!
  • Start SW4STM32. During starup 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).

Update Firmware

The firmware on the target board can be updated via the USB bootloader, or by using a ST-Link programmer.

  • The bootloader method does not require a programmer, but is not integrated with SW4STM32 and project can not be debugged. For details, click here.
  • The section below described the preferred method using ST-Link programmer.

Debug and Run project

Programming NZ32-Sx board Next step is to program and debug the target 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

System Workbench for STM32

System Workbench for STM32 is based on the Eclipse IDE for C/C++ developers (Eclipse CDT). There is a lot of information available online if you get stuck. 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.

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

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)

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

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.

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/nz32/ide/sw4stm32-with-nz32-boards.txt · Last modified: 2017/02/10 07:08 by modtronix