FlexSEA Wiki


User Tools

Site Tools


Getting started with Dephy STM32 projects


This page will get you up and running writing code for any STM32 microcontroller in a Dephy product. Over the course of the document we will cover installing the necessary tools, how to build the project for different applications and boards, and finally how to load the software onto the device. To learn more about the build system refer to Dephy Build System.


Windows: Install/download prerequisites

GNU Arm Embedded Toolchain: 10-2020-q4-major

  • Download Windows ZIP download of gcc-arm-none-eabi-10-2020-q4-major-win32.zip. Be sure you get the correct version!
  • Extract the downloaded contents to a path with no spaces i.e. C:\toolchains\
  • Note full toolchain path extracted i.e. C:\toolchains\gcc-arm-none-eabi-10-2020-q4-major\
  • Path:
    • To use the toolchain with CLion you need to add a new environment variable (see FAQ)
    • To use the toolchain with the Bash scripts you need to edit local_settings.sh (see Bash section below)
    • We recommend doing both to avoid surprises

We moved to GCC 10 in 2021, after more than two years on GCC 7. We encourage everyone to upgrade as soon as possible. Migrating to ARM GNU v10 Toolchain


  • Download CMake from this link: https://cmake.org/download/
  • Download the latest binary distribution for your Windows platform
  • Run the .msi installer and proceed through the steps
  • Be sure to select the “Add CMake to the system PATH” option when prompted. If this step is missed, manually add the CMake installation folder to the system path. Google “add directory to path windows” for details.


  • Navigate to this link in a web browser: https://github.com/ninja-build/ninja/releases
  • Download the version for your platform and extract the zip file. Place the file in a folder in the Program Files directory (i.e. C:\Program Files\ninja-win\)
  • Add the location of the Ninja installation folder to the system path. Google “add directory to path windows” for details.
    • This is typically done under the “Path” that's linked to your username
    • Reboot your computer to make it active

OpenOCD (optional)

Clone this repository

  • Download and install Git Bash https://gitforwindows.org/
  • During installation, be sure to select the “Associate .sh files to be run with Bash” at the Select Components screen.
  • Open a Git Bash terminal in the desired folder and run the following command (access required; given on an as needed basis):
git clone --recursive https://github.com/DephyInc/FlexSEA-Embedded-STM.git

Linux: Install/download prerequisites

GNU Arm Embedded Toolchain: 10-2020-q4-major

sudo apt-get install cmake ninja-build
  • Clone this repository:
git clone --recursive https://github.com/DephyInc/FlexSEA-Embedded-STM.git

Building Target Applications

This project is built using CMake so technically it is possible to build directly from the command line using only CMake but below are 3 easier ways to work with the project.

Recommended IDE: If you prefer to use an IDE, CLion is a great choice as it is entirely built around using CMake and has a number of great features. You can experiment with a demo license first, then ask your manager for a subscription.

Free IDE: System Workbench from STMicroelectronics also works and has all necessary tools for working with STM32 microcontrollers bundled with the IDE (Eclipse). However Eclipse prefers to generate its own Makefiles so there can be issues using CMake but as of 8/2/2019 we did find a plugin that works fine and instructions are below. This is only recommended for external clients, not for internal development.

Command line (Bash script): The other main option is to build and download the project using the included bash script. This is best if you prefer to use your favorite text editor like Vim, Sublime, etc.


Install IDE

  • Download and install CLion from this link.
  • The fastest/easiest installation is to use all default settings

Setup Project

  • Navigate to the FlexSEA-Embedded-STM directory you previously cloned
  • Copy the file named workspace_template.xml in the .idea directory of this repository and rename it workspace.xml (replace the existing workspace.xml file if it exists). Make sure that you now have a file called workspace.xml in the .idea directory, this is where the CMake profiles for different build targets are stored and it is very important to have.
  • Copy the file named local_settings_template.sh in the main project directory of this repository and rename it local_settings.sh (replace the existing local_settings.sh file if it exists). Open it in a text editor and update the toolchain path.
  • Download MinGW following this link if you haven't downloaded it before: Install Build Tools (Windows)
  • Make sure you have access to the following git repository. If you don't, please request access to this repository to simplify replicating CLion Settings.
  • You're now ready to open CLion and finish the setup
    • Open this project in CLion
      • Navigate to File → Open
      • Navigate to the location of this repo on your PC
    • Please generate a Personal Access token on your github profile. Use the link to follow instructions on how to generate a Personal Access Token.
    • Navigate to File → Manage IDE Settings → Settings Repository
    • Enter https://github.com/DephyInc/clion_settings as the Upstream URL.
    • Click Overwrite Local. This will prompt for a Token. Use the token generated in the previous step.
    • Once the sync completes CLion will show a notification. Wait for all the indexing to complete. You can see the status bar at the bottom of the main window. Once done, Exit and Restart CLion and you should be all set.

NOTE: When performing CLion IDE Settings Sync do NOT click Overwrite Remote under any case, unless you want to save a newer CLion Settings that you wish for everyone else to have as well.

Configure toolchain

Point CLion to your toolchain by defining TOOLCHAIN_PATH:

