Created by Robin Hellmers, published on Github
- 1. Pre-requisites
- 2. Install STM32CubeCLT - Command Line Tool
- 3. Install STM32CubeMX - Initialization Code Generator
- 4. Initialize a project - STM32CubeMX
- 5. Setup Visual Studio Code
- WSL2 installed with an Ubuntu instance
- Visual Studio Code (VSCode) installed
- VSCode 'Remote Development' extension installed for access to the WSL instance
- Download the Generic Linux Installer, instead of the
Debian based one
- It requires an account at ST
- Go to the Windows explorer under Downloads, where the downloaded
.zip
is located - Copy the Windows path from the file explorer
- E.g.
C:\Users\<user>\Downloads
- E.g.
- Open your WSL Ubuntu instance
- Get the linux style path
wslpath "<path>"
- Observe the quotation
- E.g.
wslpath "C:\Users\<user>\Downloads"
- Move the
.zip
installer to your home directorymv <path>/<file> ~
- Install
unzip
sudo apt install unzip
- Unzip the installer
cd ~
unzip <file>
- Run the
.sh
installer usingsudo
sudo sh <filename>.sh
- Accept the prompt with
y
- Accept location installation with
<Enter>
, which default to something similar to:/opt/st/stm32cubeclt_<version
The installation will also add a script to /etc/profile.d/
similar to
cubeclt-bin-path_<version>.sh
which will extend your PATH
.
You do thereby have to open a new terminal for these to load in, or you source
it yourself e.g.:
. /etc/profile.d/cubeclt-bin-path_1.16.0.sh
-
Check the Release Note at the download page, under Installing on Linux which describes the missing packages as well as you needing the correct python version.
-
You can use the
ldd <executable>
command to see dependencies
| prints the shared objects (shared libraries) required by each program or shared object
Find out missing packages for gdb
installed with STM32CubeCLT.
ldd "$(which arm-none-eabi-gdb)" | grep 'not found'
Probably outputs:
libncurses.so.5 => not found
libtinfo.so.5 => not found
Which also probably reflects if you try to run it:
arm-none-eabi-gdb --version
With e.g. the output:
arm-none-eabi-gdb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
libncurses.so.5
depends on libtinfo.so.5
, which is why we start installing libtinfo
.
These are not even available in the apt
universe
repository for newer Ubuntu
versions. Which is why we install them through the Ubuntu archive.
Download the .deb
file:
wget \
http://archive.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.4-2_amd64.deb
Install using the file:
sudo dpkg -i ./libtinfo5_6.4-2_amd64.deb
Download the .deb
file:
wget \
http://archive.ubuntu.com/ubuntu/pool/universe/n/ncurses/libncurses5_6.4-2_amd64.deb
Install using the file:
sudo dpkg -i ./libncurses5_6.4-2_amd64.deb
ldd "$(which arm-none-eabi-gdb)"
Which outputs something similar to:
linux-vdso.so.1 (0x00007ffec9943000)
libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007f7d3ee6f000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f7d3ee3f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7d3ee3a000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7d3df83000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7d3ed51000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7d3ed22000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7d3ed1d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7d3dd71000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7d3ee9c000)
Indicating that both libncurses.so.5
and libtinfo.so.5
are found.
arm-none-eabi-gdb --version
Which should not complain and output something similar to:
GNU gdb (GNU Tools for STM32 12.3.rel1.20240612-1315) 13.2.90.20230627-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
From testing both an install on Windows as well as on an Ubuntu WSL2 instance, I would recommend the Windows installation to avoid issues. This is a GUI based tool and thereby works the best on Windows as that is the host system.
It works great with generating code within the WSL2 Ubuntu instance.
- Download the Windows Installer
- It requires an account at ST
- Unzip the
.zip
in Windows - Execute the
.exe
file - Follow the installation instructions
Upcoming link to markdown file with instructions
Create a project which builds with Makefile. It shall be created to demonstrate a Intellisense setup for C/C++ with Makefile.
-
Start STM32CubeMX on Windows.
-
Click Start My project from ST Board
- Wait while it downloads information
-
Under Commercial Part Number, search for
P-NUCLEO-WB55-NUCLEO
-
Double-click the found board with the same commercial part number
-
In the Board Project Options popup window, select
Generate demonstration code
and then click OK -
Click the Project Manager tab.
-
Enter the fields:
Project Name
- Which will be the directory name as well. Avoid spaces as it is in the linux space
Project Location
- Reach the WSL2 Ubuntu instance throuch
\\wsl.localhost\<wsl_instance>\
- Can e.g. be reached through the Windows Explorer
- Find WSL instance name by opening CMD and listing all instances
wsl --list
- Example location:
\\wsl.localhost\Ubuntu-24.04-6\home\hellmers\git\project
- Reach the WSL2 Ubuntu instance throuch
Application Structure
- Not as important, choose
Advanced
- Not as important, choose
Toolchain Folder Location
- Automatically filled using
Project Location
andProject Name
- Automatically filled using
Toolchain / IDE
- Select
Makefile
as this guide showcases this - Could as well have been
CMake
- Select
-
Click the GENERATE CODE button, top right above the tabs
- Wait a little while for the code to generate
-
Open the WSL2 Ubuntu instance and go to the project location
-
Install
make
withapt
sudo apt install make
-
While in the project directory, where the generated
Makefile
is, compile everything:make
- Just to make sure there are no issues
Install the Visual Studio Code (VSCode) extensions e.g. through the GUI Extensions tab.
Install the extension:
- C/C++ extension
- ID:
ms-vscode.cpptools
- ID:
The build system extension of course depends on which build system you have chosen to use when e.g. generating a project with STM32CubeMX.
Example build systems:
- Makefile
- CMake
This guide specifically used Makefile.
Install your corresponding extension:
- Makefile Tools
- ID:
ms-vscode.makefile-tools
- ID:
- CMake Tools
- ID:
ms-vscode.cmake-tools
- ID:
Open VSCode at the project root using code .
if you are in the project root.
- Open the
Command Palette
:- Press
Ctrl
+Shift
+P
- Press
- Enter
C/C++: Edit Configurations (UI)
- Creates a configuration file at the project directory
.vscode/c_cpp_properties.json
- Presents configuration options
- Creates a configuration file at the project directory
- Configure the following fields:
Compiler path
- Check the drop-down list if it presents you with the full path to
arm-none-eabi-gcc
- If not, open the Ubuntu instance and check the path with
which arm-none-eabi-gcc
- Check the drop-down list if it presents you with the full path to
IntelliSense mode
- Select
linux-gcc-arm
- Select
Include path
- Should already have
${workspaceFolder}/**
- Should already have
- At the bottom, expand the Advanced Settings drop-down
- Configure the following fields:
Configuration provider
j- Tells which build system that is used and which extension to integrate with
- For Makefile:
ms-vscode.makefile-tools
- Extension ID can be found by:
- Open Extensions by pressing
Ctrl
+Shift
+X
- Click the cogwheel to the right of your build system extension
- E.g.
Makefile Tools
- E.g.
- Click Copy Extension ID
- Open Extensions by pressing
This results in a similar .vscode/c_cpp_properties.json
:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/opt/st/stm32cubeclt_1.16.0/GNU-tools-for-STM32/bin/arm-none-eabi-gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-arm",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
For IntelliSense to work properly, it needs to read the commands executed
when running make. To do this, it runs something similar to make clean
followed by make --dry-run
, basically not executing the commands but printing
out the commands to be executed. That output is put into a temporary file, which
then is read and used for IntelliSense.
First, try with just:
- Open the
Command Palette
:- Press
Ctrl
+Shift
+P
- Press
- Enter
Makefile: Configure
If the output in the Makefile tools
terminal or .vscode/extension.log
shows
failed execution, you can do it manually:
- Open the
Command Palette
:- Press
Ctrl
+Shift
+P
- Press
- Enter
Makefile: Open Build Log Setting
- Configure the following field:
Build Log
- Enter
./dryrun.log
- Enter
- Generate
dryrun.log
- Open the project location
- Clean up any previous build
make clean
- Generate the log:
make --dry-run > dryrun.log
- Reload the window
- Potentially run the same as previous:
Makefile: Configure
This results in the following setting in .vscode/settings.json
:
{
"makefile.buildLog": "./dryrun.log"
}