Note: this can be done as a Windows environment variable too, but doing it in CLion has less chances of impacting other systems on your computer, and doesn't require rebooting.

  • If needed, create a new “stm32” toolchain and:
    • Use the CMake you installed and not the one included with CLion
    • Point to the GDB included in your embedded toolchain

In your project config make sure it uses that stm32 toolchain:


  • In the top right corner there should be a dropdown menu with build targets
    • Click the drop down then click on fx_manage
    • You can the select the build target, current options include Exo-rigid2.0-left, ActPack-rigid2.0, etc.
  • CLion will attempt to compile the project and compile output should appear in the window at the bottom

Exchanging Build/Projects Settings

It is common to exchange your project settings with team members. workspace.xml contains that information in plain text form. Look for the <component name=“CMakeSettings” AUTO_RELOAD=“true”> section. Add configurations as needed, and save the file. It will auto-reload and the list of projects will be accessible in the CMake settings as well as the drop-wodn Build menu.

Bash script

First Time

  • Copy the file in the root directory of the cloned repo called local_settings_template.sh to a new file named local_settings.sh
  • Open local_settings.sh in a text editor
  • Change the value of TOOLCHAIN_DIR to the path where the GNU Arm Toolchain was installed.
    • On Windows make sure the path does not have spaces!

General Usage

  • Open a Bash terminal (on Windows use Git Bash) and enter the root directory of this repository.
  • Running the command ./manage_builder.sh with no arguments will print some of the possible build targets.
  • In the root directory these are some of the commands that can be run:
./manage_builder.sh ActPack-rigid1.0
./manage_builder.sh ActPack-rigid0.2 download
./manage_builder.sh Exo-rigid2.0
./manage_builder.sh Exo-rigid3.0-left

The basic format of the arguments is APP-HARDWARE_PLATFORM but subproject can be added with an additional * symbol as seen in the last example and download can be added to the end of the arguments to also flash a device. For more examples and instructions refer to Build Firmware.

These options can be added as build configurations for CLion or Eclipse.

Downloading firmware to target

Both a .hex and a .bin file are generated in the build directory after compiling an application. This is the firmware image and the only difference between the hex and bin files are the format. They can be used interchangeably.


  • stlink is a command line utility for flashing STM32s: More information about the tool can be found on the ST-What? page under the stlink/st-flash section
  • Install the required software for the tool as indicated in the ST-What?>stlink/stflash>Installation section
  • Connect the ST-Link programmer to the programming header of the target device
  • Refer to the Tips & Tricks section in the above page. Take special note of getting the right drivers installed to be able to use the st-link/st-flash util binaries.
  • For example, running the following command will flash manage on a rigid board:
./manage_builder.sh Exo-rigid3.0-left download

Windows (Optional GUI)

  • Refer to the Tips & Tricks section in the above page. Take special note of getting the right drivers installed to be able to use the st-link/st-flash util binaries.


  • stlink is a command line linux utility for flashing STM32s
git clone https://github.com/texane/stlink.git
  • On Ubuntu it may be necessary to download the repo and compile
  • After you have a copy of the st-flash binary add it to your path
    • The easiest way is to append it to the PATH variable in the bottom of your ~/.bashrc file
  • Running this command will flash manage on a rigid board
./manage_builder.sh Exo-rigid3.0-left download

Setting up and using the debugger in CLion

Clion fully supports step-by-step debugging using GDB/OpenOCD/STLink-v2 or v3.

  1. Only follow this section after you have completed the general Setup and the CLion Setup steps.
  2. Settings > Build, Execution, Deployment > Toolchains > set the debugger to be “arm-none-eabi-gdb.exe” with the proper path (ex.: C:\toolchains\7-2018-q2-update\bin\arm-none-eabi-gdb.exe)
  3. Run/Debug Configurations > OpenOCD Download and Run
    • Target and Executable need to be fx-manage
    • Pick a board config file. \FlexSEA-Embedded-STM\config\debugging\fx-rigid-f4-openocd.cfg works. Using the Discovery files that came with OpenOCD is also OK.
    • User preference, but Download Always and Reset Init work well

FAQ & Troubleshooting

  • Make sure you made a local_settings.sh file in the root of the repo with the correct path to your compiler.
/bin/bash manage_builder.sh ActPack-rigid2.0
Please copy local_settings_template.sh to local_settings.sh!
Process finished with exit code 0
  • CMake or Ninja not found? Make sure you installed these tools and added to your path!
  • Triple check you have the right compiler version (7-2018-q2-update)
  • st-flash is not the same as ST-Link Utility, or STMFlasher. The ST-What? page was created just for that reason.
  • Issues using your ST-Link v2 with the scripts or CLion? Make sure it's connected to a USB 2.0 port.
  • As of now, the ST-Link v3 does not work with the scripts. It can be used with the ST-Link Utility.

Adding toolchain to environment variables

For Windows OS:

  • Go to Control Panel → System
  • Click Advanced System Settings
  • Click Advanced Tab
  • Click Environment Variables
  • In user variables, click new.
  • Type name and variable as
    Variable name: TOOLCHAIN_PATH
    Variable value: C:\toolchains\gcc-arm-none-eabi-10-2020-q4-major
manage/software.txt · Last modified: 2021/08/11 16:40 by casmat